2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #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 /* try to make sure pending X events have been processed before continuing */
64 static void flush_events(void)
68 DWORD time = GetTickCount() + diff;
72 MsgWaitForMultipleObjects( 0, NULL, FALSE, diff, QS_ALLINPUT );
73 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
74 diff = time - GetTickCount();
78 /* check the values returned by the various parent/owner functions on a given window */
79 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
80 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
86 res = pGetAncestor( hwnd, GA_PARENT );
87 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
89 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
90 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
91 res = GetParent( hwnd );
92 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
93 res = GetWindow( hwnd, GW_OWNER );
94 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
97 res = pGetAncestor( hwnd, GA_ROOT );
98 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
99 res = pGetAncestor( hwnd, GA_ROOTOWNER );
100 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
104 BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
107 trace("EnumChildProc on %p\n", hwndChild);
108 if (*(LPINT)lParam > 1) return FALSE;
112 /* will search for the given window */
113 BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
115 trace("EnumChildProc1 on %p\n", hwndChild);
116 if ((HWND)lParam == hwndChild) return FALSE;
120 static HWND create_tool_window( LONG style, HWND parent )
122 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
123 0, 0, 100, 100, parent, 0, 0, NULL );
124 ok( ret != 0, "Creation failed\n" );
128 /* test parent and owner values for various combinations */
129 static void test_parent_owner(void)
132 HWND test, owner, ret;
133 HWND desktop = GetDesktopWindow();
134 HWND child = create_tool_window( WS_CHILD, hwndMain );
137 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
139 /* child without parent, should fail */
140 SetLastError(0xdeadbeef);
141 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
142 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
143 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD, "CreateWindowExA should call SetLastError\n" );
144 ok( !test, "WS_CHILD without parent created\n" );
147 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
148 style = GetWindowLongA( desktop, GWL_STYLE );
149 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
150 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
151 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
153 /* normal child window */
154 test = create_tool_window( WS_CHILD, hwndMain );
155 trace( "created child %p\n", test );
156 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
157 SetWindowLongA( test, GWL_STYLE, 0 );
158 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
159 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
160 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
161 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
162 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
163 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
164 DestroyWindow( test );
166 /* normal child window with WS_MAXIMIZE */
167 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
168 DestroyWindow( test );
170 /* normal child window with WS_THICKFRAME */
171 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
172 DestroyWindow( test );
174 /* popup window with WS_THICKFRAME */
175 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
176 DestroyWindow( test );
178 /* child of desktop */
179 test = create_tool_window( WS_CHILD, desktop );
180 trace( "created child of desktop %p\n", test );
181 check_parents( test, desktop, 0, desktop, 0, test, desktop );
182 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
183 check_parents( test, desktop, 0, 0, 0, test, test );
184 SetWindowLongA( test, GWL_STYLE, 0 );
185 check_parents( test, desktop, 0, 0, 0, test, test );
186 DestroyWindow( test );
188 /* child of desktop with WS_MAXIMIZE */
189 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
190 DestroyWindow( test );
192 /* child of desktop with WS_MINIMIZE */
193 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
194 DestroyWindow( test );
197 test = create_tool_window( WS_CHILD, child );
198 trace( "created child of child %p\n", test );
199 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
200 SetWindowLongA( test, GWL_STYLE, 0 );
201 check_parents( test, child, child, 0, 0, hwndMain, test );
202 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
203 check_parents( test, child, child, 0, 0, hwndMain, test );
204 DestroyWindow( test );
206 /* child of child with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
208 DestroyWindow( test );
210 /* child of child with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
212 DestroyWindow( test );
214 /* not owned top-level window */
215 test = create_tool_window( 0, 0 );
216 trace( "created top-level %p\n", test );
217 check_parents( test, desktop, 0, 0, 0, test, test );
218 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
219 check_parents( test, desktop, 0, 0, 0, test, test );
220 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
221 check_parents( test, desktop, 0, desktop, 0, test, desktop );
222 DestroyWindow( test );
224 /* not owned top-level window with WS_MAXIMIZE */
225 test = create_tool_window( WS_MAXIMIZE, 0 );
226 DestroyWindow( test );
228 /* owned top-level window */
229 test = create_tool_window( 0, hwndMain );
230 trace( "created owned top-level %p\n", test );
231 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
232 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
233 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
234 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
235 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
236 DestroyWindow( test );
238 /* owned top-level window with WS_MAXIMIZE */
239 test = create_tool_window( WS_MAXIMIZE, hwndMain );
240 DestroyWindow( test );
242 /* not owned popup */
243 test = create_tool_window( WS_POPUP, 0 );
244 trace( "created popup %p\n", test );
245 check_parents( test, desktop, 0, 0, 0, test, test );
246 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
247 check_parents( test, desktop, 0, desktop, 0, test, desktop );
248 SetWindowLongA( test, GWL_STYLE, 0 );
249 check_parents( test, desktop, 0, 0, 0, test, test );
250 DestroyWindow( test );
252 /* not owned popup with WS_MAXIMIZE */
253 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
254 DestroyWindow( test );
257 test = create_tool_window( WS_POPUP, hwndMain );
258 trace( "created owned popup %p\n", test );
259 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
260 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
261 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
262 SetWindowLongA( test, GWL_STYLE, 0 );
263 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
264 DestroyWindow( test );
266 /* owned popup with WS_MAXIMIZE */
267 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
268 DestroyWindow( test );
270 /* top-level window owned by child (same as owned by top-level) */
271 test = create_tool_window( 0, child );
272 trace( "created top-level owned by child %p\n", test );
273 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
274 DestroyWindow( test );
276 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
277 test = create_tool_window( WS_MAXIMIZE, child );
278 DestroyWindow( test );
280 /* popup owned by desktop (same as not owned) */
281 test = create_tool_window( WS_POPUP, desktop );
282 trace( "created popup owned by desktop %p\n", test );
283 check_parents( test, desktop, 0, 0, 0, test, test );
284 DestroyWindow( test );
286 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
287 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
288 DestroyWindow( test );
290 /* popup owned by child (same as owned by top-level) */
291 test = create_tool_window( WS_POPUP, child );
292 trace( "created popup owned by child %p\n", test );
293 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
294 DestroyWindow( test );
296 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
297 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
298 DestroyWindow( test );
300 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
301 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
302 trace( "created WS_CHILD popup %p\n", test );
303 check_parents( test, desktop, 0, 0, 0, test, test );
304 DestroyWindow( test );
306 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
307 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
308 DestroyWindow( test );
310 /* owned popup with WS_CHILD (same as WS_POPUP only) */
311 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
312 trace( "created owned WS_CHILD popup %p\n", test );
313 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
314 DestroyWindow( test );
316 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
317 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
318 DestroyWindow( test );
320 /******************** parent changes *************************/
321 trace( "testing parent changes\n" );
324 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
325 #if 0 /* this test succeeds on NT but crashes on win9x systems */
326 ret = (HWND)SetWindowLongA( test, GWL_HWNDPARENT, (LONG_PTR)hwndMain2 );
327 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
328 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
329 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
330 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
332 /* normal child window */
333 test = create_tool_window( WS_CHILD, hwndMain );
334 trace( "created child %p\n", test );
336 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
337 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
338 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
340 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
341 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
342 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
344 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
345 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
346 check_parents( test, desktop, 0, desktop, 0, test, desktop );
348 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
349 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
350 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
351 check_parents( test, desktop, child, desktop, child, test, desktop );
353 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
354 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
355 check_parents( test, desktop, 0, desktop, 0, test, desktop );
356 DestroyWindow( test );
358 /* not owned top-level window */
359 test = create_tool_window( 0, 0 );
360 trace( "created top-level %p\n", test );
362 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
363 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
364 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
366 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
367 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
368 check_parents( test, desktop, child, 0, child, test, test );
370 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
371 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
372 check_parents( test, desktop, 0, 0, 0, test, test );
373 DestroyWindow( test );
375 /* not owned popup */
376 test = create_tool_window( WS_POPUP, 0 );
377 trace( "created popup %p\n", test );
379 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
380 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
381 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
383 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
384 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
385 check_parents( test, desktop, child, child, child, test, hwndMain );
387 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
388 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
389 check_parents( test, desktop, 0, 0, 0, test, test );
390 DestroyWindow( test );
392 /* normal child window */
393 test = create_tool_window( WS_CHILD, hwndMain );
394 trace( "created child %p\n", test );
396 ret = SetParent( test, desktop );
397 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
398 check_parents( test, desktop, 0, desktop, 0, test, desktop );
400 ret = SetParent( test, child );
401 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
402 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
404 ret = SetParent( test, hwndMain2 );
405 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
406 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
407 DestroyWindow( test );
409 /* not owned top-level window */
410 test = create_tool_window( 0, 0 );
411 trace( "created top-level %p\n", test );
413 ret = SetParent( test, child );
414 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
415 check_parents( test, child, child, 0, 0, hwndMain, test );
416 DestroyWindow( test );
419 test = create_tool_window( WS_POPUP, hwndMain2 );
420 trace( "created owned popup %p\n", test );
422 ret = SetParent( test, child );
423 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
424 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
426 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
427 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
428 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
429 DestroyWindow( test );
431 /**************** test owner destruction *******************/
433 /* owned child popup */
434 owner = create_tool_window( 0, 0 );
435 test = create_tool_window( WS_POPUP, owner );
436 trace( "created owner %p and popup %p\n", owner, test );
437 ret = SetParent( test, child );
438 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
439 check_parents( test, child, child, owner, owner, hwndMain, owner );
440 /* window is now child of 'child' but owned by 'owner' */
441 DestroyWindow( owner );
442 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
443 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
444 * while Win95, Win2k, WinXP do.
446 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
447 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
450 /* owned top-level popup */
451 owner = create_tool_window( 0, 0 );
452 test = create_tool_window( WS_POPUP, owner );
453 trace( "created owner %p and popup %p\n", owner, test );
454 check_parents( test, desktop, owner, owner, owner, test, owner );
455 DestroyWindow( owner );
456 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
458 /* top-level popup owned by child */
459 owner = create_tool_window( WS_CHILD, hwndMain2 );
460 test = create_tool_window( WS_POPUP, 0 );
461 trace( "created owner %p and popup %p\n", owner, test );
462 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
463 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
464 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
465 DestroyWindow( owner );
466 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
467 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
468 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
469 * while Win95, Win2k, WinXP do.
471 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
475 DestroyWindow(child);
478 owner = create_tool_window( WS_OVERLAPPED, 0 );
479 test = create_tool_window( WS_POPUP, desktop );
481 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
483 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
484 "EnumChildWindows should have returned FALSE\n" );
485 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
487 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
488 ret = SetParent( test, owner );
489 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
492 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
493 "EnumChildWindows should have returned TRUE\n" );
494 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
496 child = create_tool_window( WS_CHILD, owner );
498 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
499 "EnumChildWindows should have returned FALSE\n" );
500 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
501 DestroyWindow( child );
503 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
504 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
506 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
507 "EnumChildWindows should have returned TRUE\n" );
508 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
510 ret = SetParent( child, owner );
511 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
512 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
514 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
518 ret = SetParent( child, NULL );
519 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
520 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
522 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
523 "EnumChildWindows should have returned TRUE\n" );
524 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
526 /* even GW_OWNER == owner it's still a desktop's child */
527 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
528 "EnumChildWindows should have found %p and returned FALSE\n", child );
530 DestroyWindow( child );
531 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
533 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
534 "EnumChildWindows should have found %p and returned FALSE\n", child );
536 DestroyWindow( child );
537 DestroyWindow( test );
538 DestroyWindow( owner );
542 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
546 case WM_GETMINMAXINFO:
548 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
550 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
551 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
552 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
553 minmax->ptReserved.x, minmax->ptReserved.y,
554 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
555 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
556 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
557 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
558 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
561 case WM_WINDOWPOSCHANGING:
563 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
564 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
565 trace("main: WM_WINDOWPOSCHANGING\n");
566 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
567 winpos->hwnd, winpos->hwndInsertAfter,
568 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
569 if (!(winpos->flags & SWP_NOMOVE))
571 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
572 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
574 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
575 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
577 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
578 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
582 case WM_WINDOWPOSCHANGED:
585 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
586 trace("main: WM_WINDOWPOSCHANGED\n");
587 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
588 winpos->hwnd, winpos->hwndInsertAfter,
589 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
590 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
591 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
593 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
594 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
596 GetWindowRect(hwnd, &rc1);
597 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
598 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
599 /* note: winpos coordinates are relative to parent */
600 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
601 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
602 #if 0 /* Uncomment this once the test succeeds in all cases */
603 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
606 GetClientRect(hwnd, &rc2);
607 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
608 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
609 ok(EqualRect(&rc1, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
610 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
615 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
616 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
618 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
619 if (got_getminmaxinfo)
620 trace("%p got WM_GETMINMAXINFO\n", hwnd);
622 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
623 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
625 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
629 if (test_lbuttondown_flag)
630 ShowWindow((HWND)wparam, SW_SHOW);
634 return DefWindowProcA(hwnd, msg, wparam, lparam);
637 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
641 case WM_GETMINMAXINFO:
643 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
645 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd, wparam, lparam);
646 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
647 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
648 minmax->ptReserved.x, minmax->ptReserved.y,
649 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
650 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
651 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
652 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
653 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
658 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
659 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
661 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd, cs->hwndParent, cs->style);
662 if (got_getminmaxinfo)
663 trace("%p got WM_GETMINMAXINFO\n", hwnd);
665 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
666 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
668 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
673 return DefWindowProcA(hwnd, msg, wparam, lparam);
676 static BOOL RegisterWindowClasses(void)
680 cls.style = CS_DBLCLKS;
681 cls.lpfnWndProc = main_window_procA;
684 cls.hInstance = GetModuleHandleA(0);
686 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
687 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
688 cls.lpszMenuName = NULL;
689 cls.lpszClassName = "MainWindowClass";
691 if(!RegisterClassA(&cls)) return FALSE;
694 cls.lpfnWndProc = tool_window_procA;
697 cls.hInstance = GetModuleHandleA(0);
699 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
700 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
701 cls.lpszMenuName = NULL;
702 cls.lpszClassName = "ToolWindowClass";
704 if(!RegisterClassA(&cls)) return FALSE;
709 static void verify_window_info(HWND hwnd, const WINDOWINFO *info, BOOL test_borders)
711 RECT rcWindow, rcClient;
715 ok(IsWindow(hwnd), "bad window handle\n");
717 GetWindowRect(hwnd, &rcWindow);
718 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow\n");
720 GetClientRect(hwnd, &rcClient);
721 /* translate to screen coordinates */
722 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
723 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient\n");
725 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
726 "wrong dwStyle: %08lx != %08lx\n", info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE));
727 ok(info->dwExStyle == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
728 "wrong dwExStyle: %08lx != %08lx\n", info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE));
729 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
730 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04lx != %04lx\n",
731 info->dwWindowStatus, status);
733 if (test_borders && !IsRectEmpty(&rcWindow))
735 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
736 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
738 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
739 "wrong cxWindowBorders %d != %ld\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
740 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
741 ok(info->cyWindowBorders == border,
742 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
745 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType\n");
746 ok(info->wCreatorVersion == 0x0400, "wrong wCreatorVersion %04x\n", info->wCreatorVersion);
749 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
751 AdjustWindowRectEx(rc, style, menu, exstyle);
752 /* AdjustWindowRectEx does not include scroll bars */
753 if (style & WS_VSCROLL)
755 if(exstyle & WS_EX_LEFTSCROLLBAR)
756 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
758 rc->right += GetSystemMetrics(SM_CXVSCROLL);
760 if (style & WS_HSCROLL)
761 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
764 static void test_nonclient_area(HWND hwnd)
766 DWORD style, exstyle;
767 RECT rc_window, rc_client, rc;
769 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
771 style = GetWindowLongA(hwnd, GWL_STYLE);
772 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
773 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
775 GetWindowRect(hwnd, &rc_window);
776 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
777 GetClientRect(hwnd, &rc_client);
778 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
780 /* avoid some cases when things go wrong */
781 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
782 rc_window.right > 32768 || rc_window.bottom > 32768) return;
784 CopyRect(&rc, &rc_client);
785 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
786 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
788 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
789 ok(EqualRect(&rc, &rc_window), "window rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
792 CopyRect(&rc, &rc_window);
793 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
794 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
795 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
796 ok(EqualRect(&rc, &rc_client), "client rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
798 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
802 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
803 SetRect(&rc_client, 0, 0, 250, 150);
804 CopyRect(&rc_window, &rc_client);
805 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
806 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
807 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
808 rc_window.left, rc_window.top, rc_window.right, rc_window.bottom);
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc.left, rc.top, rc.right, rc.bottom);
814 ok(EqualRect(&rc, &rc_client), "synthetic rect does not match: style:exstyle=0x%08lx:0x%08lx, menu=%d\n", style, exstyle, menu);
817 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
819 static const char *CBT_code_name[10] = {
830 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
832 trace("CBT: %d (%s), %08x, %08lx\n", nCode, code_name, wParam, lParam);
834 /* on HCBT_DESTROYWND window state is undefined */
835 if (nCode != HCBT_DESTROYWND && IsWindow((HWND)wParam))
841 /* Win98 actually does check the info.cbSize and doesn't allow
842 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
843 * WinXP do not check it at all.
845 info.cbSize = sizeof(WINDOWINFO);
846 ok(pGetWindowInfo((HWND)wParam, &info), "GetWindowInfo should not fail\n");
847 /* win2k SP4 returns broken border info if GetWindowInfo
848 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
850 verify_window_info((HWND)wParam, &info, nCode != HCBT_MINMAX);
858 #if 0 /* Uncomment this once the test succeeds in all cases */
859 static const RECT rc_null;
863 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
864 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
865 (HWND)wParam, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
866 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
868 /* WS_VISIBLE should be turned off yet */
869 style = createwnd->lpcs->style & ~WS_VISIBLE;
870 ok(style == GetWindowLongA((HWND)wParam, GWL_STYLE),
871 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
872 GetWindowLongA((HWND)wParam, GWL_STYLE), style);
874 #if 0 /* Uncomment this once the test succeeds in all cases */
875 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
877 ok(GetParent((HWND)wParam) == hwndMessage,
878 "wrong result from GetParent %p: message window %p\n",
879 GetParent((HWND)wParam), hwndMessage);
882 ok(!GetParent((HWND)wParam), "GetParent should return 0 at this point\n");
884 ok(!GetWindow((HWND)wParam, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
886 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
887 * Win9x still has them set to 0.
889 ok(GetWindow((HWND)wParam, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
890 ok(GetWindow((HWND)wParam, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
892 ok(!GetWindow((HWND)wParam, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
893 ok(!GetWindow((HWND)wParam, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
895 #if 0 /* Uncomment this once the test succeeds in all cases */
898 ok(pGetAncestor((HWND)wParam, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
899 ok(pGetAncestor((HWND)wParam, GA_ROOT) == (HWND)wParam,
900 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOT), (HWND)wParam);
902 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
903 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == hwndMessage,
904 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
906 ok(pGetAncestor((HWND)wParam, GA_ROOTOWNER) == (HWND)wParam,
907 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND)wParam, GA_ROOTOWNER), (HWND)wParam);
910 ok(GetWindowRect((HWND)wParam, &rc), "GetWindowRect failed\n");
911 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
912 ok(GetClientRect((HWND)wParam, &rc), "GetClientRect failed\n");
913 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
919 return CallNextHookEx(hhook, nCode, wParam, lParam);
922 static void test_shell_window(void)
926 HMODULE hinst, hUser32;
927 BOOL (WINAPI*SetShellWindow)(HWND);
928 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
929 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
930 HWND shellWindow, nextWnd;
932 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
934 trace("Skipping shell window test on Win9x\n");
938 shellWindow = GetShellWindow();
939 hinst = GetModuleHandle(0);
940 hUser32 = GetModuleHandleA("user32");
942 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
943 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
945 trace("previous shell window: %p\n", shellWindow);
951 ret = DestroyWindow(shellWindow);
952 error = GetLastError();
954 ok(!ret, "DestroyWindow(shellWindow)\n");
955 /* passes on Win XP, but not on Win98 */
956 ok(error==ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
958 /* close old shell instance */
959 GetWindowThreadProcessId(shellWindow, &pid);
960 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
961 ret = TerminateProcess(hProcess, 0);
962 ok(ret, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
963 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
964 CloseHandle(hProcess);
967 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
968 trace("created window 1: %p\n", hwnd1);
970 ret = SetShellWindow(hwnd1);
971 ok(ret, "first call to SetShellWindow(hwnd1)\n");
972 shellWindow = GetShellWindow();
973 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
975 ret = SetShellWindow(hwnd1);
976 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
978 ret = SetShellWindow(0);
979 error = GetLastError();
980 /* passes on Win XP, but not on Win98
981 ok(!ret, "reset shell window by SetShellWindow(0)\n");
982 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
984 ret = SetShellWindow(hwnd1);
985 /* passes on Win XP, but not on Win98
986 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
990 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
991 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
992 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
995 ret = DestroyWindow(hwnd1);
996 ok(ret, "DestroyWindow(hwnd1)\n");
998 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
999 trace("created window 2: %p\n", hwnd2);
1000 ret = SetShellWindow(hwnd2);
1001 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1003 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1004 trace("created window 3: %p\n", hwnd3);
1006 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1007 trace("created window 4: %p\n", hwnd4);
1009 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1010 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1012 ret = SetShellWindow(hwnd4);
1013 ok(ret, "SetShellWindow(hwnd4)\n");
1014 shellWindow = GetShellWindow();
1015 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1017 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1018 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1020 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1021 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1023 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1024 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1026 ret = SetShellWindow(hwnd3);
1027 ok(!ret, "SetShellWindow(hwnd3)\n");
1028 shellWindow = GetShellWindow();
1029 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1031 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1032 trace("created window 5: %p\n", hwnd5);
1033 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1034 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1038 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1039 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1042 /* destroy test windows */
1043 DestroyWindow(hwnd2);
1044 DestroyWindow(hwnd3);
1045 DestroyWindow(hwnd4);
1046 DestroyWindow(hwnd5);
1049 /************** MDI test ****************/
1051 static const char mdi_lParam_test_message[] = "just a test string";
1053 static void test_MDI_create(HWND parent, HWND mdi_client, INT first_id)
1055 MDICREATESTRUCTA mdi_cs;
1057 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1058 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1059 BOOL isWin9x = FALSE;
1061 mdi_cs.szClass = "MDI_child_Class_1";
1062 mdi_cs.szTitle = "MDI child";
1063 mdi_cs.hOwner = GetModuleHandle(0);
1064 mdi_cs.x = CW_USEDEFAULT;
1065 mdi_cs.y = CW_USEDEFAULT;
1066 mdi_cs.cx = CW_USEDEFAULT;
1067 mdi_cs.cy = CW_USEDEFAULT;
1069 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1070 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1071 ok(mdi_child != 0, "MDI child creation failed\n");
1072 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1073 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1074 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1076 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1077 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1078 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");
1083 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1084 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1085 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1087 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1091 ok(mdi_child != 0, "MDI child creation failed\n");
1092 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1093 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1094 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1097 /* test MDICREATESTRUCT A<->W mapping */
1098 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1100 mdi_cs.szClass = (LPCSTR)classW;
1101 mdi_cs.szTitle = (LPCSTR)titleW;
1102 SetLastError(0xdeadbeef);
1103 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1106 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1109 ok(mdi_child != 0, "MDI child creation failed\n");
1113 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1114 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1115 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1118 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1120 CW_USEDEFAULT, CW_USEDEFAULT,
1121 CW_USEDEFAULT, CW_USEDEFAULT,
1122 mdi_client, GetModuleHandle(0),
1123 (LPARAM)mdi_lParam_test_message);
1124 ok(mdi_child != 0, "MDI child creation failed\n");
1125 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1126 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1127 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1129 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1130 0x7fffffff, /* without WS_POPUP */
1131 CW_USEDEFAULT, CW_USEDEFAULT,
1132 CW_USEDEFAULT, CW_USEDEFAULT,
1133 mdi_client, GetModuleHandle(0),
1134 (LPARAM)mdi_lParam_test_message);
1135 ok(mdi_child != 0, "MDI child creation failed\n");
1136 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1137 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1138 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1140 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1141 0xffffffff, /* with WS_POPUP */
1142 CW_USEDEFAULT, CW_USEDEFAULT,
1143 CW_USEDEFAULT, CW_USEDEFAULT,
1144 mdi_client, GetModuleHandle(0),
1145 (LPARAM)mdi_lParam_test_message);
1146 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1148 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1152 ok(mdi_child != 0, "MDI child creation failed\n");
1153 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1154 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1155 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1158 /* test MDICREATESTRUCT A<->W mapping */
1159 SetLastError(0xdeadbeef);
1160 mdi_child = CreateMDIWindowW(classW, titleW,
1162 CW_USEDEFAULT, CW_USEDEFAULT,
1163 CW_USEDEFAULT, CW_USEDEFAULT,
1164 mdi_client, GetModuleHandle(0),
1165 (LPARAM)mdi_lParam_test_message);
1168 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1171 ok(mdi_child != 0, "MDI child creation failed\n");
1175 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1176 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1177 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1180 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1182 CW_USEDEFAULT, CW_USEDEFAULT,
1183 CW_USEDEFAULT, CW_USEDEFAULT,
1184 mdi_client, 0, GetModuleHandle(0),
1185 (LPVOID)mdi_lParam_test_message);
1186 ok(mdi_child != 0, "MDI child creation failed\n");
1187 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1188 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1189 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1191 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1192 0x7fffffff, /* without WS_POPUP */
1193 CW_USEDEFAULT, CW_USEDEFAULT,
1194 CW_USEDEFAULT, CW_USEDEFAULT,
1195 mdi_client, 0, GetModuleHandle(0),
1196 (LPVOID)mdi_lParam_test_message);
1197 ok(mdi_child != 0, "MDI child creation failed\n");
1198 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1199 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1200 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1202 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1203 0xffffffff, /* with WS_POPUP */
1204 CW_USEDEFAULT, CW_USEDEFAULT,
1205 CW_USEDEFAULT, CW_USEDEFAULT,
1206 mdi_client, 0, GetModuleHandle(0),
1207 (LPVOID)mdi_lParam_test_message);
1208 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1210 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1214 ok(mdi_child != 0, "MDI child creation failed\n");
1215 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1216 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1217 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1220 /* test MDICREATESTRUCT A<->W mapping */
1221 SetLastError(0xdeadbeef);
1222 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1224 CW_USEDEFAULT, CW_USEDEFAULT,
1225 CW_USEDEFAULT, CW_USEDEFAULT,
1226 mdi_client, 0, GetModuleHandle(0),
1227 (LPVOID)mdi_lParam_test_message);
1230 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1233 ok(mdi_child != 0, "MDI child creation failed\n");
1237 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == first_id, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1238 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1239 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1242 /* This test fails on Win9x */
1245 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 CW_USEDEFAULT, CW_USEDEFAULT,
1249 parent, 0, GetModuleHandle(0),
1250 (LPVOID)mdi_lParam_test_message);
1251 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1254 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1255 WS_CHILD, /* without WS_POPUP */
1256 CW_USEDEFAULT, CW_USEDEFAULT,
1257 CW_USEDEFAULT, CW_USEDEFAULT,
1258 mdi_client, 0, GetModuleHandle(0),
1259 (LPVOID)mdi_lParam_test_message);
1260 ok(mdi_child != 0, "MDI child creation failed\n");
1261 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1262 DestroyWindow(mdi_child);
1264 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1265 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1266 CW_USEDEFAULT, CW_USEDEFAULT,
1267 CW_USEDEFAULT, CW_USEDEFAULT,
1268 mdi_client, 0, GetModuleHandle(0),
1269 (LPVOID)mdi_lParam_test_message);
1270 ok(mdi_child != 0, "MDI child creation failed\n");
1271 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1272 DestroyWindow(mdi_child);
1274 /* maximized child */
1275 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1276 WS_CHILD | WS_MAXIMIZE,
1277 CW_USEDEFAULT, CW_USEDEFAULT,
1278 CW_USEDEFAULT, CW_USEDEFAULT,
1279 mdi_client, 0, GetModuleHandle(0),
1280 (LPVOID)mdi_lParam_test_message);
1281 ok(mdi_child != 0, "MDI child creation failed\n");
1282 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1283 DestroyWindow(mdi_child);
1285 trace("Creating maximized child with a caption\n");
1286 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1287 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1288 CW_USEDEFAULT, CW_USEDEFAULT,
1289 CW_USEDEFAULT, CW_USEDEFAULT,
1290 mdi_client, 0, GetModuleHandle(0),
1291 (LPVOID)mdi_lParam_test_message);
1292 ok(mdi_child != 0, "MDI child creation failed\n");
1293 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1294 DestroyWindow(mdi_child);
1296 trace("Creating maximized child with a caption and a thick frame\n");
1297 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1298 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1299 CW_USEDEFAULT, CW_USEDEFAULT,
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 mdi_client, 0, GetModuleHandle(0),
1302 (LPVOID)mdi_lParam_test_message);
1303 ok(mdi_child != 0, "MDI child creation failed\n");
1304 ok(GetWindowLongPtrA(mdi_child, GWLP_ID) == 0, "wrong child id %ld\n", GetWindowLongPtrA(mdi_child, GWLP_ID));
1305 DestroyWindow(mdi_child);
1308 /**********************************************************************
1309 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1311 * Note: The rule here is that client rect of the maximized MDI child
1312 * is equal to the client rect of the MDI client window.
1314 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1318 GetClientRect( client, &rect );
1319 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1320 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1322 rect.right -= rect.left;
1323 rect.bottom -= rect.top;
1324 lpMinMax->ptMaxSize.x = rect.right;
1325 lpMinMax->ptMaxSize.y = rect.bottom;
1327 lpMinMax->ptMaxPosition.x = rect.left;
1328 lpMinMax->ptMaxPosition.y = rect.top;
1330 trace("max rect (%ld,%ld - %ld, %ld)\n",
1331 rect.left, rect.top, rect.right, rect.bottom);
1334 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1341 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1342 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs->lpCreateParams;
1344 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1345 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1347 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1348 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1349 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1350 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1351 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1353 /* MDICREATESTRUCT should have original values */
1354 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1355 "mdi_cs->style does not match (%08lx)\n", mdi_cs->style);
1356 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1357 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1358 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1359 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1361 /* CREATESTRUCT should have fixed values */
1362 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1363 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1365 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1366 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1367 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1369 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1371 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1373 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1374 ok(cs->style == style,
1375 "cs->style does not match (%08lx)\n", cs->style);
1379 LONG style = mdi_cs->style;
1381 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1382 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1383 ok(cs->style == style,
1384 "cs->style does not match (%08lx)\n", cs->style);
1389 case WM_GETMINMAXINFO:
1391 HWND client = GetParent(hwnd);
1393 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1394 MINMAXINFO my_minmax;
1395 LONG style, exstyle;
1397 style = GetWindowLongA(hwnd, GWL_STYLE);
1398 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1400 GetWindowRect(client, &rc);
1401 trace("MDI client %p window size = (%ld x %ld)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1402 GetClientRect(client, &rc);
1403 trace("MDI client %p client size = (%ld x %ld)\n", client, rc.right, rc.bottom);
1404 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1405 GetSystemMetrics(SM_CYSCREEN));
1407 GetClientRect(client, &rc);
1408 if ((style & WS_CAPTION) == WS_CAPTION)
1409 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1410 AdjustWindowRectEx(&rc, style, 0, exstyle);
1411 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1413 trace("ptReserved = (%ld,%ld)\n"
1414 "ptMaxSize = (%ld,%ld)\n"
1415 "ptMaxPosition = (%ld,%ld)\n"
1416 "ptMinTrackSize = (%ld,%ld)\n"
1417 "ptMaxTrackSize = (%ld,%ld)\n",
1418 minmax->ptReserved.x, minmax->ptReserved.y,
1419 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1420 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1421 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1422 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1424 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1425 minmax->ptMaxSize.x, rc.right - rc.left);
1426 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1427 minmax->ptMaxSize.y, rc.bottom - rc.top);
1429 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1431 trace("DefMDIChildProc returned:\n"
1432 "ptReserved = (%ld,%ld)\n"
1433 "ptMaxSize = (%ld,%ld)\n"
1434 "ptMaxPosition = (%ld,%ld)\n"
1435 "ptMinTrackSize = (%ld,%ld)\n"
1436 "ptMaxTrackSize = (%ld,%ld)\n",
1437 minmax->ptReserved.x, minmax->ptReserved.y,
1438 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1439 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1440 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1441 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1443 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1444 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %ld != %ld\n",
1445 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1446 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %ld != %ld\n",
1447 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1452 case WM_MDIACTIVATE:
1454 HWND active, client = GetParent(hwnd);
1455 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1456 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1457 if (hwnd == (HWND)lparam) /* if we are being activated */
1458 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1460 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1464 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1467 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1474 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1476 trace("%s\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE");
1477 trace("x %d, y %d, cx %d, cy %d\n", cs->x, cs->y, cs->cx, cs->cy);
1479 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1480 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1482 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1483 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1485 /* CREATESTRUCT should have fixed values */
1486 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1488 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1489 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1491 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1492 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1493 while Win95, Win2k, WinXP do. */
1494 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1495 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1499 case WM_GETMINMAXINFO:
1501 HWND parent = GetParent(hwnd);
1503 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1504 LONG style, exstyle;
1506 trace("WM_GETMINMAXINFO\n");
1508 style = GetWindowLongA(hwnd, GWL_STYLE);
1509 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1511 GetClientRect(parent, &rc);
1512 trace("parent %p client size = (%ld x %ld)\n", parent, rc.right, rc.bottom);
1514 GetClientRect(parent, &rc);
1515 if ((style & WS_CAPTION) == WS_CAPTION)
1516 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1517 AdjustWindowRectEx(&rc, style, 0, exstyle);
1518 trace("calculated max child window size = (%ld x %ld)\n", rc.right-rc.left, rc.bottom-rc.top);
1520 trace("ptReserved = (%ld,%ld)\n"
1521 "ptMaxSize = (%ld,%ld)\n"
1522 "ptMaxPosition = (%ld,%ld)\n"
1523 "ptMinTrackSize = (%ld,%ld)\n"
1524 "ptMaxTrackSize = (%ld,%ld)\n",
1525 minmax->ptReserved.x, minmax->ptReserved.y,
1526 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
1527 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
1528 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
1529 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
1531 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %ld != %ld\n",
1532 minmax->ptMaxSize.x, rc.right - rc.left);
1533 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %ld != %ld\n",
1534 minmax->ptMaxSize.y, rc.bottom - rc.top);
1538 case WM_WINDOWPOSCHANGED:
1540 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1543 GetWindowRect(hwnd, &rc1);
1544 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1545 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1546 /* note: winpos coordinates are relative to parent */
1547 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1548 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1549 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1551 GetWindowRect(hwnd, &rc1);
1552 GetClientRect(hwnd, &rc2);
1553 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1554 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1555 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1558 case WM_WINDOWPOSCHANGING:
1560 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1561 WINDOWPOS my_winpos = *winpos;
1563 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1564 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1565 winpos->hwnd, winpos->hwndInsertAfter,
1566 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1568 DefWindowProcA(hwnd, msg, wparam, lparam);
1570 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1571 winpos->hwnd, winpos->hwndInsertAfter,
1572 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1574 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1575 "DefWindowProc should not change WINDOWPOS values\n");
1580 return DefWindowProcA(hwnd, msg, wparam, lparam);
1583 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1585 static HWND mdi_client;
1591 CLIENTCREATESTRUCT client_cs;
1594 GetClientRect(hwnd, &rc);
1596 client_cs.hWindowMenu = 0;
1597 client_cs.idFirstChild = 1;
1599 /* MDIClient without MDIS_ALLCHILDSTYLES */
1600 mdi_client = CreateWindowExA(0, "mdiclient",
1602 WS_CHILD /*| WS_VISIBLE*/,
1603 /* tests depend on a not zero MDIClient size */
1604 0, 0, rc.right, rc.bottom,
1605 hwnd, 0, GetModuleHandle(0),
1606 (LPVOID)&client_cs);
1608 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1609 DestroyWindow(mdi_client);
1611 /* MDIClient with MDIS_ALLCHILDSTYLES */
1612 mdi_client = CreateWindowExA(0, "mdiclient",
1614 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1615 /* tests depend on a not zero MDIClient size */
1616 0, 0, rc.right, rc.bottom,
1617 hwnd, 0, GetModuleHandle(0),
1618 (LPVOID)&client_cs);
1620 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1621 DestroyWindow(mdi_client);
1625 case WM_WINDOWPOSCHANGED:
1627 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1630 GetWindowRect(hwnd, &rc1);
1631 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1632 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1633 /* note: winpos coordinates are relative to parent */
1634 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1635 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1636 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1638 GetWindowRect(hwnd, &rc1);
1639 GetClientRect(hwnd, &rc2);
1640 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1641 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1642 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1645 case WM_WINDOWPOSCHANGING:
1647 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1648 WINDOWPOS my_winpos = *winpos;
1650 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1651 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1652 winpos->hwnd, winpos->hwndInsertAfter,
1653 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1655 DefWindowProcA(hwnd, msg, wparam, lparam);
1657 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1658 winpos->hwnd, winpos->hwndInsertAfter,
1659 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1661 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1662 "DefWindowProc should not change WINDOWPOS values\n");
1671 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1674 static BOOL mdi_RegisterWindowClasses(void)
1679 cls.lpfnWndProc = mdi_main_wnd_procA;
1682 cls.hInstance = GetModuleHandleA(0);
1684 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1685 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1686 cls.lpszMenuName = NULL;
1687 cls.lpszClassName = "MDI_parent_Class";
1688 if(!RegisterClassA(&cls)) return FALSE;
1690 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1691 cls.lpszClassName = "MDI_child_Class_1";
1692 if(!RegisterClassA(&cls)) return FALSE;
1694 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1695 cls.lpszClassName = "MDI_child_Class_2";
1696 if(!RegisterClassA(&cls)) return FALSE;
1701 static void test_mdi(void)
1706 if (!mdi_RegisterWindowClasses()) assert(0);
1708 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1709 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1710 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1711 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1712 GetDesktopWindow(), 0,
1713 GetModuleHandle(0), NULL);
1714 assert(mdi_hwndMain);
1716 while(GetMessage(&msg, 0, 0, 0))
1718 TranslateMessage(&msg);
1719 DispatchMessage(&msg);
1724 static void test_icons(void)
1728 HICON icon = LoadIconA(0, (LPSTR)IDI_APPLICATION);
1729 HICON icon2 = LoadIconA(0, (LPSTR)IDI_QUESTION);
1730 HICON small_icon = LoadImageA(0, (LPSTR)IDI_APPLICATION, IMAGE_ICON,
1731 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1734 cls.cbSize = sizeof(cls);
1736 cls.lpfnWndProc = DefWindowProcA;
1740 cls.hIcon = LoadIconA(0, (LPSTR)IDI_HAND);
1741 cls.hIconSm = small_icon;
1742 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
1743 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1744 cls.lpszMenuName = NULL;
1745 cls.lpszClassName = "IconWindowClass";
1747 RegisterClassExA(&cls);
1749 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1750 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1753 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1754 ok( res == 0, "wrong big icon %p/0\n", res );
1755 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1756 ok( res == 0, "wrong previous big icon %p/0\n", res );
1757 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1758 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1759 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1760 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1761 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1762 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1764 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1765 ok( res == 0, "wrong small icon %p/0\n", res );
1766 /* this test is XP specific */
1767 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1768 ok( res != 0, "wrong small icon %p\n", res );*/
1769 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1770 ok( res == 0, "wrong previous small icon %p/0\n", res );
1771 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1772 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1773 /* this test is XP specific */
1774 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1775 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1776 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1777 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1778 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1779 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1780 /* this test is XP specific */
1781 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1782 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1784 /* make sure the big icon hasn't changed */
1785 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1786 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1789 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1791 if (msg == WM_NCCALCSIZE)
1793 RECT *rect = (RECT *)lparam;
1794 /* first time around increase the rectangle, next time decrease it */
1795 if (rect->left == 100) InflateRect( rect, 10, 10 );
1796 else InflateRect( rect, -10, -10 );
1799 return DefWindowProc( hwnd, msg, wparam, lparam );
1802 static void test_SetWindowPos(HWND hwnd)
1804 RECT orig_win_rc, rect;
1806 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1808 SetRect(&rect, 111, 222, 333, 444);
1809 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1810 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1811 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1813 SetRect(&rect, 111, 222, 333, 444);
1814 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1815 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1816 "wrong window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1818 GetWindowRect(hwnd, &orig_win_rc);
1820 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1821 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1822 GetWindowRect( hwnd, &rect );
1823 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1824 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1825 GetClientRect( hwnd, &rect );
1826 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1827 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1828 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1830 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1831 GetWindowRect( hwnd, &rect );
1832 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1833 "invalid window rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1834 GetClientRect( hwnd, &rect );
1835 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1836 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1837 "invalid client rect %ld,%ld-%ld,%ld\n", rect.left, rect.top, rect.right, rect.bottom );
1839 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1840 orig_win_rc.right, orig_win_rc.bottom, 0);
1841 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1843 /* Win9x truncates coordinates to 16-bit irrespectively */
1846 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1847 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1849 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1850 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1853 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1854 orig_win_rc.right, orig_win_rc.bottom, 0);
1857 static void test_SetMenu(HWND parent)
1861 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1865 hMenu = CreateMenu();
1868 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1870 /* fails on (at least) Wine, NT4, XP SP2 */
1871 test_nonclient_area(parent);
1873 ret = GetMenu(parent);
1874 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1875 /* test whether we can destroy a menu assigned to a window */
1876 retok = DestroyMenu(hMenu);
1877 ok( retok, "DestroyMenu error %ld\n", GetLastError());
1878 ok(!IsMenu(hMenu), "menu handle should be not valid after DestroyMenu\n");
1879 ret = GetMenu(parent);
1880 /* This test fails on Win9x */
1882 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1883 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1884 test_nonclient_area(parent);
1886 hMenu = CreateMenu();
1890 ret = GetMenu(parent);
1891 ok(ret == 0, "unexpected menu id %p\n", ret);
1893 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1894 test_nonclient_area(parent);
1895 ret = GetMenu(parent);
1896 ok(ret == 0, "unexpected menu id %p\n", ret);
1898 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1900 /* fails on (at least) Wine, NT4, XP SP2 */
1901 test_nonclient_area(parent);
1903 ret = GetMenu(parent);
1904 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1906 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1907 test_nonclient_area(parent);
1908 ret = GetMenu(parent);
1909 ok(ret == 0, "unexpected menu id %p\n", ret);
1912 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1915 ret = GetMenu(child);
1916 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1918 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1919 test_nonclient_area(child);
1920 ret = GetMenu(child);
1921 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1923 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1924 test_nonclient_area(child);
1925 ret = GetMenu(child);
1926 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1928 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1929 test_nonclient_area(child);
1930 ret = GetMenu(child);
1931 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1933 style = GetWindowLong(child, GWL_STYLE);
1934 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1935 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1936 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1937 SetWindowLong(child, GWL_STYLE, style);
1939 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1940 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1941 SetWindowLong(child, GWL_STYLE, style);
1943 DestroyWindow(child);
1947 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1949 HWND child[5], hwnd;
1954 hwnd = GetWindow(parent, GW_CHILD);
1955 ok(!hwnd, "have to start without children to perform the test\n");
1957 for (i = 0; i < total; i++)
1959 if (style[i] & DS_CONTROL)
1961 child[i] = CreateWindowExA(0, MAKEINTATOMA(32770), "", style[i] & ~WS_VISIBLE,
1962 0,0,0,0, parent, (HMENU)i, 0, NULL);
1963 if (style[i] & WS_VISIBLE)
1964 ShowWindow(child[i], SW_SHOW);
1966 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
1969 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
1970 parent, (HMENU)i, 0, NULL);
1971 trace("child[%d] = %p\n", i, child[i]);
1972 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
1975 hwnd = GetWindow(parent, GW_CHILD);
1976 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
1977 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
1978 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
1980 for (i = 0; i < total; i++)
1982 trace("hwnd[%d] = %p\n", i, hwnd);
1983 ok(child[order[i]] == hwnd, "Z order of child #%d is wrong\n", i);
1985 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
1988 for (i = 0; i < total; i++)
1989 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
1992 static void test_children_zorder(HWND parent)
1994 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
1996 const int simple_order[5] = { 0, 1, 2, 3, 4 };
1998 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
1999 WS_CHILD | WS_VISIBLE, WS_CHILD,
2000 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2001 const int complex_order_1[1] = { 0 };
2002 const int complex_order_2[2] = { 1, 0 };
2003 const int complex_order_3[3] = { 1, 0, 2 };
2004 const int complex_order_4[4] = { 1, 0, 2, 3 };
2005 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2006 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2007 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2008 WS_CHILD | WS_VISIBLE };
2009 const int complex_order_6[3] = { 0, 1, 2 };
2011 /* simple WS_CHILD */
2012 test_window_tree(parent, simple_style, simple_order, 5);
2014 /* complex children styles */
2015 test_window_tree(parent, complex_style, complex_order_1, 1);
2016 test_window_tree(parent, complex_style, complex_order_2, 2);
2017 test_window_tree(parent, complex_style, complex_order_3, 3);
2018 test_window_tree(parent, complex_style, complex_order_4, 4);
2019 test_window_tree(parent, complex_style, complex_order_5, 5);
2021 /* another set of complex children styles */
2022 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2025 static void test_vis_rgn( HWND hwnd )
2027 RECT win_rect, rgn_rect;
2028 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2031 ShowWindow(hwnd,SW_SHOW);
2032 hdc = GetDC( hwnd );
2033 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2034 GetWindowRect( hwnd, &win_rect );
2035 GetRgnBox( hrgn, &rgn_rect );
2036 if (GetVersion() & 0x80000000)
2038 trace("win9x, mapping to screen coords\n");
2039 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2041 trace("win: %ld,%ld-%ld,%ld\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2042 trace("rgn: %ld,%ld-%ld,%ld\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2043 ok( win_rect.left <= rgn_rect.left, "rgn left %ld not inside win rect %ld\n",
2044 rgn_rect.left, win_rect.left );
2045 ok( win_rect.top <= rgn_rect.top, "rgn top %ld not inside win rect %ld\n",
2046 rgn_rect.top, win_rect.top );
2047 ok( win_rect.right >= rgn_rect.right, "rgn right %ld not inside win rect %ld\n",
2048 rgn_rect.right, win_rect.right );
2049 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %ld not inside win rect %ld\n",
2050 rgn_rect.bottom, win_rect.bottom );
2051 ReleaseDC( hwnd, hdc );
2054 static void test_SetFocus(HWND hwnd)
2058 /* check if we can set focus to non-visible windows */
2060 ShowWindow(hwnd, SW_SHOW);
2063 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2064 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2065 ShowWindow(hwnd, SW_HIDE);
2068 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2069 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2070 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2073 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2074 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2075 ShowWindow(child, SW_SHOW);
2076 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2077 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2078 ShowWindow(child, SW_HIDE);
2079 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2080 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2081 ShowWindow(child, SW_SHOW);
2083 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2084 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2085 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2087 ShowWindow(child, SW_HIDE);
2089 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2090 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2091 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2092 ShowWindow(child, SW_HIDE);
2093 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2095 ShowWindow(hwnd, SW_SHOW);
2096 ShowWindow(child, SW_SHOW);
2098 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2099 EnableWindow(hwnd, FALSE);
2100 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2101 EnableWindow(hwnd, TRUE);
2103 DestroyWindow( child );
2106 static void check_wnd_state(HWND active, HWND foreground, HWND focus, HWND capture)
2108 ok(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2110 ok(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2111 ok(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2112 ok(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2115 static void test_SetActiveWindow(HWND hwnd)
2119 ShowWindow(hwnd, SW_HIDE);
2122 check_wnd_state(0, 0, 0, 0);
2124 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2126 ShowWindow(hwnd, SW_SHOW);
2127 check_wnd_state(hwnd, hwnd, hwnd, 0);
2129 hwnd2 = SetActiveWindow(0);
2130 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2131 check_wnd_state(0, 0, 0, 0);
2133 hwnd2 = SetActiveWindow(hwnd);
2134 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2135 check_wnd_state(hwnd, hwnd, hwnd, 0);
2137 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2138 check_wnd_state(hwnd, hwnd, hwnd, 0);
2140 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2141 check_wnd_state(hwnd, hwnd, hwnd, 0);
2143 ShowWindow(hwnd, SW_HIDE);
2144 check_wnd_state(0, 0, 0, 0);
2146 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2147 SetActiveWindow(hwnd);
2148 check_wnd_state(hwnd, hwnd, hwnd, 0);
2150 ShowWindow(hwnd, SW_SHOW);
2151 check_wnd_state(hwnd, hwnd, hwnd, 0);
2153 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2154 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2156 DestroyWindow(hwnd2);
2157 check_wnd_state(hwnd, hwnd, hwnd, 0);
2159 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2160 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2162 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2163 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2165 DestroyWindow(hwnd2);
2166 check_wnd_state(hwnd, hwnd, hwnd, 0);
2169 static void test_SetForegroundWindow(HWND hwnd)
2174 ShowWindow(hwnd, SW_HIDE);
2177 check_wnd_state(0, 0, 0, 0);
2179 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2181 ShowWindow(hwnd, SW_SHOW);
2182 check_wnd_state(hwnd, hwnd, hwnd, 0);
2184 hwnd2 = SetActiveWindow(0);
2185 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2186 check_wnd_state(0, 0, 0, 0);
2188 ret = SetForegroundWindow(hwnd);
2189 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2190 check_wnd_state(hwnd, hwnd, hwnd, 0);
2192 SetLastError(0xdeadbeef);
2193 ret = SetForegroundWindow(0);
2194 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2195 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got error %ld expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2196 check_wnd_state(hwnd, hwnd, hwnd, 0);
2198 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2199 check_wnd_state(hwnd, hwnd, hwnd, 0);
2201 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2202 check_wnd_state(hwnd, hwnd, hwnd, 0);
2204 ShowWindow(hwnd, SW_HIDE);
2205 check_wnd_state(0, 0, 0, 0);
2207 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2208 ret = SetForegroundWindow(hwnd);
2209 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2210 check_wnd_state(hwnd, hwnd, hwnd, 0);
2212 ShowWindow(hwnd, SW_SHOW);
2213 check_wnd_state(hwnd, hwnd, hwnd, 0);
2215 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2216 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2218 DestroyWindow(hwnd2);
2219 check_wnd_state(hwnd, hwnd, hwnd, 0);
2221 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2222 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2224 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2225 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2227 DestroyWindow(hwnd2);
2228 check_wnd_state(hwnd, hwnd, hwnd, 0);
2231 static WNDPROC old_button_proc;
2233 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2238 key_state = GetKeyState(VK_LBUTTON);
2239 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2241 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2243 if (msg == WM_LBUTTONDOWN)
2247 check_wnd_state(button, button, button, button);
2249 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2251 trace("hwnd %p\n", hwnd);
2253 check_wnd_state(button, button, button, button);
2255 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2257 check_wnd_state(button, button, button, button);
2259 DestroyWindow(hwnd);
2261 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2263 trace("hwnd %p\n", hwnd);
2265 check_wnd_state(button, button, button, button);
2267 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2268 * match internal button state.
2270 SendMessage(button, WM_KILLFOCUS, 0, 0);
2271 check_wnd_state(button, button, button, 0);
2273 ShowWindow(hwnd, SW_SHOW);
2274 check_wnd_state(hwnd, hwnd, hwnd, 0);
2276 capture = SetCapture(hwnd);
2277 ok(capture == 0, "SetCapture() = %p\n", capture);
2279 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2281 DestroyWindow(hwnd);
2283 check_wnd_state(button, 0, button, 0);
2289 static void test_capture_1(void)
2291 HWND button, capture;
2293 capture = GetCapture();
2294 ok(capture == 0, "GetCapture() = %p\n", capture);
2296 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2298 trace("button %p\n", button);
2300 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2302 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2304 capture = SetCapture(button);
2305 ok(capture == 0, "SetCapture() = %p\n", capture);
2306 check_wnd_state(button, 0, button, button);
2308 DestroyWindow(button);
2309 check_wnd_state(0, 0, 0, 0);
2312 static void test_capture_2(void)
2314 HWND button, hwnd, capture;
2316 check_wnd_state(0, 0, 0, 0);
2318 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2320 trace("button %p\n", button);
2322 check_wnd_state(button, button, button, 0);
2324 capture = SetCapture(button);
2325 ok(capture == 0, "SetCapture() = %p\n", capture);
2327 check_wnd_state(button, button, button, button);
2329 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2330 * internal button state.
2332 SendMessage(button, WM_KILLFOCUS, 0, 0);
2333 check_wnd_state(button, button, button, button);
2335 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2337 trace("hwnd %p\n", hwnd);
2339 check_wnd_state(button, button, button, button);
2341 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2343 check_wnd_state(button, button, button, button);
2345 DestroyWindow(hwnd);
2347 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2349 trace("hwnd %p\n", hwnd);
2351 check_wnd_state(button, button, button, button);
2353 ShowWindow(hwnd, SW_SHOW);
2355 check_wnd_state(hwnd, hwnd, hwnd, button);
2357 capture = SetCapture(hwnd);
2358 ok(capture == button, "SetCapture() = %p\n", capture);
2360 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2362 DestroyWindow(hwnd);
2363 check_wnd_state(button, button, button, 0);
2365 DestroyWindow(button);
2366 check_wnd_state(0, 0, 0, 0);
2369 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2373 ShowWindow(hwnd1, SW_HIDE);
2374 ShowWindow(hwnd2, SW_HIDE);
2376 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2377 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2380 check_wnd_state(0, 0, 0, hwnd1);
2383 check_wnd_state(0, 0, 0, hwnd2);
2385 ShowWindow(hwnd1, SW_SHOW);
2386 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2388 ret = ReleaseCapture();
2389 ok (ret, "releasecapture did not return TRUE.\n");
2390 ret = ReleaseCapture();
2391 ok (ret, "releasecapture did not return TRUE after second try.\n");
2394 static void test_keyboard_input(HWND hwnd)
2399 ShowWindow(hwnd, SW_SHOW);
2403 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2406 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2408 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2410 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2411 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2412 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2413 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2414 ok( !ret, "message %04x available\n", msg.message);
2416 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2418 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2419 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2420 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2421 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2422 ok( !ret, "message %04x available\n", msg.message);
2424 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2426 keybd_event(VK_SPACE, 0, 0, 0);
2427 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2428 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2429 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2430 ok( !ret, "message %04x available\n", msg.message);
2433 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2435 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2437 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2438 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2439 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2440 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2441 ok( !ret, "message %04x available\n", msg.message);
2443 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2445 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2446 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2447 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2448 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2449 ok( !ret, "message %04x available\n", msg.message);
2451 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2453 keybd_event(VK_SPACE, 0, 0, 0);
2454 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2455 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2456 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2457 ok( !ret, "message %04x available\n", msg.message);
2460 static void test_mouse_input(HWND hwnd)
2470 ShowWindow(hwnd, SW_SHOW);
2473 GetWindowRect(hwnd, &rc);
2474 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2476 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2477 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2480 ShowWindow(popup, SW_SHOW);
2481 UpdateWindow(popup);
2483 GetWindowRect(popup, &rc);
2484 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2486 x = rc.left + (rc.right - rc.left) / 2;
2487 y = rc.top + (rc.bottom - rc.top) / 2;
2488 trace("setting cursor to (%d,%d)\n", x, y);
2492 ok(x == pt.x && y == pt.y, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt.x, pt.y, x, y);
2494 /* force the system to update its internal queue mouse position,
2495 * otherwise it won't generate relative mouse movements below.
2497 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2498 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2501 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2502 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2503 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2504 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2505 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2506 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2507 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2508 ok( !ret, "message %04x available\n", msg.message);
2510 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2511 ShowWindow(popup, SW_HIDE);
2512 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2513 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2514 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2516 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2517 ShowWindow(hwnd, SW_HIDE);
2518 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2519 ok( !ret, "message %04x available\n", msg.message);
2521 /* test mouse clicks */
2523 ShowWindow(hwnd, SW_SHOW);
2524 ShowWindow(popup, SW_SHOW);
2526 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2528 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2529 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2530 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2531 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2533 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2534 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2535 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2536 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2538 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2539 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2540 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2541 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2543 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2544 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2545 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2546 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2548 ok(PeekMessageA(&msg, 0, 0, 0, 0), "no message available\n");
2549 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2550 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2551 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2553 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2554 ok(!ret, "message %04x available\n", msg.message);
2556 ShowWindow(popup, SW_HIDE);
2557 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2559 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2560 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2561 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2562 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2564 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2565 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2566 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2567 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2569 test_lbuttondown_flag = TRUE;
2570 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2571 test_lbuttondown_flag = FALSE;
2573 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2574 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2575 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2576 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2577 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2579 /* Test WM_MOUSEACTIVATE */
2580 #define TEST_MOUSEACTIVATE(A,B) \
2581 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2582 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2584 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2585 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2586 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2587 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2588 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2589 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2590 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2591 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2592 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2593 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2594 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2595 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2596 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2597 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2598 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2599 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2600 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2601 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2602 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2603 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2604 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2605 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2606 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2607 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2609 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2610 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2612 DestroyWindow(popup);
2615 static void test_validatergn(HWND hwnd)
2621 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2622 ShowWindow(hwnd, SW_SHOW);
2623 UpdateWindow( hwnd);
2624 /* test that ValidateRect validates children*/
2625 InvalidateRect( child, NULL, 1);
2626 GetWindowRect( child, &rc);
2627 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2628 ret = GetUpdateRect( child, &rc2, 0);
2629 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2630 "Update rectangle is empty!\n");
2631 ValidateRect( hwnd, &rc);
2632 ret = GetUpdateRect( child, &rc2, 0);
2633 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2634 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2635 rc2.right, rc2.bottom);
2637 /* now test ValidateRgn */
2638 InvalidateRect( child, NULL, 1);
2639 GetWindowRect( child, &rc);
2640 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2641 rgn = CreateRectRgnIndirect( &rc);
2642 ValidateRgn( hwnd, rgn);
2643 ret = GetUpdateRect( child, &rc2, 0);
2644 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2645 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2.left, rc2.top,
2646 rc2.right, rc2.bottom);
2649 DestroyWindow( child );
2652 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2654 MoveWindow( hwnd, 0, 0, x, y, 0);
2655 GetWindowRect( hwnd, prc);
2656 trace("window rect is %ld,%ld - %ld,%ld\n",
2657 prc->left,prc->top,prc->right,prc->bottom);
2658 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2659 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2660 prc->left,prc->top,prc->right,prc->bottom);
2663 static void test_nccalcscroll(HWND parent)
2666 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2667 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2668 HWND hwnd = CreateWindowExA(0, "static", NULL,
2669 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2670 10, 10, 200, 200, parent, 0, 0, NULL);
2671 ShowWindow( parent, SW_SHOW);
2672 UpdateWindow( parent);
2674 /* test window too low for a horizontal scroll bar */
2675 nccalchelper( hwnd, 100, sbheight, &rc1);
2676 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2677 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2679 /* test window just high enough for a horizontal scroll bar */
2680 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2681 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2682 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2684 /* test window too narrow for a vertical scroll bar */
2685 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2686 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2687 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2689 /* test window just wide enough for a vertical scroll bar */
2690 nccalchelper( hwnd, sbwidth, 100, &rc1);
2691 ok( rc1.right - rc1.left == 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2692 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
2694 /* same test, but with client edge: not enough width */
2695 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
2696 nccalchelper( hwnd, sbwidth, 100, &rc1);
2697 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
2698 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2699 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
2701 DestroyWindow( hwnd);
2704 static void test_SetParent(void)
2707 HWND desktop = GetDesktopWindow();
2709 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
2710 HWND parent, child1, child2, child3, child4, sibling;
2712 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2713 100, 100, 200, 200, 0, 0, 0, NULL);
2714 assert(parent != 0);
2715 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2716 0, 0, 50, 50, parent, 0, 0, NULL);
2717 assert(child1 != 0);
2718 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2719 0, 0, 50, 50, child1, 0, 0, NULL);
2720 assert(child2 != 0);
2721 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
2722 0, 0, 50, 50, child2, 0, 0, NULL);
2723 assert(child3 != 0);
2724 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
2725 0, 0, 50, 50, child3, 0, 0, NULL);
2726 assert(child4 != 0);
2728 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2729 parent, child1, child2, child3, child4);
2731 check_parents(parent, desktop, 0, 0, 0, parent, parent);
2732 check_parents(child1, parent, parent, parent, 0, parent, parent);
2733 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2734 check_parents(child3, child2, child2, child2, 0, child2, parent);
2735 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2738 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
2739 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
2740 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2741 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
2742 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2745 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
2747 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
2749 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
2750 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
2751 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
2752 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
2753 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
2754 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
2756 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
2759 if (!is_win9x) /* Win9x doesn't survive this test */
2761 ok(!SetParent(parent, child1), "SetParent should fail\n");
2762 ok(!SetParent(child2, child3), "SetParent should fail\n");
2763 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
2764 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
2765 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
2766 ok(!SetParent(child2, parent), "SetParent should fail\n");
2767 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
2769 check_parents(parent, child4, child4, 0, 0, child4, parent);
2770 check_parents(child1, parent, parent, parent, 0, child4, parent);
2771 check_parents(child2, desktop, parent, parent, parent, child2, parent);
2772 check_parents(child3, child2, child2, child2, 0, child2, parent);
2773 check_parents(child4, desktop, child2, child2, child2, child4, parent);
2776 hMenu = CreateMenu();
2777 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
2778 100, 100, 200, 200, 0, hMenu, 0, NULL);
2779 assert(sibling != 0);
2781 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
2782 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
2784 ret = DestroyWindow(parent);
2785 ok( ret, "DestroyWindow() error %ld\n", GetLastError());
2787 ok(!IsWindow(parent), "parent still exists\n");
2788 ok(!IsWindow(sibling), "sibling still exists\n");
2789 ok(!IsWindow(child1), "child1 still exists\n");
2790 ok(!IsWindow(child2), "child2 still exists\n");
2791 ok(!IsWindow(child3), "child3 still exists\n");
2792 ok(!IsWindow(child4), "child4 still exists\n");
2795 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2797 LPCREATESTRUCT lpcs;
2804 lpcs = (LPCREATESTRUCT)lparam;
2805 lpss = (LPSTYLESTRUCT)lpcs->lpCreateParams;
2808 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
2809 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
2810 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
2811 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
2813 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2815 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
2816 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2817 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
2819 ok(lpss->styleNew == lpcs->style,
2820 "Style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2821 lpss->styleNew, lpcs->style);
2825 return DefWindowProc(hwnd, msg, wparam, lparam);
2828 static ATOM atomStyleCheckClass;
2830 static void register_style_check_class(void)
2838 GetModuleHandle(NULL),
2840 LoadCursor(NULL, IDC_ARROW),
2841 (HBRUSH)(COLOR_BTNFACE+1),
2843 TEXT("WineStyleCheck"),
2846 atomStyleCheckClass = RegisterClass(&wc);
2849 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
2851 DWORD dwActualStyle;
2852 DWORD dwActualExStyle;
2855 HWND hwndParent = NULL;
2858 ss.styleNew = dwStyleIn;
2859 ss.styleOld = dwExStyleIn;
2861 if (dwStyleIn & WS_CHILD)
2863 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
2864 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
2867 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
2868 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
2871 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
2873 TranslateMessage(&msg);
2874 DispatchMessage(&msg);
2877 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
2878 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
2879 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
2880 "Style (0x%08lx) should really be 0x%08lx and/or Ex style (0x%08lx) should really be 0x%08lx\n",
2881 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
2883 DestroyWindow(hwnd);
2884 if (hwndParent) DestroyWindow(hwndParent);
2887 /* tests what window styles the window manager automatically adds */
2888 static void test_window_styles(void)
2890 register_style_check_class();
2892 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
2893 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
2894 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
2895 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
2896 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
2897 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
2898 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
2899 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2900 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
2901 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
2902 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
2905 static void test_scrollvalidate( HWND parent)
2908 HRGN hrgn=CreateRectRgn(0,0,0,0);
2909 HRGN exprgn, tmprgn, clipping;
2910 RECT rc, rcu, cliprc;
2911 /* create two overlapping child windows. The visual region
2912 * of hwnd1 is clipped by the overlapping part of
2913 * hwnd2 because of the WS_CLIPSIBLING style */
2916 clipping = CreateRectRgn(0,0,0,0);
2917 tmprgn = CreateRectRgn(0,0,0,0);
2918 exprgn = CreateRectRgn(0,0,0,0);
2919 hwnd2 = CreateWindowExA(0, "static", NULL,
2920 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2921 75, 30, 100, 100, parent, 0, 0, NULL);
2922 hwnd1 = CreateWindowExA(0, "static", NULL,
2923 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
2924 25, 50, 100, 100, parent, 0, 0, NULL);
2925 ShowWindow( parent, SW_SHOW);
2926 UpdateWindow( parent);
2927 GetClientRect( hwnd1, &rc);
2929 SetRectRgn( clipping, 10, 10, 90, 90);
2930 hdc = GetDC( hwnd1);
2931 /* for a visual touch */
2932 TextOut( hdc, 0,10, "0123456789", 10);
2933 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2934 if (winetest_debug > 0) dump_region(hrgn);
2935 /* create a region with what is expected */
2936 SetRectRgn( exprgn, 39,0,49,74);
2937 SetRectRgn( tmprgn, 88,79,98,93);
2938 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2939 SetRectRgn( tmprgn, 0,93,98,98);
2940 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2941 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2942 trace("update rect is %ld,%ld - %ld,%ld\n",
2943 rcu.left,rcu.top,rcu.right,rcu.bottom);
2944 /* now with clipping region */
2945 SelectClipRgn( hdc, clipping);
2946 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
2947 if (winetest_debug > 0) dump_region(hrgn);
2948 /* create a region with what is expected */
2949 SetRectRgn( exprgn, 39,10,49,74);
2950 SetRectRgn( tmprgn, 80,79,90,85);
2951 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2952 SetRectRgn( tmprgn, 10,85,90,90);
2953 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2954 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2955 trace("update rect is %ld,%ld - %ld,%ld\n",
2956 rcu.left,rcu.top,rcu.right,rcu.bottom);
2957 ReleaseDC( hwnd1, hdc);
2959 /* test scrolling a window with an update region */
2960 DestroyWindow( hwnd2);
2961 ValidateRect( hwnd1, NULL);
2962 SetRect( &rc, 40,40, 50,50);
2963 InvalidateRect( hwnd1, &rc, 1);
2964 GetClientRect( hwnd1, &rc);
2966 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
2967 SW_SCROLLCHILDREN | SW_INVALIDATE);
2968 if (winetest_debug > 0) dump_region(hrgn);
2969 SetRectRgn( exprgn, 88,0,98,98);
2970 SetRectRgn( tmprgn, 30, 40, 50, 50);
2971 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2972 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2974 /* now test ScrollWindowEx with a combination of
2975 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
2976 /* make hwnd2 the child of hwnd1 */
2977 hwnd2 = CreateWindowExA(0, "static", NULL,
2978 WS_CHILD| WS_VISIBLE | WS_BORDER ,
2979 50, 50, 100, 100, hwnd1, 0, 0, NULL);
2980 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
2981 GetClientRect( hwnd1, &rc);
2984 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
2985 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
2986 ValidateRect( hwnd1, NULL);
2987 ValidateRect( hwnd2, NULL);
2988 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
2989 SW_SCROLLCHILDREN | SW_INVALIDATE);
2990 if (winetest_debug > 0) dump_region(hrgn);
2991 SetRectRgn( exprgn, 88,0,98,88);
2992 SetRectRgn( tmprgn, 0,88,98,98);
2993 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
2994 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
2996 /* SW_SCROLLCHILDREN */
2997 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
2998 ValidateRect( hwnd1, NULL);
2999 ValidateRect( hwnd2, NULL);
3000 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3001 if (winetest_debug > 0) dump_region(hrgn);
3002 /* expected region is the same as in previous test */
3003 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3005 /* no SW_SCROLLCHILDREN */
3006 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3007 ValidateRect( hwnd1, NULL);
3008 ValidateRect( hwnd2, NULL);
3009 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3010 if (winetest_debug > 0) dump_region(hrgn);
3011 /* expected region is the same as in previous test */
3012 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3014 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3015 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3016 ValidateRect( hwnd1, NULL);
3017 ValidateRect( hwnd2, NULL);
3018 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3019 if (winetest_debug > 0) dump_region(hrgn);
3020 SetRectRgn( exprgn, 88,0,98,20);
3021 SetRectRgn( tmprgn, 20,20,98,30);
3022 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3023 SetRectRgn( tmprgn, 20,30,30,88);
3024 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3025 SetRectRgn( tmprgn, 0,88,30,98);
3026 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3027 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3030 DeleteObject( hrgn);
3031 DeleteObject( exprgn);
3032 DeleteObject( tmprgn);
3033 DestroyWindow( hwnd1);
3034 DestroyWindow( hwnd2);
3037 /* couple of tests of return values of scrollbar functions
3038 * called on a scrollbarless window */
3039 static void test_scroll(void)
3044 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3045 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3046 100, 100, 200, 200, 0, 0, 0, NULL);
3048 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3049 ok( ret, "GetScrollRange returns FALSE\n");
3050 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3051 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3052 si.cbSize = sizeof( si);
3053 si.fMask = SIF_PAGE;
3054 si.nPage = 0xdeadbeef;
3055 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3056 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3057 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3059 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3060 ok( ret, "GetScrollRange returns FALSE\n");
3061 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3062 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3063 si.cbSize = sizeof( si);
3064 si.fMask = SIF_PAGE;
3065 si.nPage = 0xdeadbeef;
3066 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3067 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3068 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3070 DestroyWindow( hwnd);
3073 static void test_scrolldc( HWND parent)
3076 HRGN exprgn, tmprgn, hrgn;
3077 RECT rc, rc2, rcu, cliprc;
3081 hrgn = CreateRectRgn(0,0,0,0);
3082 tmprgn = CreateRectRgn(0,0,0,0);
3083 exprgn = CreateRectRgn(0,0,0,0);
3085 hwnd1 = CreateWindowExA(0, "static", NULL,
3086 WS_CHILD| WS_VISIBLE,
3087 25, 50, 100, 100, parent, 0, 0, NULL);
3088 ShowWindow( parent, SW_SHOW);
3089 UpdateWindow( parent);
3090 GetClientRect( hwnd1, &rc);
3091 hdc = GetDC( hwnd1);
3092 /* paint the upper half of the window black */
3094 rc2.bottom = ( rc.top + rc.bottom) /2;
3095 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3096 /* clip region is the lower half */
3098 cliprc.top = (rc.top + rc.bottom) /2;
3099 /* test whether scrolled pixels are properly clipped */
3100 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3101 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3102 /* this scroll should not cause any visible changes */
3103 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3104 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3105 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3106 /* test with NULL clip rect */
3107 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3108 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3109 trace("update rect: %ld,%ld - %ld,%ld\n",
3110 rcu.left, rcu.top, rcu.right, rcu.bottom);
3111 if (winetest_debug > 0) dump_region(hrgn);
3112 SetRect(&rc2, 0, 0, 100, 100);
3113 ok(EqualRect(&rcu, &rc2), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
3114 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3116 SetRectRgn( exprgn, 0, 0, 20, 80);
3117 SetRectRgn( tmprgn, 0, 80, 100, 100);
3118 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3119 if (winetest_debug > 0) dump_region(exprgn);
3120 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3121 /* test clip rect > scroll rect */
3122 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3124 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3125 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3126 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3127 SetRectRgn( exprgn, 25, 25, 75, 35);
3128 SetRectRgn( tmprgn, 25, 35, 35, 75);
3129 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3130 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3131 colr = GetPixel( hdc, 80, 80);
3132 ok ( colr == 0, "pixel should be black, color is %08lx\n", colr);
3133 trace("update rect: %ld,%ld - %ld,%ld\n",
3134 rcu.left, rcu.top, rcu.right, rcu.bottom);
3135 if (winetest_debug > 0) dump_region(hrgn);
3139 DeleteObject(exprgn);
3140 DeleteObject(tmprgn);
3141 DestroyWindow(hwnd1);
3144 static void test_params(void)
3149 /* Just a param check */
3150 SetLastError(0xdeadbeef);
3151 rc = GetWindowText(hwndMain2, NULL, 1024);
3152 ok( rc==0, "GetWindowText: rc=%d err=%ld\n",rc,GetLastError());
3154 SetLastError(0xdeadbeef);
3155 hwnd=CreateWindow("LISTBOX", "TestList",
3156 (LBS_STANDARD & ~LBS_SORT),
3158 NULL, (HMENU)1, NULL, 0);
3160 ok(!hwnd, "CreateWindow with invalid menu handle should fail\n");
3161 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3162 GetLastError() == 0xdeadbeef, /* Win9x */
3163 "wrong last error value %ld\n", GetLastError());
3166 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3170 hwnd = CreateWindowEx(exStyle, class, class, style,
3177 trace("Failed to create window class=%s, style=0x%08lx, exStyle=0x%08lx\n", class, style, exStyle);
3180 ShowWindow(hwnd, SW_SHOW);
3182 test_nonclient_area(hwnd);
3185 DestroyWindow(hwnd);
3188 static BOOL AWR_init(void)
3192 class.style = CS_HREDRAW | CS_VREDRAW;
3193 class.lpfnWndProc = DefWindowProcA;
3194 class.cbClsExtra = 0;
3195 class.cbWndExtra = 0;
3196 class.hInstance = 0;
3197 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3198 class.hCursor = LoadCursor (0, IDC_ARROW);
3199 class.hbrBackground = 0;
3200 class.lpszMenuName = 0;
3201 class.lpszClassName = szAWRClass;
3203 if (!RegisterClass (&class)) {
3204 ok(FALSE, "RegisterClass failed\n");
3208 hmenu = CreateMenu();
3211 ok(hmenu != 0, "Failed to create menu\n");
3212 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3218 static void test_AWR_window_size(BOOL menu)
3222 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3225 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3226 WS_HSCROLL, WS_VSCROLL
3230 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3233 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3234 WS_EX_DLGMODALFRAME,
3241 /* A exhaustive check of all the styles takes too long
3242 * so just do a (hopefully representative) sample
3244 for (i = 0; i < COUNTOF(styles); ++i)
3245 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3246 for (i = 0; i < COUNTOF(exStyles); ++i) {
3247 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3248 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3253 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3255 static void test_AdjustWindowRect(void)
3260 SHOWSYSMETRIC(SM_CYCAPTION);
3261 SHOWSYSMETRIC(SM_CYSMCAPTION);
3262 SHOWSYSMETRIC(SM_CYMENU);
3263 SHOWSYSMETRIC(SM_CXEDGE);
3264 SHOWSYSMETRIC(SM_CYEDGE);
3265 SHOWSYSMETRIC(SM_CXVSCROLL);
3266 SHOWSYSMETRIC(SM_CYHSCROLL);
3267 SHOWSYSMETRIC(SM_CXFRAME);
3268 SHOWSYSMETRIC(SM_CYFRAME);
3269 SHOWSYSMETRIC(SM_CXDLGFRAME);
3270 SHOWSYSMETRIC(SM_CYDLGFRAME);
3271 SHOWSYSMETRIC(SM_CXBORDER);
3272 SHOWSYSMETRIC(SM_CYBORDER);
3274 test_AWR_window_size(FALSE);
3275 test_AWR_window_size(TRUE);
3279 #undef SHOWSYSMETRIC
3282 /* Global variables to trigger exit from loop */
3283 static int redrawComplete, WMPAINT_count;
3285 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3290 trace("doing WM_PAINT %d\n", WMPAINT_count);
3292 if (WMPAINT_count > 10 && redrawComplete == 0) {
3294 BeginPaint(hwnd, &ps);
3295 EndPaint(hwnd, &ps);
3301 return DefWindowProc(hwnd, msg, wparam, lparam);
3304 /* Ensure we exit from RedrawNow regardless of invalidated area */
3305 static void test_redrawnow(void)
3310 cls.style = CS_DBLCLKS;
3311 cls.lpfnWndProc = redraw_window_procA;
3314 cls.hInstance = GetModuleHandleA(0);
3316 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3317 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3318 cls.lpszMenuName = NULL;
3319 cls.lpszClassName = "RedrawWindowClass";
3321 if(!RegisterClassA(&cls)) {
3322 trace("Register failed %ld\n", GetLastError());
3326 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3327 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3329 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3330 ShowWindow(hwndMain, SW_SHOW);
3331 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3332 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3333 ok( WMPAINT_count == 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3334 redrawComplete = TRUE;
3335 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3338 DestroyWindow( hwndMain);
3341 struct parentdc_stat {
3347 struct parentdc_test {
3348 struct parentdc_stat main, main_todo;
3349 struct parentdc_stat child1, child1_todo;
3350 struct parentdc_stat child2, child2_todo;
3353 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3358 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3363 trace("doing WM_PAINT on %p\n", hwnd);
3364 GetClientRect(hwnd, &rc);
3365 CopyRect(&t->client, &rc);
3366 trace("client rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3367 GetWindowRect(hwnd, &rc);
3368 trace("window rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3369 BeginPaint(hwnd, &ps);
3370 CopyRect(&t->paint, &ps.rcPaint);
3371 GetClipBox(ps.hdc, &rc);
3372 CopyRect(&t->clip, &rc);
3373 trace("clip rect (%ld, %ld)-(%ld, %ld)\n", rc.left, rc.top, rc.right, rc.bottom);
3374 trace("paint rect (%ld, %ld)-(%ld, %ld)\n", ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3375 EndPaint(hwnd, &ps);
3378 return DefWindowProc(hwnd, msg, wparam, lparam);
3381 static void zero_parentdc_stat(struct parentdc_stat *t)
3383 SetRectEmpty(&t->client);
3384 SetRectEmpty(&t->clip);
3385 SetRectEmpty(&t->paint);
3388 static void zero_parentdc_test(struct parentdc_test *t)
3390 zero_parentdc_stat(&t->main);
3391 zero_parentdc_stat(&t->child1);
3392 zero_parentdc_stat(&t->child2);
3395 #define parentdc_field_ok(t, w, r, f, got) \
3396 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3397 ": expected %ld, got %ld\n", \
3400 #define parentdc_todo_field_ok(t, w, r, f, got) \
3401 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3402 else parentdc_field_ok(t, w, r, f, got)
3404 #define parentdc_rect_ok(t, w, r, got) \
3405 parentdc_todo_field_ok(t, w, r, left, got); \
3406 parentdc_todo_field_ok(t, w, r, top, got); \
3407 parentdc_todo_field_ok(t, w, r, right, got); \
3408 parentdc_todo_field_ok(t, w, r, bottom, got);
3410 #define parentdc_win_ok(t, w, got) \
3411 parentdc_rect_ok(t, w, client, got); \
3412 parentdc_rect_ok(t, w, clip, got); \
3413 parentdc_rect_ok(t, w, paint, got);
3415 #define parentdc_ok(t, got) \
3416 parentdc_win_ok(t, main, got); \
3417 parentdc_win_ok(t, child1, got); \
3418 parentdc_win_ok(t, child2, got);
3420 static void test_csparentdc(void)
3422 WNDCLASSA clsMain, cls;
3423 HWND hwndMain, hwnd1, hwnd2;
3427 struct parentdc_test test_answer;
3429 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3430 const struct parentdc_test test1 =
3432 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3433 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3434 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3437 const struct parentdc_test test2 =
3439 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3440 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3441 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3444 const struct parentdc_test test3 =
3446 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3447 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3448 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3451 const struct parentdc_test test4 =
3453 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3454 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3455 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3458 const struct parentdc_test test5 =
3460 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3461 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3462 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3465 const struct parentdc_test test6 =
3467 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3468 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3469 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3472 const struct parentdc_test test7 =
3474 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3475 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3476 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3480 clsMain.style = CS_DBLCLKS;
3481 clsMain.lpfnWndProc = parentdc_window_procA;
3482 clsMain.cbClsExtra = 0;
3483 clsMain.cbWndExtra = 0;
3484 clsMain.hInstance = GetModuleHandleA(0);
3486 clsMain.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3487 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3488 clsMain.lpszMenuName = NULL;
3489 clsMain.lpszClassName = "ParentDcMainWindowClass";
3491 if(!RegisterClassA(&clsMain)) {
3492 trace("Register failed %ld\n", GetLastError());
3496 cls.style = CS_DBLCLKS | CS_PARENTDC;
3497 cls.lpfnWndProc = parentdc_window_procA;
3500 cls.hInstance = GetModuleHandleA(0);
3502 cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
3503 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3504 cls.lpszMenuName = NULL;
3505 cls.lpszClassName = "ParentDcWindowClass";
3507 if(!RegisterClassA(&cls)) {
3508 trace("Register failed %ld\n", GetLastError());
3512 SetRect(&rc, 0, 0, 150, 150);
3513 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3514 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3515 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3516 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3517 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3518 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3519 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3520 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3521 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3522 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3523 ShowWindow(hwndMain, SW_SHOW);
3524 ShowWindow(hwnd1, SW_SHOW);
3525 ShowWindow(hwnd2, SW_SHOW);
3528 zero_parentdc_test(&test_answer);
3529 InvalidateRect(hwndMain, NULL, TRUE);
3530 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3531 parentdc_ok(test1, test_answer);
3533 zero_parentdc_test(&test_answer);
3534 SetRect(&rc, 0, 0, 50, 50);
3535 InvalidateRect(hwndMain, &rc, TRUE);
3536 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3537 parentdc_ok(test2, test_answer);
3539 zero_parentdc_test(&test_answer);
3540 SetRect(&rc, 0, 0, 10, 10);
3541 InvalidateRect(hwndMain, &rc, TRUE);
3542 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3543 parentdc_ok(test3, test_answer);
3545 zero_parentdc_test(&test_answer);
3546 SetRect(&rc, 40, 40, 50, 50);
3547 InvalidateRect(hwndMain, &rc, TRUE);
3548 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3549 parentdc_ok(test4, test_answer);
3551 zero_parentdc_test(&test_answer);
3552 SetRect(&rc, 20, 20, 60, 60);
3553 InvalidateRect(hwndMain, &rc, TRUE);
3554 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3555 parentdc_ok(test5, test_answer);
3557 zero_parentdc_test(&test_answer);
3558 SetRect(&rc, 0, 0, 10, 10);
3559 InvalidateRect(hwnd1, &rc, TRUE);
3560 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3561 parentdc_ok(test6, test_answer);
3563 zero_parentdc_test(&test_answer);
3564 SetRect(&rc, -5, -5, 65, 65);
3565 InvalidateRect(hwnd1, &rc, TRUE);
3566 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3567 parentdc_ok(test7, test_answer);
3569 DestroyWindow(hwndMain);
3570 DestroyWindow(hwnd1);
3571 DestroyWindow(hwnd2);
3574 static void test_IsWindowUnicode(void)
3576 static const char ansi_class_nameA[] = "ansi class name";
3577 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3578 static const char unicode_class_nameA[] = "unicode class name";
3579 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3584 memset(&classW, 0, sizeof(classW));
3585 classW.hInstance = GetModuleHandleA(0);
3586 classW.lpfnWndProc = DefWindowProcW;
3587 classW.lpszClassName = unicode_class_nameW;
3588 if (!RegisterClassW(&classW)) return;
3590 memset(&classA, 0, sizeof(classA));
3591 classA.hInstance = GetModuleHandleA(0);
3592 classA.lpfnWndProc = DefWindowProcA;
3593 classA.lpszClassName = ansi_class_nameA;
3594 assert(RegisterClassA(&classA));
3596 /* unicode class: window proc */
3597 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3598 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3601 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3602 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3603 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3604 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3605 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3607 DestroyWindow(hwnd);
3609 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3610 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3613 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3614 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3615 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3616 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3617 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3619 DestroyWindow(hwnd);
3621 /* ansi class: window proc */
3622 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3623 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3626 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3627 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3628 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3629 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3630 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3632 DestroyWindow(hwnd);
3634 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3635 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3638 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3639 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3640 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3641 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3642 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3644 DestroyWindow(hwnd);
3646 /* unicode class: class proc */
3647 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3648 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3651 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3652 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3653 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3654 /* do not restore class window proc back to unicode */
3656 DestroyWindow(hwnd);
3658 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3659 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3662 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3663 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3664 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3666 DestroyWindow(hwnd);
3668 /* ansi class: class proc */
3669 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3670 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3673 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3674 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcW);
3675 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3676 /* do not restore class window proc back to ansi */
3678 DestroyWindow(hwnd);
3680 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3681 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3684 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3685 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)DefWindowProcA);
3686 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3688 DestroyWindow(hwnd);
3691 static void test_CreateWindow(void)
3696 #define expect_menu(window, menu) \
3697 SetLastError(0xdeadbeef); \
3698 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %ld\n", GetLastError())
3700 #define expect_style(window, style)\
3701 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %lx != %lx\n", (long)(style), GetWindowLong(window, GWL_STYLE))
3703 #define expect_ex_style(window, ex_style)\
3704 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %lx != %lx\n", (long)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3706 hmenu = CreateMenu();
3708 parent = GetDesktopWindow();
3709 assert(parent != 0);
3711 SetLastError(0xdeadbeef);
3712 ok(IsMenu(hmenu), "IsMenu error %ld\n", GetLastError());
3714 SetLastError(0xdeadbeef);
3715 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
3716 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3717 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3718 expect_menu(hwnd, 1);
3719 expect_style(hwnd, WS_CHILD);
3720 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3721 DestroyWindow(hwnd);
3723 SetLastError(0xdeadbeef);
3724 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
3725 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3726 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3727 expect_menu(hwnd, 1);
3728 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3729 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3730 DestroyWindow(hwnd);
3732 SetLastError(0xdeadbeef);
3733 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
3734 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3735 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3736 expect_menu(hwnd, 1);
3737 expect_style(hwnd, WS_CHILD);
3738 expect_ex_style(hwnd, 0);
3739 DestroyWindow(hwnd);
3741 SetLastError(0xdeadbeef);
3742 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
3743 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
3744 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3745 expect_menu(hwnd, 1);
3746 expect_style(hwnd, WS_CHILD | WS_CAPTION);
3747 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3748 DestroyWindow(hwnd);
3750 SetLastError(0xdeadbeef);
3751 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3752 0, 0, 100, 100, parent, hmenu, 0, NULL);
3753 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3754 expect_menu(hwnd, hmenu);
3755 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3756 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3757 DestroyWindow(hwnd);
3758 SetLastError(0xdeadbeef);
3759 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3760 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3762 hmenu = CreateMenu();
3764 SetLastError(0xdeadbeef);
3765 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
3766 0, 0, 100, 100, parent, hmenu, 0, NULL);
3767 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3768 expect_menu(hwnd, hmenu);
3769 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3770 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
3771 DestroyWindow(hwnd);
3772 SetLastError(0xdeadbeef);
3773 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3774 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3776 hmenu = CreateMenu();
3778 SetLastError(0xdeadbeef);
3779 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
3780 0, 0, 100, 100, parent, hmenu, 0, NULL);
3781 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3782 expect_menu(hwnd, hmenu);
3783 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3784 expect_ex_style(hwnd, WS_EX_APPWINDOW);
3785 DestroyWindow(hwnd);
3786 SetLastError(0xdeadbeef);
3787 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3788 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3790 hmenu = CreateMenu();
3792 SetLastError(0xdeadbeef);
3793 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
3794 0, 0, 100, 100, parent, hmenu, 0, NULL);
3795 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3796 expect_menu(hwnd, hmenu);
3797 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
3798 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
3799 DestroyWindow(hwnd);
3800 SetLastError(0xdeadbeef);
3801 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3802 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3804 hmenu = CreateMenu();
3806 SetLastError(0xdeadbeef);
3807 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
3808 0, 0, 100, 100, parent, hmenu, 0, NULL);
3809 ok(hwnd != 0, "CreateWindowEx error %ld\n", GetLastError());
3810 expect_menu(hwnd, hmenu);
3811 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
3812 expect_ex_style(hwnd, 0);
3813 DestroyWindow(hwnd);
3814 SetLastError(0xdeadbeef);
3815 ok(!IsMenu(hmenu), "IsMenu should fail\n");
3816 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE, "IsMenu set error %ld\n", GetLastError());
3820 #undef expect_ex_style
3823 /* function that remembers whether the system the test is running on sets the
3824 * last error for user32 functions to make the tests stricter */
3825 static int check_error(DWORD actual, DWORD expected)
3827 static int sets_last_error = -1;
3828 if (sets_last_error == -1)
3829 sets_last_error = (actual != 0xdeadbeef);
3830 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
3833 static void test_SetWindowLong(void)
3836 WNDPROC old_window_procW;
3838 SetLastError(0xdeadbeef);
3839 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
3840 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%x\n", retval);
3841 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
3842 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %ld\n", GetLastError());
3844 SetLastError(0xdeadbeef);
3845 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
3846 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%x\n", retval);
3847 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
3848 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %ld\n", GetLastError());
3850 SetLastError(0xdeadbeef);
3851 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
3852 ok((WNDPROC)retval == main_window_procA,
3853 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%x\n", retval);
3854 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %ld\n", GetLastError());
3855 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
3856 ok((WNDPROC)retval == main_window_procA,
3857 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%x\n", retval);
3858 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
3860 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
3861 SetLastError(0xdeadbeef);
3862 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
3863 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
3865 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %ld\n", GetLastError());
3866 ok(retval != 0, "SetWindowLongPtr error %ld\n", GetLastError());
3867 ok((WNDPROC)retval == old_window_procW,
3868 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%x\n", retval);
3869 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
3871 /* set it back to ANSI */
3872 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
3878 pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
3879 pGetWindowInfo = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
3881 hwndMain = CreateWindowExA(0, "static", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, NULL);
3884 ok(!GetParent(hwndMain), "GetParent should return 0 for message only windows\n");
3887 hwndMessage = pGetAncestor(hwndMain, GA_PARENT);
3888 ok(hwndMessage != 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
3889 trace("hwndMessage %p\n", hwndMessage);
3891 DestroyWindow(hwndMain);
3894 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
3896 if (!RegisterWindowClasses()) assert(0);
3898 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
3901 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
3902 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3903 WS_MAXIMIZEBOX | WS_POPUP,
3906 test_nonclient_area(hwndMain);
3908 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
3909 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
3910 WS_MAXIMIZEBOX | WS_POPUP,
3914 assert( hwndMain2 );
3916 /* Add the tests below this line */
3921 test_capture_3(hwndMain, hwndMain2);
3923 test_CreateWindow();
3924 test_parent_owner();
3926 test_shell_window();
3930 test_SetWindowPos(hwndMain);
3931 test_SetMenu(hwndMain);
3932 test_SetFocus(hwndMain);
3933 test_SetActiveWindow(hwndMain);
3934 test_SetForegroundWindow(hwndMain);
3936 test_children_zorder(hwndMain);
3937 test_keyboard_input(hwndMain);
3938 test_mouse_input(hwndMain);
3939 test_validatergn(hwndMain);
3940 test_nccalcscroll( hwndMain);
3941 test_scrollvalidate( hwndMain);
3942 test_scrolldc( hwndMain);
3944 test_IsWindowUnicode();
3945 test_vis_rgn(hwndMain);
3947 test_AdjustWindowRect();
3948 test_window_styles();
3951 test_SetWindowLong();
3953 /* add the tests above this line */
3954 UnhookWindowsHookEx(hhook);