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
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn);
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
54 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
55 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
57 static BOOL test_lbuttondown_flag;
58 static HWND hwndMessage;
59 static HWND hwndMain, hwndMain2;
62 static const char* szAWRClass = "Winsize";
66 static BOOL is_win9x = FALSE;
68 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
70 static void dump_minmax_info( const MINMAXINFO *minmax )
72 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
73 minmax->ptReserved.x, minmax->ptReserved.y,
74 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
75 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
76 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
77 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
80 /* try to make sure pending X events have been processed before continuing */
81 static void flush_events( BOOL remove_messages )
85 int min_timeout = 100;
86 DWORD time = GetTickCount() + diff;
90 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
92 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
93 diff = time - GetTickCount();
98 /* check the values returned by the various parent/owner functions on a given window */
99 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
100 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
106 res = pGetAncestor( hwnd, GA_PARENT );
107 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
109 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
110 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
111 res = GetParent( hwnd );
112 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
113 res = GetWindow( hwnd, GW_OWNER );
114 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
117 res = pGetAncestor( hwnd, GA_ROOT );
118 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
119 res = pGetAncestor( hwnd, GA_ROOTOWNER );
120 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
124 static BOOL ignore_message( UINT message )
126 /* these are always ignored */
127 return (message >= 0xc000 ||
128 message == WM_GETICON ||
129 message == WM_GETOBJECT ||
130 message == WM_TIMECHANGE ||
131 message == WM_DEVICECHANGE);
134 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
137 trace("EnumChildProc on %p\n", hwndChild);
138 if (*(LPINT)lParam > 1) return FALSE;
142 /* will search for the given window */
143 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
145 trace("EnumChildProc1 on %p\n", hwndChild);
146 if ((HWND)lParam == hwndChild) return FALSE;
150 static HWND create_tool_window( LONG style, HWND parent )
152 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
153 0, 0, 100, 100, parent, 0, 0, NULL );
154 ok( ret != 0, "Creation failed\n" );
158 /* test parent and owner values for various combinations */
159 static void test_parent_owner(void)
162 HWND test, owner, ret;
163 HWND desktop = GetDesktopWindow();
164 HWND child = create_tool_window( WS_CHILD, hwndMain );
167 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
169 /* child without parent, should fail */
170 SetLastError(0xdeadbeef);
171 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
172 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
173 ok( !test, "WS_CHILD without parent created\n" );
174 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
175 broken(GetLastError() == 0xdeadbeef), /* win9x */
176 "CreateWindowExA error %u\n", GetLastError() );
179 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
180 style = GetWindowLongA( desktop, GWL_STYLE );
181 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
182 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
183 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
185 /* normal child window */
186 test = create_tool_window( WS_CHILD, hwndMain );
187 trace( "created child %p\n", test );
188 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
189 SetWindowLongA( test, GWL_STYLE, 0 );
190 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
191 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
192 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
193 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
194 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
195 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
196 DestroyWindow( test );
198 /* normal child window with WS_MAXIMIZE */
199 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
200 DestroyWindow( test );
202 /* normal child window with WS_THICKFRAME */
203 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
204 DestroyWindow( test );
206 /* popup window with WS_THICKFRAME */
207 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
208 DestroyWindow( test );
210 /* child of desktop */
211 test = create_tool_window( WS_CHILD, desktop );
212 trace( "created child of desktop %p\n", test );
213 check_parents( test, desktop, 0, desktop, 0, test, desktop );
214 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
215 check_parents( test, desktop, 0, 0, 0, test, test );
216 SetWindowLongA( test, GWL_STYLE, 0 );
217 check_parents( test, desktop, 0, 0, 0, test, test );
218 DestroyWindow( test );
220 /* child of desktop with WS_MAXIMIZE */
221 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
222 DestroyWindow( test );
224 /* child of desktop with WS_MINIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
226 DestroyWindow( test );
229 test = create_tool_window( WS_CHILD, child );
230 trace( "created child of child %p\n", test );
231 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
232 SetWindowLongA( test, GWL_STYLE, 0 );
233 check_parents( test, child, child, 0, 0, hwndMain, test );
234 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
235 check_parents( test, child, child, 0, 0, hwndMain, test );
236 DestroyWindow( test );
238 /* child of child with WS_MAXIMIZE */
239 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
240 DestroyWindow( test );
242 /* child of child with WS_MINIMIZE */
243 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
244 DestroyWindow( test );
246 /* not owned top-level window */
247 test = create_tool_window( 0, 0 );
248 trace( "created top-level %p\n", test );
249 check_parents( test, desktop, 0, 0, 0, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, 0, 0, 0, test, test );
252 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
253 check_parents( test, desktop, 0, desktop, 0, test, desktop );
254 DestroyWindow( test );
256 /* not owned top-level window with WS_MAXIMIZE */
257 test = create_tool_window( WS_MAXIMIZE, 0 );
258 DestroyWindow( test );
260 /* owned top-level window */
261 test = create_tool_window( 0, hwndMain );
262 trace( "created owned top-level %p\n", test );
263 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
264 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
265 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
266 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
267 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
268 DestroyWindow( test );
270 /* owned top-level window with WS_MAXIMIZE */
271 test = create_tool_window( WS_MAXIMIZE, hwndMain );
272 DestroyWindow( test );
274 /* not owned popup */
275 test = create_tool_window( WS_POPUP, 0 );
276 trace( "created popup %p\n", test );
277 check_parents( test, desktop, 0, 0, 0, test, test );
278 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
279 check_parents( test, desktop, 0, desktop, 0, test, desktop );
280 SetWindowLongA( test, GWL_STYLE, 0 );
281 check_parents( test, desktop, 0, 0, 0, test, test );
282 DestroyWindow( test );
284 /* not owned popup with WS_MAXIMIZE */
285 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
286 DestroyWindow( test );
289 test = create_tool_window( WS_POPUP, hwndMain );
290 trace( "created owned popup %p\n", test );
291 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
292 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
293 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
294 SetWindowLongA( test, GWL_STYLE, 0 );
295 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
296 DestroyWindow( test );
298 /* owned popup with WS_MAXIMIZE */
299 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
300 DestroyWindow( test );
302 /* top-level window owned by child (same as owned by top-level) */
303 test = create_tool_window( 0, child );
304 trace( "created top-level owned by child %p\n", test );
305 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
306 DestroyWindow( test );
308 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
309 test = create_tool_window( WS_MAXIMIZE, child );
310 DestroyWindow( test );
312 /* popup owned by desktop (same as not owned) */
313 test = create_tool_window( WS_POPUP, desktop );
314 trace( "created popup owned by desktop %p\n", test );
315 check_parents( test, desktop, 0, 0, 0, test, test );
316 DestroyWindow( test );
318 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
319 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
320 DestroyWindow( test );
322 /* popup owned by child (same as owned by top-level) */
323 test = create_tool_window( WS_POPUP, child );
324 trace( "created popup owned by child %p\n", test );
325 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
326 DestroyWindow( test );
328 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
329 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
330 DestroyWindow( test );
332 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
333 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
334 trace( "created WS_CHILD popup %p\n", test );
335 check_parents( test, desktop, 0, 0, 0, test, test );
336 DestroyWindow( test );
338 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
339 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
340 DestroyWindow( test );
342 /* owned popup with WS_CHILD (same as WS_POPUP only) */
343 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
344 trace( "created owned WS_CHILD popup %p\n", test );
345 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
346 DestroyWindow( test );
348 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
349 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
350 DestroyWindow( test );
352 /******************** parent changes *************************/
353 trace( "testing parent changes\n" );
356 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
359 /* this test succeeds on NT but crashes on win9x systems */
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
361 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
362 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
363 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
364 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
366 /* normal child window */
367 test = create_tool_window( WS_CHILD, hwndMain );
368 trace( "created child %p\n", test );
370 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
371 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
372 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
374 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
375 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
376 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
378 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
379 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
380 check_parents( test, desktop, 0, desktop, 0, test, desktop );
382 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
383 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
384 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
385 check_parents( test, desktop, child, desktop, child, test, desktop );
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, desktop, 0, test, desktop );
390 DestroyWindow( test );
392 /* not owned top-level window */
393 test = create_tool_window( 0, 0 );
394 trace( "created top-level %p\n", test );
396 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
397 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
398 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
400 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
401 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
402 check_parents( test, desktop, child, 0, child, test, test );
404 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
405 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
406 check_parents( test, desktop, 0, 0, 0, test, test );
407 DestroyWindow( test );
409 /* not owned popup */
410 test = create_tool_window( WS_POPUP, 0 );
411 trace( "created popup %p\n", test );
413 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
414 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
415 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
417 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
418 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
419 check_parents( test, desktop, child, child, child, test, hwndMain );
421 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
422 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
423 check_parents( test, desktop, 0, 0, 0, test, test );
424 DestroyWindow( test );
426 /* normal child window */
427 test = create_tool_window( WS_CHILD, hwndMain );
428 trace( "created child %p\n", test );
430 ret = SetParent( test, desktop );
431 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
432 check_parents( test, desktop, 0, desktop, 0, test, desktop );
434 ret = SetParent( test, child );
435 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
436 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
438 ret = SetParent( test, hwndMain2 );
439 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
440 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
441 DestroyWindow( test );
443 /* not owned top-level window */
444 test = create_tool_window( 0, 0 );
445 trace( "created top-level %p\n", test );
447 ret = SetParent( test, child );
448 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
449 check_parents( test, child, child, 0, 0, hwndMain, test );
453 ShowWindow( test, SW_SHOW );
454 ret = SetParent( test, test );
455 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
456 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
457 check_parents( test, child, child, 0, 0, hwndMain, test );
460 win_skip( "Test crashes on Win9x/WinMe\n" );
461 DestroyWindow( test );
464 test = create_tool_window( WS_POPUP, hwndMain2 );
465 trace( "created owned popup %p\n", test );
467 ret = SetParent( test, child );
468 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
469 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
471 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
472 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
473 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
474 DestroyWindow( test );
476 /**************** test owner destruction *******************/
478 /* owned child popup */
479 owner = create_tool_window( 0, 0 );
480 test = create_tool_window( WS_POPUP, owner );
481 trace( "created owner %p and popup %p\n", owner, test );
482 ret = SetParent( test, child );
483 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
484 check_parents( test, child, child, owner, owner, hwndMain, owner );
485 /* window is now child of 'child' but owned by 'owner' */
486 DestroyWindow( owner );
487 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
491 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
492 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
495 /* owned top-level popup */
496 owner = create_tool_window( 0, 0 );
497 test = create_tool_window( WS_POPUP, owner );
498 trace( "created owner %p and popup %p\n", owner, test );
499 check_parents( test, desktop, owner, owner, owner, test, owner );
500 DestroyWindow( owner );
501 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
503 /* top-level popup owned by child */
504 owner = create_tool_window( WS_CHILD, hwndMain2 );
505 test = create_tool_window( WS_POPUP, 0 );
506 trace( "created owner %p and popup %p\n", owner, test );
507 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
508 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
509 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
510 DestroyWindow( owner );
511 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
512 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
513 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
514 * while Win95, Win2k, WinXP do.
516 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
520 DestroyWindow(child);
523 owner = create_tool_window( WS_OVERLAPPED, 0 );
524 test = create_tool_window( WS_POPUP, desktop );
526 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
528 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
529 "EnumChildWindows should have returned FALSE\n" );
530 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
532 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
533 ret = SetParent( test, owner );
534 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
537 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
538 "EnumChildWindows should have returned TRUE\n" );
539 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
541 child = create_tool_window( WS_CHILD, owner );
543 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
544 "EnumChildWindows should have returned FALSE\n" );
545 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
546 DestroyWindow( child );
548 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
549 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
551 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
552 "EnumChildWindows should have returned TRUE\n" );
553 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
555 ret = SetParent( child, owner );
556 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
557 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
559 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
560 "EnumChildWindows should have returned FALSE\n" );
561 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
563 ret = SetParent( child, NULL );
564 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
565 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
567 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
568 "EnumChildWindows should have returned TRUE\n" );
569 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
571 /* even GW_OWNER == owner it's still a desktop's child */
572 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
573 "EnumChildWindows should have found %p and returned FALSE\n", child );
575 DestroyWindow( child );
576 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
578 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
579 "EnumChildWindows should have found %p and returned FALSE\n", child );
581 DestroyWindow( child );
582 DestroyWindow( test );
583 DestroyWindow( owner );
586 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
589 if (*(LPINT)lParam > 2) return FALSE;
592 static DWORD CALLBACK enum_thread( void *arg )
599 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
602 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
603 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
604 ok( count == 0, "count should be 0 got %d\n", count );
606 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
607 0, 0, 100, 100, 0, 0, 0, NULL );
609 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
610 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
611 if (count != 2) /* Vista gives us two windows for the price of one */
613 ok( count == 1, "count should be 1 got %d\n", count );
614 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
615 0, 0, 100, 100, 0, 0, 0, NULL );
619 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
620 0, 0, 100, 100, 0, 0, 0, NULL );
622 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
623 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
624 ok( count == 3, "count should be 3 got %d\n", count );
626 if (hwnd[2]) DestroyWindow(hwnd[2]);
627 DestroyWindow(hwnd[1]);
628 DestroyWindow(hwnd[0]);
632 /* test EnumThreadWindows in a separate thread */
633 static void test_enum_thread_windows(void)
636 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
637 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
638 CloseHandle( handle );
641 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
645 case WM_GETMINMAXINFO:
647 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
649 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
650 dump_minmax_info( minmax );
651 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
654 case WM_WINDOWPOSCHANGING:
656 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
657 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
658 winpos->hwnd, winpos->hwndInsertAfter,
659 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
660 if (!(winpos->flags & SWP_NOMOVE))
662 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
663 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
665 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
666 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
668 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
669 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
673 case WM_WINDOWPOSCHANGED:
676 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
677 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
678 winpos->hwnd, winpos->hwndInsertAfter,
679 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
680 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
681 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
683 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
684 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
686 GetWindowRect(hwnd, &rc1);
687 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
688 /* note: winpos coordinates are relative to parent */
689 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
692 /* Uncomment this once the test succeeds in all cases */
693 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
694 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
696 GetClientRect(hwnd, &rc2);
697 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
698 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
699 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
700 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
706 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
707 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
709 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
710 if (got_getminmaxinfo)
711 trace("%p got WM_GETMINMAXINFO\n", hwnd);
713 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
714 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
716 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
720 if (test_lbuttondown_flag)
722 ShowWindow((HWND)wparam, SW_SHOW);
723 flush_events( FALSE );
728 return DefWindowProcA(hwnd, msg, wparam, lparam);
731 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
735 case WM_GETMINMAXINFO:
737 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
739 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
740 dump_minmax_info( minmax );
741 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
746 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
747 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
749 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
750 if (got_getminmaxinfo)
751 trace("%p got WM_GETMINMAXINFO\n", hwnd);
753 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
754 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
756 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
761 return DefWindowProcA(hwnd, msg, wparam, lparam);
764 static BOOL RegisterWindowClasses(void)
768 cls.style = CS_DBLCLKS;
769 cls.lpfnWndProc = main_window_procA;
772 cls.hInstance = GetModuleHandleA(0);
774 cls.hCursor = LoadCursorA(0, IDC_ARROW);
775 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
776 cls.lpszMenuName = NULL;
777 cls.lpszClassName = "MainWindowClass";
779 if(!RegisterClassA(&cls)) return FALSE;
782 cls.lpfnWndProc = tool_window_procA;
785 cls.hInstance = GetModuleHandleA(0);
787 cls.hCursor = LoadCursorA(0, IDC_ARROW);
788 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
789 cls.lpszMenuName = NULL;
790 cls.lpszClassName = "ToolWindowClass";
792 if(!RegisterClassA(&cls)) return FALSE;
797 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
799 RECT rcWindow, rcClient;
802 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
804 GetWindowRect(hwnd, &rcWindow);
805 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
807 GetClientRect(hwnd, &rcClient);
808 /* translate to screen coordinates */
809 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
810 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
812 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
813 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
814 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
815 /* Windows reports some undocumented exstyles in WINDOWINFO, but
816 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
818 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
819 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
820 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
821 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
822 if (GetForegroundWindow())
823 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
824 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
826 /* win2k and XP return broken border info in GetWindowInfo most of
827 * the time, so there is no point in testing it.
831 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
832 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
833 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
834 ok(info->cyWindowBorders == border,
835 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
837 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
839 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
840 info->wCreatorVersion == 0x0500 /* Vista */,
841 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
844 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
846 AdjustWindowRectEx(rc, style, menu, exstyle);
847 /* AdjustWindowRectEx does not include scroll bars */
848 if (style & WS_VSCROLL)
850 if(exstyle & WS_EX_LEFTSCROLLBAR)
851 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
853 rc->right += GetSystemMetrics(SM_CXVSCROLL);
855 if (style & WS_HSCROLL)
856 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
859 static void test_nonclient_area(HWND hwnd)
861 DWORD style, exstyle;
862 RECT rc_window, rc_client, rc;
866 style = GetWindowLongA(hwnd, GWL_STYLE);
867 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
868 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
870 GetWindowRect(hwnd, &rc_window);
871 GetClientRect(hwnd, &rc_client);
873 /* avoid some cases when things go wrong */
874 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
875 rc_window.right > 32768 || rc_window.bottom > 32768) return;
877 CopyRect(&rc, &rc_client);
878 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
879 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
881 ok(EqualRect(&rc, &rc_window),
882 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
883 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
884 rc.left, rc.top, rc.right, rc.bottom);
887 CopyRect(&rc, &rc_window);
888 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
889 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
890 ok(EqualRect(&rc, &rc_client),
891 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
892 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
893 rc.left, rc.top, rc.right, rc.bottom);
895 /* NULL rectangle shouldn't crash */
896 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
897 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
899 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
903 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
904 SetRect(&rc_client, 0, 0, 250, 150);
905 CopyRect(&rc_window, &rc_client);
906 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
907 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
909 CopyRect(&rc, &rc_window);
910 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
911 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
912 ok(EqualRect(&rc, &rc_client),
913 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
914 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
915 rc.left, rc.top, rc.right, rc.bottom);
918 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
920 static const char *CBT_code_name[10] = {
931 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
932 HWND hwnd = (HWND)wParam;
938 static const RECT rc_null;
941 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
942 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
943 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
944 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
949 info.cbSize = sizeof(WINDOWINFO);
950 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
951 verify_window_info(code_name, hwnd, &info);
954 /* WS_VISIBLE should be turned off yet */
955 style = createwnd->lpcs->style & ~WS_VISIBLE;
956 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
957 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
958 GetWindowLongA(hwnd, GWL_STYLE), style);
962 /* Uncomment this once the test succeeds in all cases */
963 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
965 ok(GetParent(hwnd) == hwndMessage,
966 "wrong result from GetParent %p: message window %p\n",
967 GetParent(hwnd), hwndMessage);
970 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
972 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
976 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
977 * Win9x still has them set to 0.
979 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
980 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
982 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
983 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
987 /* Uncomment this once the test succeeds in all cases */
990 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
991 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
992 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
994 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
995 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
996 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
998 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
999 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1002 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1003 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1004 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1005 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1013 if (pGetWindowInfo && IsWindow(hwnd))
1017 /* Win98 actually does check the info.cbSize and doesn't allow
1018 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1019 * WinXP do not check it at all.
1021 info.cbSize = sizeof(WINDOWINFO);
1022 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1023 verify_window_info(code_name, hwnd, &info);
1026 /* on HCBT_DESTROYWND window state is undefined */
1027 case HCBT_DESTROYWND:
1028 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
1034 return CallNextHookEx(hhook, nCode, wParam, lParam);
1037 static void test_shell_window(void)
1041 HMODULE hinst, hUser32;
1042 BOOL (WINAPI*SetShellWindow)(HWND);
1043 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
1044 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1045 HWND shellWindow, nextWnd;
1049 win_skip("Skipping shell window test on Win9x\n");
1053 shellWindow = GetShellWindow();
1054 hinst = GetModuleHandle(0);
1055 hUser32 = GetModuleHandleA("user32");
1057 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1058 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
1060 trace("previous shell window: %p\n", shellWindow);
1066 GetWindowThreadProcessId(shellWindow, &pid);
1067 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1070 skip( "cannot get access to shell process\n" );
1074 SetLastError(0xdeadbeef);
1075 ret = DestroyWindow(shellWindow);
1076 error = GetLastError();
1078 ok(!ret, "DestroyWindow(shellWindow)\n");
1079 /* passes on Win XP, but not on Win98 */
1080 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1081 "got %u after DestroyWindow(shellWindow)\n", error);
1083 /* close old shell instance */
1084 ret = TerminateProcess(hProcess, 0);
1085 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1086 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1087 CloseHandle(hProcess);
1090 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1091 trace("created window 1: %p\n", hwnd1);
1093 ret = SetShellWindow(hwnd1);
1094 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1095 shellWindow = GetShellWindow();
1096 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1098 ret = SetShellWindow(hwnd1);
1099 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1101 ret = SetShellWindow(0);
1102 error = GetLastError();
1103 /* passes on Win XP, but not on Win98
1104 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1105 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1107 ret = SetShellWindow(hwnd1);
1108 /* passes on Win XP, but not on Win98
1109 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1111 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1112 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1113 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1115 ret = DestroyWindow(hwnd1);
1116 ok(ret, "DestroyWindow(hwnd1)\n");
1118 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1119 trace("created window 2: %p\n", hwnd2);
1120 ret = SetShellWindow(hwnd2);
1121 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1123 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1124 trace("created window 3: %p\n", hwnd3);
1126 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1127 trace("created window 4: %p\n", hwnd4);
1129 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1130 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1132 ret = SetShellWindow(hwnd4);
1133 ok(ret, "SetShellWindow(hwnd4)\n");
1134 shellWindow = GetShellWindow();
1135 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1137 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1138 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1140 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1141 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1143 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1144 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1146 ret = SetShellWindow(hwnd3);
1147 ok(!ret, "SetShellWindow(hwnd3)\n");
1148 shellWindow = GetShellWindow();
1149 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1151 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1152 trace("created window 5: %p\n", hwnd5);
1153 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1154 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1158 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1159 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1162 /* destroy test windows */
1163 DestroyWindow(hwnd2);
1164 DestroyWindow(hwnd3);
1165 DestroyWindow(hwnd4);
1166 DestroyWindow(hwnd5);
1169 /************** MDI test ****************/
1171 static char mdi_lParam_test_message[] = "just a test string";
1173 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1175 MDICREATESTRUCTA mdi_cs;
1178 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1179 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1180 BOOL isWin9x = FALSE;
1182 mdi_cs.szClass = "MDI_child_Class_1";
1183 mdi_cs.szTitle = "MDI child";
1184 mdi_cs.hOwner = GetModuleHandle(0);
1185 mdi_cs.x = CW_USEDEFAULT;
1186 mdi_cs.y = CW_USEDEFAULT;
1187 mdi_cs.cx = CW_USEDEFAULT;
1188 mdi_cs.cy = CW_USEDEFAULT;
1190 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1191 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1192 ok(mdi_child != 0, "MDI child creation failed\n");
1193 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1194 ok(id == first_id, "wrong child id %ld\n", id);
1195 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1196 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1198 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1199 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1200 ok(mdi_child != 0, "MDI child creation failed\n");
1201 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1202 ok(id == first_id, "wrong child id %ld\n", id);
1203 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1204 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1206 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1207 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
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 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1216 ok(id == first_id, "wrong child id %ld\n", id);
1217 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1218 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1221 /* test MDICREATESTRUCT A<->W mapping */
1222 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1224 mdi_cs.szClass = (LPCSTR)classW;
1225 mdi_cs.szTitle = (LPCSTR)titleW;
1226 SetLastError(0xdeadbeef);
1227 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1230 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1233 ok(mdi_child != 0, "MDI child creation failed\n");
1237 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1238 ok(id == first_id, "wrong child id %ld\n", id);
1239 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1240 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1243 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1245 CW_USEDEFAULT, CW_USEDEFAULT,
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 mdi_client, GetModuleHandle(0),
1248 (LPARAM)mdi_lParam_test_message);
1249 ok(mdi_child != 0, "MDI child creation failed\n");
1250 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1251 ok(id == first_id, "wrong child id %ld\n", id);
1252 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1253 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1255 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1256 0x7fffffff, /* without WS_POPUP */
1257 CW_USEDEFAULT, CW_USEDEFAULT,
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 mdi_client, GetModuleHandle(0),
1260 (LPARAM)mdi_lParam_test_message);
1261 ok(mdi_child != 0, "MDI child creation failed\n");
1262 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1263 ok(id == first_id, "wrong child id %ld\n", id);
1264 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1265 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1267 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1268 0xffffffff, /* with WS_POPUP */
1269 CW_USEDEFAULT, CW_USEDEFAULT,
1270 CW_USEDEFAULT, CW_USEDEFAULT,
1271 mdi_client, GetModuleHandle(0),
1272 (LPARAM)mdi_lParam_test_message);
1273 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1275 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1279 ok(mdi_child != 0, "MDI child creation failed\n");
1280 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1281 ok(id == first_id, "wrong child id %ld\n", id);
1282 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1283 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1286 /* test MDICREATESTRUCT A<->W mapping */
1287 SetLastError(0xdeadbeef);
1288 mdi_child = CreateMDIWindowW(classW, titleW,
1290 CW_USEDEFAULT, CW_USEDEFAULT,
1291 CW_USEDEFAULT, CW_USEDEFAULT,
1292 mdi_client, GetModuleHandle(0),
1293 (LPARAM)mdi_lParam_test_message);
1296 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1299 ok(mdi_child != 0, "MDI child creation failed\n");
1303 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1304 ok(id == first_id, "wrong child id %ld\n", id);
1305 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1306 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1309 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1311 CW_USEDEFAULT, CW_USEDEFAULT,
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 mdi_client, 0, GetModuleHandle(0),
1314 mdi_lParam_test_message);
1315 ok(mdi_child != 0, "MDI child creation failed\n");
1316 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1317 ok(id == first_id, "wrong child id %ld\n", id);
1318 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1319 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1321 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1322 0x7fffffff, /* without WS_POPUP */
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 mdi_client, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message);
1327 ok(mdi_child != 0, "MDI child creation failed\n");
1328 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1329 ok(id == first_id, "wrong child id %ld\n", id);
1330 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1331 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1333 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1334 0xffffffff, /* with WS_POPUP */
1335 CW_USEDEFAULT, CW_USEDEFAULT,
1336 CW_USEDEFAULT, CW_USEDEFAULT,
1337 mdi_client, 0, GetModuleHandle(0),
1338 mdi_lParam_test_message);
1339 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1341 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1345 ok(mdi_child != 0, "MDI child creation failed\n");
1346 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1347 ok(id == first_id, "wrong child id %ld\n", id);
1348 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1349 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1352 /* test MDICREATESTRUCT A<->W mapping */
1353 SetLastError(0xdeadbeef);
1354 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1356 CW_USEDEFAULT, CW_USEDEFAULT,
1357 CW_USEDEFAULT, CW_USEDEFAULT,
1358 mdi_client, 0, GetModuleHandle(0),
1359 mdi_lParam_test_message);
1362 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1365 ok(mdi_child != 0, "MDI child creation failed\n");
1369 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1370 ok(id == first_id, "wrong child id %ld\n", id);
1371 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1372 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1375 /* This test fails on Win9x */
1378 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1380 CW_USEDEFAULT, CW_USEDEFAULT,
1381 CW_USEDEFAULT, CW_USEDEFAULT,
1382 parent, 0, GetModuleHandle(0),
1383 mdi_lParam_test_message);
1384 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1387 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1388 WS_CHILD, /* without WS_POPUP */
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 CW_USEDEFAULT, CW_USEDEFAULT,
1391 mdi_client, 0, GetModuleHandle(0),
1392 mdi_lParam_test_message);
1393 ok(mdi_child != 0, "MDI child creation failed\n");
1394 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1395 ok(id == 0, "wrong child id %ld\n", id);
1396 DestroyWindow(mdi_child);
1398 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1399 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1400 CW_USEDEFAULT, CW_USEDEFAULT,
1401 CW_USEDEFAULT, CW_USEDEFAULT,
1402 mdi_client, 0, GetModuleHandle(0),
1403 mdi_lParam_test_message);
1404 ok(mdi_child != 0, "MDI child creation failed\n");
1405 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1406 ok(id == 0, "wrong child id %ld\n", id);
1407 DestroyWindow(mdi_child);
1409 /* maximized child */
1410 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1411 WS_CHILD | WS_MAXIMIZE,
1412 CW_USEDEFAULT, CW_USEDEFAULT,
1413 CW_USEDEFAULT, CW_USEDEFAULT,
1414 mdi_client, 0, GetModuleHandle(0),
1415 mdi_lParam_test_message);
1416 ok(mdi_child != 0, "MDI child creation failed\n");
1417 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1418 ok(id == 0, "wrong child id %ld\n", id);
1419 DestroyWindow(mdi_child);
1421 trace("Creating maximized child with a caption\n");
1422 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1423 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1424 CW_USEDEFAULT, CW_USEDEFAULT,
1425 CW_USEDEFAULT, CW_USEDEFAULT,
1426 mdi_client, 0, GetModuleHandle(0),
1427 mdi_lParam_test_message);
1428 ok(mdi_child != 0, "MDI child creation failed\n");
1429 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1430 ok(id == 0, "wrong child id %ld\n", id);
1431 DestroyWindow(mdi_child);
1433 trace("Creating maximized child with a caption and a thick frame\n");
1434 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1435 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1436 CW_USEDEFAULT, CW_USEDEFAULT,
1437 CW_USEDEFAULT, CW_USEDEFAULT,
1438 mdi_client, 0, GetModuleHandle(0),
1439 mdi_lParam_test_message);
1440 ok(mdi_child != 0, "MDI child creation failed\n");
1441 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1442 ok(id == 0, "wrong child id %ld\n", id);
1443 DestroyWindow(mdi_child);
1446 /**********************************************************************
1447 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1449 * Note: The rule here is that client rect of the maximized MDI child
1450 * is equal to the client rect of the MDI client window.
1452 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1456 GetClientRect( client, &rect );
1457 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1458 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1460 rect.right -= rect.left;
1461 rect.bottom -= rect.top;
1462 lpMinMax->ptMaxSize.x = rect.right;
1463 lpMinMax->ptMaxSize.y = rect.bottom;
1465 lpMinMax->ptMaxPosition.x = rect.left;
1466 lpMinMax->ptMaxPosition.y = rect.top;
1468 trace("max rect (%d,%d - %d, %d)\n",
1469 rect.left, rect.top, rect.right, rect.bottom);
1472 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1479 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1480 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1482 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1483 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1485 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1486 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1487 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1488 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1489 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1491 /* MDICREATESTRUCT should have original values */
1492 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1493 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1494 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1495 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1496 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1497 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1499 /* CREATESTRUCT should have fixed values */
1500 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1501 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1503 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1504 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1505 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1507 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1509 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1511 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1512 ok(cs->style == style,
1513 "cs->style does not match (%08x)\n", cs->style);
1517 LONG style = mdi_cs->style;
1519 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1520 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1521 ok(cs->style == style,
1522 "cs->style does not match (%08x)\n", cs->style);
1527 case WM_GETMINMAXINFO:
1529 HWND client = GetParent(hwnd);
1531 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1532 MINMAXINFO my_minmax;
1533 LONG style, exstyle;
1535 style = GetWindowLongA(hwnd, GWL_STYLE);
1536 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1538 GetWindowRect(client, &rc);
1539 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1540 GetClientRect(client, &rc);
1541 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1542 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1543 GetSystemMetrics(SM_CYSCREEN));
1545 GetClientRect(client, &rc);
1546 if ((style & WS_CAPTION) == WS_CAPTION)
1547 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1548 AdjustWindowRectEx(&rc, style, 0, exstyle);
1549 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1550 dump_minmax_info( minmax );
1552 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1553 minmax->ptMaxSize.x, rc.right - rc.left);
1554 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1555 minmax->ptMaxSize.y, rc.bottom - rc.top);
1557 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1559 trace("DefMDIChildProc returned:\n");
1560 dump_minmax_info( minmax );
1562 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1563 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1564 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1565 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1566 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1571 case WM_MDIACTIVATE:
1573 HWND active, client = GetParent(hwnd);
1574 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1575 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1576 if (hwnd == (HWND)lparam) /* if we are being activated */
1577 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1579 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1583 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1586 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1593 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1595 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1596 cs->x, cs->y, cs->cx, cs->cy);
1598 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1599 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1601 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1602 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1604 /* CREATESTRUCT should have fixed values */
1605 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1607 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1608 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1610 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1611 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1612 while Win95, Win2k, WinXP do. */
1613 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1614 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1618 case WM_GETMINMAXINFO:
1620 HWND parent = GetParent(hwnd);
1622 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1623 LONG style, exstyle;
1625 style = GetWindowLongA(hwnd, GWL_STYLE);
1626 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1628 GetClientRect(parent, &rc);
1629 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1631 GetClientRect(parent, &rc);
1632 if ((style & WS_CAPTION) == WS_CAPTION)
1633 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1634 AdjustWindowRectEx(&rc, style, 0, exstyle);
1635 dump_minmax_info( minmax );
1637 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1638 minmax->ptMaxSize.x, rc.right - rc.left);
1639 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1640 minmax->ptMaxSize.y, rc.bottom - rc.top);
1644 case WM_WINDOWPOSCHANGED:
1646 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1649 GetWindowRect(hwnd, &rc1);
1650 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1651 /* note: winpos coordinates are relative to parent */
1652 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1653 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1654 rc1.left, rc1.top, rc1.right, rc1.bottom,
1655 rc2.left, rc2.top, rc2.right, rc2.bottom);
1656 GetWindowRect(hwnd, &rc1);
1657 GetClientRect(hwnd, &rc2);
1658 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1659 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1660 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1661 rc1.left, rc1.top, rc1.right, rc1.bottom,
1662 rc2.left, rc2.top, rc2.right, rc2.bottom);
1665 case WM_WINDOWPOSCHANGING:
1667 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1668 WINDOWPOS my_winpos = *winpos;
1670 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1671 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1672 winpos->hwnd, winpos->hwndInsertAfter,
1673 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1675 DefWindowProcA(hwnd, msg, wparam, lparam);
1677 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1678 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1679 winpos->hwnd, winpos->hwndInsertAfter,
1680 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1685 return DefWindowProcA(hwnd, msg, wparam, lparam);
1688 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1690 static HWND mdi_client;
1696 CLIENTCREATESTRUCT client_cs;
1699 GetClientRect(hwnd, &rc);
1701 client_cs.hWindowMenu = 0;
1702 client_cs.idFirstChild = 1;
1704 /* MDIClient without MDIS_ALLCHILDSTYLES */
1705 mdi_client = CreateWindowExA(0, "mdiclient",
1707 WS_CHILD /*| WS_VISIBLE*/,
1708 /* tests depend on a not zero MDIClient size */
1709 0, 0, rc.right, rc.bottom,
1710 hwnd, 0, GetModuleHandle(0),
1713 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1714 DestroyWindow(mdi_client);
1716 /* MDIClient with MDIS_ALLCHILDSTYLES */
1717 mdi_client = CreateWindowExA(0, "mdiclient",
1719 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1720 /* tests depend on a not zero MDIClient size */
1721 0, 0, rc.right, rc.bottom,
1722 hwnd, 0, GetModuleHandle(0),
1725 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1726 DestroyWindow(mdi_client);
1730 case WM_WINDOWPOSCHANGED:
1732 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1735 GetWindowRect(hwnd, &rc1);
1736 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1737 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1738 /* note: winpos coordinates are relative to parent */
1739 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1740 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1741 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1743 GetWindowRect(hwnd, &rc1);
1744 GetClientRect(hwnd, &rc2);
1745 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1746 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1747 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1750 case WM_WINDOWPOSCHANGING:
1752 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1753 WINDOWPOS my_winpos = *winpos;
1755 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1756 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1757 winpos->hwnd, winpos->hwndInsertAfter,
1758 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1760 DefWindowProcA(hwnd, msg, wparam, lparam);
1762 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1763 winpos->hwnd, winpos->hwndInsertAfter,
1764 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1766 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1767 "DefWindowProc should not change WINDOWPOS values\n");
1776 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1779 static BOOL mdi_RegisterWindowClasses(void)
1784 cls.lpfnWndProc = mdi_main_wnd_procA;
1787 cls.hInstance = GetModuleHandleA(0);
1789 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1790 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1791 cls.lpszMenuName = NULL;
1792 cls.lpszClassName = "MDI_parent_Class";
1793 if(!RegisterClassA(&cls)) return FALSE;
1795 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1796 cls.lpszClassName = "MDI_child_Class_1";
1797 if(!RegisterClassA(&cls)) return FALSE;
1799 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1800 cls.lpszClassName = "MDI_child_Class_2";
1801 if(!RegisterClassA(&cls)) return FALSE;
1806 static void test_mdi(void)
1811 if (!mdi_RegisterWindowClasses()) assert(0);
1813 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1814 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1815 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1816 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1817 GetDesktopWindow(), 0,
1818 GetModuleHandle(0), NULL);
1819 assert(mdi_hwndMain);
1821 while(GetMessage(&msg, 0, 0, 0))
1823 TranslateMessage(&msg);
1824 DispatchMessage(&msg);
1827 DestroyWindow(mdi_hwndMain);
1830 static void test_icons(void)
1834 HICON icon = LoadIconA(0, IDI_APPLICATION);
1835 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1836 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1837 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1840 cls.cbSize = sizeof(cls);
1842 cls.lpfnWndProc = DefWindowProcA;
1846 cls.hIcon = LoadIconA(0, IDI_HAND);
1847 cls.hIconSm = small_icon;
1848 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1849 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1850 cls.lpszMenuName = NULL;
1851 cls.lpszClassName = "IconWindowClass";
1853 RegisterClassExA(&cls);
1855 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1856 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1859 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1860 ok( res == 0, "wrong big icon %p/0\n", res );
1861 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1862 ok( res == 0, "wrong previous big icon %p/0\n", res );
1863 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1864 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1865 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1866 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1867 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1868 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1870 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1871 ok( res == 0, "wrong small icon %p/0\n", res );
1872 /* this test is XP specific */
1873 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1874 ok( res != 0, "wrong small icon %p\n", res );*/
1875 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1876 ok( res == 0, "wrong previous small icon %p/0\n", res );
1877 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1878 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1879 /* this test is XP specific */
1880 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1881 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1882 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1883 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1884 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1885 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1886 /* this test is XP specific */
1887 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1888 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1890 /* make sure the big icon hasn't changed */
1891 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1892 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1894 DestroyWindow( hwnd );
1897 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1899 if (msg == WM_NCCALCSIZE)
1901 RECT *rect = (RECT *)lparam;
1902 /* first time around increase the rectangle, next time decrease it */
1903 if (rect->left == 100) InflateRect( rect, 10, 10 );
1904 else InflateRect( rect, -10, -10 );
1907 return DefWindowProc( hwnd, msg, wparam, lparam );
1910 static void test_SetWindowPos(HWND hwnd)
1912 RECT orig_win_rc, rect;
1915 SetRect(&rect, 111, 222, 333, 444);
1916 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1917 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1918 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1920 SetRect(&rect, 111, 222, 333, 444);
1921 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1922 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1923 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1925 GetWindowRect(hwnd, &orig_win_rc);
1927 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1928 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1929 GetWindowRect( hwnd, &rect );
1930 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1931 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1932 GetClientRect( hwnd, &rect );
1933 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1934 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1935 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1937 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1938 GetWindowRect( hwnd, &rect );
1939 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1940 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1941 GetClientRect( hwnd, &rect );
1942 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1943 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1944 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1946 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1947 orig_win_rc.right, orig_win_rc.bottom, 0);
1948 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1950 /* Win9x truncates coordinates to 16-bit irrespectively */
1953 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1954 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1956 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1957 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1960 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1961 orig_win_rc.right, orig_win_rc.bottom, 0);
1963 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1964 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1965 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1966 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1967 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1968 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1969 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1972 static void test_SetMenu(HWND parent)
1979 hMenu = CreateMenu();
1982 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1985 /* fails on (at least) Wine, NT4, XP SP2 */
1986 test_nonclient_area(parent);
1988 ret = GetMenu(parent);
1989 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1990 /* test whether we can destroy a menu assigned to a window */
1991 retok = DestroyMenu(hMenu);
1992 ok( retok, "DestroyMenu error %d\n", GetLastError());
1993 retok = IsMenu(hMenu);
1994 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1995 ret = GetMenu(parent);
1996 /* This test fails on Win9x */
1998 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1999 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2000 test_nonclient_area(parent);
2002 hMenu = CreateMenu();
2006 ret = GetMenu(parent);
2007 ok(ret == 0, "unexpected menu id %p\n", ret);
2009 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2010 test_nonclient_area(parent);
2011 ret = GetMenu(parent);
2012 ok(ret == 0, "unexpected menu id %p\n", ret);
2014 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2017 /* fails on (at least) Wine, NT4, XP SP2 */
2018 test_nonclient_area(parent);
2020 ret = GetMenu(parent);
2021 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2023 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2024 test_nonclient_area(parent);
2025 ret = GetMenu(parent);
2026 ok(ret == 0, "unexpected menu id %p\n", ret);
2029 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2032 ret = GetMenu(child);
2033 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2035 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2036 test_nonclient_area(child);
2037 ret = GetMenu(child);
2038 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2040 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2041 test_nonclient_area(child);
2042 ret = GetMenu(child);
2043 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2045 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2046 test_nonclient_area(child);
2047 ret = GetMenu(child);
2048 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2050 style = GetWindowLong(child, GWL_STYLE);
2051 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2052 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2053 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2054 SetWindowLong(child, GWL_STYLE, style);
2056 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2057 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2058 SetWindowLong(child, GWL_STYLE, style);
2060 DestroyWindow(child);
2064 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2066 HWND child[5], hwnd;
2071 hwnd = GetWindow(parent, GW_CHILD);
2072 ok(!hwnd, "have to start without children to perform the test\n");
2074 for (i = 0; i < total; i++)
2076 if (style[i] & DS_CONTROL)
2078 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2079 0,0,0,0, parent, (HMENU)i, 0, NULL);
2080 if (style[i] & WS_VISIBLE)
2081 ShowWindow(child[i], SW_SHOW);
2083 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2086 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2087 parent, (HMENU)i, 0, NULL);
2088 trace("child[%ld] = %p\n", i, child[i]);
2089 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2092 hwnd = GetWindow(parent, GW_CHILD);
2093 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2094 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2095 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2097 for (i = 0; i < total; i++)
2099 trace("hwnd[%ld] = %p\n", i, hwnd);
2100 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2102 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2105 for (i = 0; i < total; i++)
2106 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2109 static void test_children_zorder(HWND parent)
2111 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2113 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2115 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2116 WS_CHILD | WS_VISIBLE, WS_CHILD,
2117 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2118 const int complex_order_1[1] = { 0 };
2119 const int complex_order_2[2] = { 1, 0 };
2120 const int complex_order_3[3] = { 1, 0, 2 };
2121 const int complex_order_4[4] = { 1, 0, 2, 3 };
2122 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2123 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2124 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2125 WS_CHILD | WS_VISIBLE };
2126 const int complex_order_6[3] = { 0, 1, 2 };
2128 /* simple WS_CHILD */
2129 test_window_tree(parent, simple_style, simple_order, 5);
2131 /* complex children styles */
2132 test_window_tree(parent, complex_style, complex_order_1, 1);
2133 test_window_tree(parent, complex_style, complex_order_2, 2);
2134 test_window_tree(parent, complex_style, complex_order_3, 3);
2135 test_window_tree(parent, complex_style, complex_order_4, 4);
2136 test_window_tree(parent, complex_style, complex_order_5, 5);
2138 /* another set of complex children styles */
2139 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2142 #define check_z_order(hwnd, next, prev, owner, topmost) \
2143 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2146 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2147 BOOL topmost, const char *file, int line)
2152 test = GetWindow(hwnd, GW_HWNDNEXT);
2153 /* skip foreign windows */
2154 while (test && test != next &&
2155 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2156 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2157 GetWindow(test, GW_OWNER) == next))
2159 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2160 test = GetWindow(test, GW_HWNDNEXT);
2162 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2164 test = GetWindow(hwnd, GW_HWNDPREV);
2165 /* skip foreign windows */
2166 while (test && test != prev &&
2167 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2168 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2169 GetWindow(test, GW_OWNER) == hwnd))
2171 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2172 test = GetWindow(test, GW_HWNDPREV);
2174 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2176 test = GetWindow(hwnd, GW_OWNER);
2177 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2179 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2180 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2181 hwnd, topmost ? "" : "NOT ");
2184 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2186 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2188 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2190 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2192 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2193 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2195 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2196 WS_OVERLAPPED | WS_CAPTION,
2198 0, 0, GetModuleHandle(0), NULL);
2199 trace("hwnd_F %p\n", hwnd_F);
2200 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2202 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2203 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2204 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2205 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2207 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2210 hwnd_F, 0, GetModuleHandle(0), NULL);
2211 trace("hwnd_C %p\n", hwnd_C);
2212 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2213 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2214 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2215 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2217 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2220 hwnd_F, 0, GetModuleHandle(0), NULL);
2221 trace("hwnd_B %p\n", hwnd_B);
2222 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2223 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2224 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2225 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2226 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2228 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2231 0, 0, GetModuleHandle(0), NULL);
2232 trace("hwnd_A %p\n", hwnd_A);
2233 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2234 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2235 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2236 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2237 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2238 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2240 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A, hwnd_B, hwnd_C, hwnd_D, hwnd_E, hwnd_F);
2242 /* move hwnd_F and its popups up */
2243 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2244 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2245 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2246 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2247 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2248 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2249 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2251 /* move hwnd_F and its popups down */
2252 #if 0 /* enable once Wine is fixed to pass this test */
2253 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2254 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2255 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2256 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2257 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2258 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2259 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2262 /* make hwnd_C owned by a topmost window */
2263 DestroyWindow( hwnd_C );
2264 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2267 hwnd_A, 0, GetModuleHandle(0), NULL);
2268 trace("hwnd_C %p\n", hwnd_C);
2269 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2270 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2271 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2272 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2273 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2274 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2276 DestroyWindow(hwnd_A);
2277 DestroyWindow(hwnd_B);
2278 DestroyWindow(hwnd_C);
2279 DestroyWindow(hwnd_F);
2282 static void test_vis_rgn( HWND hwnd )
2284 RECT win_rect, rgn_rect;
2285 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2288 ShowWindow(hwnd,SW_SHOW);
2289 hdc = GetDC( hwnd );
2290 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2291 GetWindowRect( hwnd, &win_rect );
2292 GetRgnBox( hrgn, &rgn_rect );
2295 trace("win9x, mapping to screen coords\n");
2296 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2298 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2299 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2300 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2301 rgn_rect.left, win_rect.left );
2302 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2303 rgn_rect.top, win_rect.top );
2304 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2305 rgn_rect.right, win_rect.right );
2306 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2307 rgn_rect.bottom, win_rect.bottom );
2308 ReleaseDC( hwnd, hdc );
2311 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2313 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2315 HWND child = GetWindow(hwnd, GW_CHILD);
2316 ok(child != 0, "couldn't find child window\n");
2318 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2321 return DefWindowProc(hwnd, msg, wp, lp);
2324 static void test_SetFocus(HWND hwnd)
2327 WNDPROC old_wnd_proc;
2329 /* check if we can set focus to non-visible windows */
2331 ShowWindow(hwnd, SW_SHOW);
2334 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2335 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2336 ShowWindow(hwnd, SW_HIDE);
2339 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2340 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2341 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2344 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2345 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2346 ShowWindow(child, SW_SHOW);
2347 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2348 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2349 ShowWindow(child, SW_HIDE);
2350 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2351 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2352 ShowWindow(child, SW_SHOW);
2353 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2355 ShowWindow(child2, SW_SHOW);
2357 ShowWindow(child, SW_HIDE);
2358 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2359 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2360 ShowWindow(child, SW_SHOW);
2362 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2363 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2364 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2366 ShowWindow(child, SW_HIDE);
2368 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2369 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2370 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2371 ShowWindow(child, SW_HIDE);
2372 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2374 ShowWindow(hwnd, SW_SHOW);
2375 ShowWindow(child, SW_SHOW);
2377 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2378 EnableWindow(hwnd, FALSE);
2379 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2380 EnableWindow(hwnd, TRUE);
2382 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2383 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2384 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2386 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2387 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2388 ShowWindow(hwnd, SW_RESTORE);
2389 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2390 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2391 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2392 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2393 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2395 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2396 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2397 ShowWindow(hwnd, SW_RESTORE);
2398 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2400 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2402 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2404 DestroyWindow( child2 );
2405 DestroyWindow( child );
2408 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2409 static void check_wnd_state_(const char *file, int line,
2410 HWND active, HWND foreground, HWND focus, HWND capture)
2412 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2413 /* only check foreground if it belongs to the current thread */
2414 /* foreground can be moved to a different app pretty much at any time */
2415 if (foreground && GetForegroundWindow() &&
2416 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2417 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2418 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2419 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2422 static void test_SetActiveWindow(HWND hwnd)
2426 flush_events( TRUE );
2427 ShowWindow(hwnd, SW_HIDE);
2430 check_wnd_state(0, 0, 0, 0);
2432 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2434 ShowWindow(hwnd, SW_SHOW);
2435 check_wnd_state(hwnd, hwnd, hwnd, 0);
2437 hwnd2 = SetActiveWindow(0);
2438 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2439 if (!GetActiveWindow()) /* doesn't always work on vista */
2441 check_wnd_state(0, 0, 0, 0);
2442 hwnd2 = SetActiveWindow(hwnd);
2443 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2445 check_wnd_state(hwnd, hwnd, hwnd, 0);
2447 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2448 check_wnd_state(hwnd, hwnd, hwnd, 0);
2450 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2451 check_wnd_state(hwnd, hwnd, hwnd, 0);
2453 ShowWindow(hwnd, SW_HIDE);
2454 check_wnd_state(0, 0, 0, 0);
2456 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2457 SetActiveWindow(hwnd);
2458 check_wnd_state(hwnd, hwnd, hwnd, 0);
2460 ShowWindow(hwnd, SW_SHOW);
2461 check_wnd_state(hwnd, hwnd, hwnd, 0);
2463 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2464 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2466 DestroyWindow(hwnd2);
2467 check_wnd_state(hwnd, hwnd, hwnd, 0);
2469 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2470 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2472 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2473 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2475 DestroyWindow(hwnd2);
2476 check_wnd_state(hwnd, hwnd, hwnd, 0);
2479 struct create_window_thread_params
2482 HANDLE window_created;
2483 HANDLE test_finished;
2486 static DWORD WINAPI create_window_thread(void *param)
2488 struct create_window_thread_params *p = param;
2492 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2494 ret = SetEvent(p->window_created);
2495 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2497 res = WaitForSingleObject(p->test_finished, INFINITE);
2498 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2500 DestroyWindow(p->window);
2504 static void test_SetForegroundWindow(HWND hwnd)
2506 struct create_window_thread_params thread_params;
2513 flush_events( TRUE );
2514 ShowWindow(hwnd, SW_HIDE);
2517 check_wnd_state(0, 0, 0, 0);
2519 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2521 ShowWindow(hwnd, SW_SHOW);
2522 check_wnd_state(hwnd, hwnd, hwnd, 0);
2524 hwnd2 = SetActiveWindow(0);
2525 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2526 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2527 check_wnd_state(hwnd, hwnd, hwnd, 0);
2529 check_wnd_state(0, 0, 0, 0);
2531 ret = SetForegroundWindow(hwnd);
2534 skip( "SetForegroundWindow not working\n" );
2537 check_wnd_state(hwnd, hwnd, hwnd, 0);
2539 SetLastError(0xdeadbeef);
2540 ret = SetForegroundWindow(0);
2541 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2542 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2543 broken(GetLastError() == 0xdeadbeef), /* win9x */
2544 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2545 check_wnd_state(hwnd, hwnd, hwnd, 0);
2547 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2548 check_wnd_state(hwnd, hwnd, hwnd, 0);
2550 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2551 check_wnd_state(hwnd, hwnd, hwnd, 0);
2553 hwnd2 = GetForegroundWindow();
2554 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2555 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2556 hwnd2 = GetForegroundWindow();
2557 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2559 ShowWindow(hwnd, SW_HIDE);
2560 check_wnd_state(0, 0, 0, 0);
2562 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2563 ret = SetForegroundWindow(hwnd);
2564 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2565 check_wnd_state(hwnd, hwnd, hwnd, 0);
2567 ShowWindow(hwnd, SW_SHOW);
2568 check_wnd_state(hwnd, hwnd, hwnd, 0);
2570 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2571 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2573 DestroyWindow(hwnd2);
2574 check_wnd_state(hwnd, hwnd, hwnd, 0);
2576 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2577 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2579 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2580 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2582 DestroyWindow(hwnd2);
2583 check_wnd_state(hwnd, hwnd, hwnd, 0);
2585 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2586 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2588 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2589 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2590 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2591 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2592 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2593 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2594 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2595 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2596 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2598 SetForegroundWindow(hwnd2);
2599 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2601 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2602 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2603 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2604 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2606 SetEvent(thread_params.test_finished);
2607 WaitForSingleObject(thread, INFINITE);
2608 CloseHandle(thread_params.test_finished);
2609 CloseHandle(thread_params.window_created);
2610 CloseHandle(thread);
2611 DestroyWindow(hwnd2);
2614 static WNDPROC old_button_proc;
2616 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2621 key_state = GetKeyState(VK_LBUTTON);
2622 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2624 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2626 if (msg == WM_LBUTTONDOWN)
2630 check_wnd_state(button, button, button, button);
2632 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2634 trace("hwnd %p\n", hwnd);
2636 check_wnd_state(button, button, button, button);
2638 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2640 check_wnd_state(button, button, button, button);
2642 DestroyWindow(hwnd);
2644 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2646 trace("hwnd %p\n", hwnd);
2648 check_wnd_state(button, button, button, button);
2650 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2651 * match internal button state.
2653 SendMessage(button, WM_KILLFOCUS, 0, 0);
2654 check_wnd_state(button, button, button, 0);
2656 ShowWindow(hwnd, SW_SHOW);
2657 check_wnd_state(hwnd, hwnd, hwnd, 0);
2659 capture = SetCapture(hwnd);
2660 ok(capture == 0, "SetCapture() = %p\n", capture);
2662 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2664 DestroyWindow(hwnd);
2666 check_wnd_state(button, 0, button, 0);
2672 static void test_capture_1(void)
2674 HWND button, capture, oldFocus, oldActive;
2676 oldFocus = GetFocus();
2677 oldActive = GetActiveWindow();
2679 capture = GetCapture();
2680 ok(capture == 0, "GetCapture() = %p\n", capture);
2682 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2684 trace("button %p\n", button);
2686 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2688 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2690 capture = SetCapture(button);
2691 ok(capture == 0, "SetCapture() = %p\n", capture);
2692 check_wnd_state(button, 0, button, button);
2694 DestroyWindow(button);
2695 check_wnd_state(oldActive, 0, oldFocus, 0);
2698 static void test_capture_2(void)
2700 HWND button, hwnd, capture, oldFocus, oldActive;
2702 oldFocus = GetFocus();
2703 oldActive = GetActiveWindow();
2704 check_wnd_state(oldActive, 0, oldFocus, 0);
2706 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2708 trace("button %p\n", button);
2710 check_wnd_state(button, button, button, 0);
2712 capture = SetCapture(button);
2713 ok(capture == 0, "SetCapture() = %p\n", capture);
2715 check_wnd_state(button, button, button, button);
2717 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2718 * internal button state.
2720 SendMessage(button, WM_KILLFOCUS, 0, 0);
2721 check_wnd_state(button, button, button, button);
2723 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2725 trace("hwnd %p\n", hwnd);
2727 check_wnd_state(button, button, button, button);
2729 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2731 check_wnd_state(button, button, button, button);
2733 DestroyWindow(hwnd);
2735 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2737 trace("hwnd %p\n", hwnd);
2739 check_wnd_state(button, button, button, button);
2741 ShowWindow(hwnd, SW_SHOW);
2743 check_wnd_state(hwnd, hwnd, hwnd, button);
2745 capture = SetCapture(hwnd);
2746 ok(capture == button, "SetCapture() = %p\n", capture);
2748 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2750 DestroyWindow(hwnd);
2751 check_wnd_state(button, button, button, 0);
2753 DestroyWindow(button);
2754 check_wnd_state(oldActive, 0, oldFocus, 0);
2757 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2761 ShowWindow(hwnd1, SW_HIDE);
2762 ShowWindow(hwnd2, SW_HIDE);
2764 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2765 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2768 check_wnd_state(0, 0, 0, hwnd1);
2771 check_wnd_state(0, 0, 0, hwnd2);
2773 ShowWindow(hwnd1, SW_SHOW);
2774 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2776 ret = ReleaseCapture();
2777 ok (ret, "releasecapture did not return TRUE.\n");
2778 ret = ReleaseCapture();
2779 ok (ret, "releasecapture did not return TRUE after second try.\n");
2782 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2785 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2789 case WM_CAPTURECHANGED:
2791 /* now try to release capture from menu. this should fail */
2792 if (pGetGUIThreadInfo)
2794 memset(>i, 0, sizeof(GUITHREADINFO));
2795 gti.cbSize = sizeof(GUITHREADINFO);
2796 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2797 ok(status, "GetGUIThreadInfo() failed!\n");
2798 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2800 cap_wnd = GetCapture();
2802 /* check that re-setting the capture for the menu fails */
2803 set_cap_wnd = SetCapture(cap_wnd);
2804 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
2805 "SetCapture should have failed!\n");
2808 DestroyWindow(hWnd);
2812 /* check that SetCapture fails for another window and that it does not touch the error code */
2813 set_cap_wnd = SetCapture(hWnd);
2814 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2816 /* check that ReleaseCapture fails and does not touch the error code */
2817 status = ReleaseCapture();
2818 ok(!status, "ReleaseCapture should have failed!\n");
2820 /* check that thread info did not change */
2821 if (pGetGUIThreadInfo)
2823 memset(>i, 0, sizeof(GUITHREADINFO));
2824 gti.cbSize = sizeof(GUITHREADINFO);
2825 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2826 ok(status, "GetGUIThreadInfo() failed!\n");
2827 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2830 /* verify that no capture change took place */
2831 cap_wnd2 = GetCapture();
2832 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2834 /* we are done. kill the window */
2835 DestroyWindow(hWnd);
2839 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2844 /* Test that no-one can mess around with the current capture while a menu is open */
2845 static void test_capture_4(void)
2851 HINSTANCE hInstance = GetModuleHandleA( NULL );
2853 if (!pGetGUIThreadInfo)
2855 win_skip("GetGUIThreadInfo is not available\n");
2858 wclass.lpszClassName = "TestCapture4Class";
2859 wclass.style = CS_HREDRAW | CS_VREDRAW;
2860 wclass.lpfnWndProc = test_capture_4_proc;
2861 wclass.hInstance = hInstance;
2862 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2863 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2864 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2865 wclass.lpszMenuName = 0;
2866 wclass.cbClsExtra = 0;
2867 wclass.cbWndExtra = 0;
2868 assert (RegisterClassA( &wclass ));
2869 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2870 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2871 400, 200, NULL, NULL, hInstance, NULL) );
2872 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2874 hmenu = CreatePopupMenu();
2876 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2877 ok( ret, "AppendMenuA has failed!\n");
2879 /* set main window to have initial capture */
2884 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2888 /* create popup (it will self-destruct) */
2889 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2890 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2895 DestroyWindow(hwnd);
2898 /* PeekMessage wrapper that ignores the messages we don't care about */
2899 static BOOL peek_message( MSG *msg )
2904 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2905 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2909 static void test_keyboard_input(HWND hwnd)
2914 flush_events( TRUE );
2915 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2917 flush_events( TRUE );
2919 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2922 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2924 flush_events( TRUE );
2926 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2927 ret = peek_message(&msg);
2928 ok( ret, "no message available\n");
2929 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2930 ret = peek_message(&msg);
2931 ok( !ret, "message %04x available\n", msg.message);
2933 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2935 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2936 ret = peek_message(&msg);
2937 ok(ret, "no message available\n");
2938 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2939 ret = peek_message(&msg);
2940 ok( !ret, "message %04x available\n", msg.message);
2942 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2944 keybd_event(VK_SPACE, 0, 0, 0);
2945 if (!peek_message(&msg))
2947 skip( "keybd_event didn't work, skipping keyboard test\n" );
2950 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2951 ret = peek_message(&msg);
2952 ok( !ret, "message %04x available\n", msg.message);
2955 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2957 flush_events( TRUE );
2959 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2960 ret = peek_message(&msg);
2961 ok(ret, "no message available\n");
2962 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2963 ret = peek_message(&msg);
2964 ok( !ret, "message %04x available\n", msg.message);
2966 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2968 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2969 ret = peek_message(&msg);
2970 ok(ret, "no message available\n");
2971 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2972 ret = peek_message(&msg);
2973 ok( !ret, "message %04x available\n", msg.message);
2975 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2977 keybd_event(VK_SPACE, 0, 0, 0);
2978 ret = peek_message(&msg);
2979 ok(ret, "no message available\n");
2980 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2981 ret = peek_message(&msg);
2982 ok( !ret, "message %04x available\n", msg.message);
2985 static BOOL wait_for_message( MSG *msg )
2991 ret = peek_message(msg);
2994 if (msg->message == WM_PAINT) DispatchMessage(msg);
2997 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2999 if (!ret) msg->message = 0;
3003 static void test_mouse_input(HWND hwnd)
3013 ShowWindow(hwnd, SW_SHOWNORMAL);
3015 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3017 GetWindowRect(hwnd, &rc);
3018 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3020 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3021 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3024 ShowWindow(popup, SW_SHOW);
3025 UpdateWindow(popup);
3026 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3028 GetWindowRect(popup, &rc);
3029 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3031 x = rc.left + (rc.right - rc.left) / 2;
3032 y = rc.top + (rc.bottom - rc.top) / 2;
3033 trace("setting cursor to (%d,%d)\n", x, y);
3037 if (x != pt.x || y != pt.y)
3039 skip( "failed to set mouse position, skipping mouse input tests\n" );
3043 flush_events( TRUE );
3045 /* Check that setting the same position may generate WM_MOUSEMOVE */
3048 ret = peek_message(&msg);
3051 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3052 msg.hwnd, msg.message);
3053 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3054 x, y, msg.pt.x, msg.pt.y);
3057 /* force the system to update its internal queue mouse position,
3058 * otherwise it won't generate relative mouse movements below.
3060 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3061 flush_events( TRUE );
3064 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3065 flush_events( FALSE );
3066 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3067 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3069 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3070 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3071 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3072 DispatchMessage(&msg);
3074 ret = peek_message(&msg);
3075 ok( !ret, "message %04x available\n", msg.message);
3077 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3078 ShowWindow(popup, SW_HIDE);
3079 ret = wait_for_message( &msg );
3081 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3082 flush_events( TRUE );
3084 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3085 ShowWindow(hwnd, SW_HIDE);
3086 ret = wait_for_message( &msg );
3087 ok( !ret, "message %04x available\n", msg.message);
3088 flush_events( TRUE );
3090 /* test mouse clicks */
3092 ShowWindow(hwnd, SW_SHOW);
3093 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3094 flush_events( TRUE );
3095 ShowWindow(popup, SW_SHOW);
3096 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3097 flush_events( TRUE );
3099 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3100 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3101 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3102 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3104 ret = wait_for_message( &msg );
3107 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3110 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3112 ret = wait_for_message( &msg );
3113 ok(ret, "no message available\n");
3116 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3117 msg.hwnd, popup, msg.message);
3119 ret = wait_for_message( &msg );
3120 ok(ret, "no message available\n");
3121 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3122 msg.hwnd, popup, msg.message);
3124 ret = wait_for_message( &msg );
3125 ok(ret, "no message available\n");
3126 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3127 msg.hwnd, popup, msg.message);
3129 ret = wait_for_message( &msg );
3130 ok(ret, "no message available\n");
3131 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3132 msg.hwnd, popup, msg.message);
3134 ret = peek_message(&msg);
3135 ok(!ret, "message %04x available\n", msg.message);
3137 ShowWindow(popup, SW_HIDE);
3138 flush_events( TRUE );
3140 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3141 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3142 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3143 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3145 ret = wait_for_message( &msg );
3146 ok(ret, "no message available\n");
3147 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3148 msg.hwnd, hwnd, msg.message);
3149 ret = wait_for_message( &msg );
3150 ok(ret, "no message available\n");
3151 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3152 msg.hwnd, hwnd, msg.message);
3154 test_lbuttondown_flag = TRUE;
3155 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3156 test_lbuttondown_flag = FALSE;
3158 ret = wait_for_message( &msg );
3159 ok(ret, "no message available\n");
3160 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3161 msg.hwnd, popup, msg.message);
3162 ok(peek_message(&msg), "no message available\n");
3163 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3164 msg.hwnd, popup, msg.message);
3165 ok(peek_message(&msg), "no message available\n");
3167 /* Test WM_MOUSEACTIVATE */
3168 #define TEST_MOUSEACTIVATE(A,B) \
3169 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3170 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3172 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3173 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3174 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3175 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3176 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3177 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3178 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3179 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3180 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3181 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3182 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3183 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3184 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3185 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3186 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3187 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3188 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3189 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3190 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3191 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3192 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3193 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3194 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3195 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3198 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3199 flush_events( TRUE );
3201 DestroyWindow(popup);
3204 static void test_validatergn(HWND hwnd)
3210 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3211 ShowWindow(hwnd, SW_SHOW);
3212 UpdateWindow( hwnd);
3213 /* test that ValidateRect validates children*/
3214 InvalidateRect( child, NULL, 1);
3215 GetWindowRect( child, &rc);
3216 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3217 ret = GetUpdateRect( child, &rc2, 0);
3218 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3219 "Update rectangle is empty!\n");
3220 ValidateRect( hwnd, &rc);
3221 ret = GetUpdateRect( child, &rc2, 0);
3222 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3223 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3224 rc2.right, rc2.bottom);
3226 /* now test ValidateRgn */
3227 InvalidateRect( child, NULL, 1);
3228 GetWindowRect( child, &rc);
3229 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3230 rgn = CreateRectRgnIndirect( &rc);
3231 ValidateRgn( hwnd, rgn);
3232 ret = GetUpdateRect( child, &rc2, 0);
3233 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3234 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3235 rc2.right, rc2.bottom);
3238 DestroyWindow( child );
3241 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3244 MoveWindow( hwnd, 0, 0, x, y, 0);
3245 GetWindowRect( hwnd, prc);
3247 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3248 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3249 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3252 static void test_nccalcscroll(HWND parent)
3255 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3256 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3257 HWND hwnd = CreateWindowExA(0, "static", NULL,
3258 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3259 10, 10, 200, 200, parent, 0, 0, NULL);
3260 ShowWindow( parent, SW_SHOW);
3261 UpdateWindow( parent);
3263 /* test window too low for a horizontal scroll bar */
3264 nccalchelper( hwnd, 100, sbheight, &rc1);
3265 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3266 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3268 /* test window just high enough for a horizontal scroll bar */
3269 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3270 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3271 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3273 /* test window too narrow for a vertical scroll bar */
3274 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3275 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3276 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3278 /* test window just wide enough for a vertical scroll bar */
3279 nccalchelper( hwnd, sbwidth, 100, &rc1);
3280 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3281 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3283 /* same test, but with client edge: not enough width */
3284 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3285 nccalchelper( hwnd, sbwidth, 100, &rc1);
3286 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3287 "Width should be %d size is %d,%d - %d,%d\n",
3288 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3290 DestroyWindow( hwnd);
3293 static void test_SetParent(void)
3296 HWND desktop = GetDesktopWindow();
3298 /* FIXME: This detection is not correct as it also covers (all?) XP+ */
3299 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3300 HWND parent, child1, child2, child3, child4, sibling;
3302 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3303 100, 100, 200, 200, 0, 0, 0, NULL);
3304 assert(parent != 0);
3305 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3306 0, 0, 50, 50, parent, 0, 0, NULL);
3307 assert(child1 != 0);
3308 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3309 0, 0, 50, 50, child1, 0, 0, NULL);
3310 assert(child2 != 0);
3311 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3312 0, 0, 50, 50, child2, 0, 0, NULL);
3313 assert(child3 != 0);
3314 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3315 0, 0, 50, 50, child3, 0, 0, NULL);
3316 assert(child4 != 0);
3318 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3319 parent, child1, child2, child3, child4);
3321 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3322 check_parents(child1, parent, parent, parent, 0, parent, parent);
3323 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3324 check_parents(child3, child2, child2, child2, 0, child2, parent);
3325 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3327 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3328 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3329 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3330 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3331 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3333 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3334 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3335 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3336 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3337 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3338 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3339 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3340 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3341 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3343 if (!is_win9x) /* Win9x doesn't survive this test */
3345 ok(!SetParent(parent, child1), "SetParent should fail\n");
3346 ok(!SetParent(child2, child3), "SetParent should fail\n");
3347 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3348 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3349 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3350 ok(!SetParent(child2, parent), "SetParent should fail\n");
3351 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3353 check_parents(parent, child4, child4, 0, 0, child4, parent);
3354 check_parents(child1, parent, parent, parent, 0, child4, parent);
3355 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3356 check_parents(child3, child2, child2, child2, 0, child2, parent);
3357 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3360 skip("Win9x/WinMe crash\n");
3362 hMenu = CreateMenu();
3363 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3364 100, 100, 200, 200, 0, hMenu, 0, NULL);
3365 assert(sibling != 0);
3367 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3368 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3370 ret = DestroyWindow(parent);
3371 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3373 ok(!IsWindow(parent), "parent still exists\n");
3374 ok(!IsWindow(sibling), "sibling still exists\n");
3375 ok(!IsWindow(child1), "child1 still exists\n");
3376 ok(!IsWindow(child2), "child2 still exists\n");
3377 ok(!IsWindow(child3), "child3 still exists\n");
3378 ok(!IsWindow(child4), "child4 still exists\n");
3381 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3383 LPCREATESTRUCT lpcs;
3390 lpcs = (LPCREATESTRUCT)lparam;
3391 lpss = lpcs->lpCreateParams;
3394 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3395 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3396 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3397 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3399 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3401 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3402 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3403 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3405 ok(lpss->styleNew == lpcs->style,
3406 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3407 lpss->styleNew, lpcs->style);
3411 return DefWindowProc(hwnd, msg, wparam, lparam);
3414 static ATOM atomStyleCheckClass;
3416 static void register_style_check_class(void)
3424 GetModuleHandle(NULL),
3426 LoadCursor(NULL, IDC_ARROW),
3427 (HBRUSH)(COLOR_BTNFACE+1),
3429 TEXT("WineStyleCheck"),
3432 atomStyleCheckClass = RegisterClass(&wc);
3435 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3437 DWORD dwActualStyle;
3438 DWORD dwActualExStyle;
3441 HWND hwndParent = NULL;
3443 ss.styleNew = dwStyleIn;
3444 ss.styleOld = dwExStyleIn;
3446 if (dwStyleIn & WS_CHILD)
3448 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3449 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3452 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3453 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3456 flush_events( TRUE );
3458 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3459 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3460 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3461 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3462 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3464 DestroyWindow(hwnd);
3465 if (hwndParent) DestroyWindow(hwndParent);
3468 /* tests what window styles the window manager automatically adds */
3469 static void test_window_styles(void)
3471 register_style_check_class();
3473 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3474 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3475 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3476 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3477 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3478 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3479 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3480 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3481 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3482 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3483 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3485 if (pGetLayeredWindowAttributes)
3487 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3488 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3489 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3490 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3494 static void test_scrollwindow( HWND hwnd)
3500 ShowWindow( hwnd, SW_SHOW);
3501 UpdateWindow( hwnd);
3502 flush_events( TRUE );
3503 GetClientRect( hwnd, &rc);
3505 /* test ScrollWindow(Ex) with no clip rectangle */
3506 /* paint the lower half of the window black */
3508 rc2.top = ( rc2.top + rc2.bottom) / 2;
3509 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3510 /* paint the upper half of the window white */
3511 rc2.bottom = rc2.top;
3513 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3514 /* scroll lower half up */
3516 rc2.top = ( rc2.top + rc2.bottom) / 2;
3517 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3518 flush_events(FALSE);
3519 /* expected: black should have scrolled to the upper half */
3520 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3521 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3522 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3523 /* paint the lower half of the window black */
3525 rc2.top = ( rc2.top + rc2.bottom) / 2;
3526 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3527 /* paint the upper half of the window white */
3528 rc2.bottom = rc2.top;
3530 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3531 /* scroll lower half up */
3533 rc2.top = ( rc2.top + rc2.bottom) / 2;
3535 rc3.left = rc3.right / 4;
3536 rc3.right -= rc3.right / 4;
3537 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3538 flush_events(FALSE);
3539 /* expected: black should have scrolled to the upper half */
3540 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3541 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3544 ReleaseDC( hwnd, hdc);
3547 static void test_scrollvalidate( HWND parent)
3550 HRGN hrgn=CreateRectRgn(0,0,0,0);
3551 HRGN exprgn, tmprgn, clipping;
3552 RECT rc, rcu, cliprc;
3553 /* create two overlapping child windows. The visual region
3554 * of hwnd1 is clipped by the overlapping part of
3555 * hwnd2 because of the WS_CLIPSIBLING style */
3558 clipping = CreateRectRgn(0,0,0,0);
3559 tmprgn = CreateRectRgn(0,0,0,0);
3560 exprgn = CreateRectRgn(0,0,0,0);
3561 hwnd2 = CreateWindowExA(0, "static", NULL,
3562 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3563 75, 30, 100, 100, parent, 0, 0, NULL);
3564 hwnd1 = CreateWindowExA(0, "static", NULL,
3565 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3566 25, 50, 100, 100, parent, 0, 0, NULL);
3567 ShowWindow( parent, SW_SHOW);
3568 UpdateWindow( parent);
3569 GetClientRect( hwnd1, &rc);
3571 SetRectRgn( clipping, 10, 10, 90, 90);
3572 hdc = GetDC( hwnd1);
3573 /* for a visual touch */
3574 TextOut( hdc, 0,10, "0123456789", 10);
3575 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3576 if (winetest_debug > 0) dump_region(hrgn);
3577 /* create a region with what is expected */
3578 SetRectRgn( exprgn, 39,0,49,74);
3579 SetRectRgn( tmprgn, 88,79,98,93);
3580 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3581 SetRectRgn( tmprgn, 0,93,98,98);
3582 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3583 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3584 trace("update rect is %d,%d - %d,%d\n",
3585 rcu.left,rcu.top,rcu.right,rcu.bottom);
3586 /* now with clipping region */
3587 SelectClipRgn( hdc, clipping);
3588 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3589 if (winetest_debug > 0) dump_region(hrgn);
3590 /* create a region with what is expected */
3591 SetRectRgn( exprgn, 39,10,49,74);
3592 SetRectRgn( tmprgn, 80,79,90,85);
3593 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3594 SetRectRgn( tmprgn, 10,85,90,90);
3595 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3596 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3597 trace("update rect is %d,%d - %d,%d\n",
3598 rcu.left,rcu.top,rcu.right,rcu.bottom);
3599 ReleaseDC( hwnd1, hdc);
3601 /* test scrolling a window with an update region */
3602 DestroyWindow( hwnd2);
3603 ValidateRect( hwnd1, NULL);
3604 SetRect( &rc, 40,40, 50,50);
3605 InvalidateRect( hwnd1, &rc, 1);
3606 GetClientRect( hwnd1, &rc);
3608 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3609 SW_SCROLLCHILDREN | SW_INVALIDATE);
3610 if (winetest_debug > 0) dump_region(hrgn);
3611 SetRectRgn( exprgn, 88,0,98,98);
3612 SetRectRgn( tmprgn, 30, 40, 50, 50);
3613 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3614 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3616 /* clear an update region */
3617 UpdateWindow( hwnd1 );
3619 SetRect( &rc, 0,40, 100,60);
3620 SetRect( &cliprc, 0,0, 100,100);
3621 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3622 if (winetest_debug > 0) dump_region( hrgn );
3623 SetRectRgn( exprgn, 0, 40, 98, 60 );
3624 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3626 /* now test ScrollWindowEx with a combination of
3627 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3628 /* make hwnd2 the child of hwnd1 */
3629 hwnd2 = CreateWindowExA(0, "static", NULL,
3630 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3631 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3632 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3633 GetClientRect( hwnd1, &rc);
3636 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3637 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3638 ValidateRect( hwnd1, NULL);
3639 ValidateRect( hwnd2, NULL);
3640 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3641 SW_SCROLLCHILDREN | SW_INVALIDATE);
3642 if (winetest_debug > 0) dump_region(hrgn);
3643 SetRectRgn( exprgn, 88,0,98,88);
3644 SetRectRgn( tmprgn, 0,88,98,98);
3645 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3646 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3648 /* SW_SCROLLCHILDREN */
3649 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3650 ValidateRect( hwnd1, NULL);
3651 ValidateRect( hwnd2, NULL);
3652 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3653 if (winetest_debug > 0) dump_region(hrgn);
3654 /* expected region is the same as in previous test */
3655 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3657 /* no SW_SCROLLCHILDREN */
3658 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3659 ValidateRect( hwnd1, NULL);
3660 ValidateRect( hwnd2, NULL);
3661 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3662 if (winetest_debug > 0) dump_region(hrgn);
3663 /* expected region is the same as in previous test */
3664 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3666 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3667 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3668 ValidateRect( hwnd1, NULL);
3669 ValidateRect( hwnd2, NULL);
3670 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3671 if (winetest_debug > 0) dump_region(hrgn);
3672 SetRectRgn( exprgn, 88,0,98,20);
3673 SetRectRgn( tmprgn, 20,20,98,30);
3674 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3675 SetRectRgn( tmprgn, 20,30,30,88);
3676 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3677 SetRectRgn( tmprgn, 0,88,30,98);
3678 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3679 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3682 DeleteObject( hrgn);
3683 DeleteObject( exprgn);
3684 DeleteObject( tmprgn);
3685 DestroyWindow( hwnd1);
3686 DestroyWindow( hwnd2);
3689 /* couple of tests of return values of scrollbar functions
3690 * called on a scrollbarless window */
3691 static void test_scroll(void)
3696 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3697 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3698 100, 100, 200, 200, 0, 0, 0, NULL);
3700 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3701 if (!ret) /* win9x */
3703 win_skip( "GetScrollRange doesn't work\n" );
3704 DestroyWindow( hwnd);
3707 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3708 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3709 si.cbSize = sizeof( si);
3710 si.fMask = SIF_PAGE;
3711 si.nPage = 0xdeadbeef;
3712 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3713 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3714 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3716 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3717 ok( ret, "GetScrollRange returns FALSE\n");
3718 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3719 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3720 si.cbSize = sizeof( si);
3721 si.fMask = SIF_PAGE;
3722 si.nPage = 0xdeadbeef;
3723 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3724 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3725 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3727 DestroyWindow( hwnd);
3730 static void test_scrolldc( HWND parent)
3733 HRGN exprgn, tmprgn, hrgn;
3734 RECT rc, rc2, rcu, cliprc;
3738 hrgn = CreateRectRgn(0,0,0,0);
3739 tmprgn = CreateRectRgn(0,0,0,0);
3740 exprgn = CreateRectRgn(0,0,0,0);
3742 hwnd1 = CreateWindowExA(0, "static", NULL,
3743 WS_CHILD| WS_VISIBLE,
3744 25, 50, 100, 100, parent, 0, 0, NULL);
3745 ShowWindow( parent, SW_SHOW);
3746 UpdateWindow( parent);
3747 flush_events( TRUE );
3748 GetClientRect( hwnd1, &rc);
3749 hdc = GetDC( hwnd1);
3750 /* paint the upper half of the window black */
3752 rc2.bottom = ( rc.top + rc.bottom) /2;
3753 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3754 /* clip region is the lower half */
3756 cliprc.top = (rc.top + rc.bottom) /2;
3757 /* test whether scrolled pixels are properly clipped */
3758 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3759 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3760 /* this scroll should not cause any visible changes */
3761 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3762 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3763 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3764 /* test with NULL clip rect */
3765 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3766 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3767 trace("update rect: %d,%d - %d,%d\n",
3768 rcu.left, rcu.top, rcu.right, rcu.bottom);
3769 if (winetest_debug > 0) dump_region(hrgn);
3770 SetRect(&rc2, 0, 0, 100, 100);
3771 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3772 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3774 SetRectRgn( exprgn, 0, 0, 20, 80);
3775 SetRectRgn( tmprgn, 0, 80, 100, 100);
3776 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3777 if (winetest_debug > 0) dump_region(exprgn);
3778 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3779 /* test clip rect > scroll rect */
3780 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3782 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3783 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3784 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3785 SetRectRgn( exprgn, 25, 25, 75, 35);
3786 SetRectRgn( tmprgn, 25, 35, 35, 75);
3787 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3788 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3789 trace("update rect: %d,%d - %d,%d\n",
3790 rcu.left, rcu.top, rcu.right, rcu.bottom);
3791 if (winetest_debug > 0) dump_region(hrgn);
3795 DeleteObject(exprgn);
3796 DeleteObject(tmprgn);
3797 DestroyWindow(hwnd1);
3800 static void test_params(void)
3805 /* Just a param check */
3806 if (pGetMonitorInfoA)
3808 SetLastError(0xdeadbeef);
3809 rc = GetWindowText(hwndMain2, NULL, 1024);
3810 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3814 /* Skips actually on Win95 and NT4 */
3815 win_skip("Test would crash on Win95\n");
3818 SetLastError(0xdeadbeef);
3819 hwnd=CreateWindow("LISTBOX", "TestList",
3820 (LBS_STANDARD & ~LBS_SORT),
3822 NULL, (HMENU)1, NULL, 0);
3824 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3825 "CreateWindow with invalid menu handle should fail\n");
3827 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3828 GetLastError() == 0xdeadbeef, /* Win9x */
3829 "wrong last error value %d\n", GetLastError());
3832 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3836 hwnd = CreateWindowEx(exStyle, class, class, style,
3843 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3846 ShowWindow(hwnd, SW_SHOW);
3848 test_nonclient_area(hwnd);
3851 DestroyWindow(hwnd);
3854 static BOOL AWR_init(void)
3858 class.style = CS_HREDRAW | CS_VREDRAW;
3859 class.lpfnWndProc = DefWindowProcA;
3860 class.cbClsExtra = 0;
3861 class.cbWndExtra = 0;
3862 class.hInstance = 0;
3863 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3864 class.hCursor = LoadCursor (0, IDC_ARROW);
3865 class.hbrBackground = 0;
3866 class.lpszMenuName = 0;
3867 class.lpszClassName = szAWRClass;
3869 if (!RegisterClass (&class)) {
3870 ok(FALSE, "RegisterClass failed\n");
3874 hmenu = CreateMenu();
3877 ok(hmenu != 0, "Failed to create menu\n");
3878 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3884 static void test_AWR_window_size(BOOL menu)
3888 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3891 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3892 WS_HSCROLL, WS_VSCROLL
3896 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3899 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3900 WS_EX_DLGMODALFRAME,
3907 /* A exhaustive check of all the styles takes too long
3908 * so just do a (hopefully representative) sample
3910 for (i = 0; i < COUNTOF(styles); ++i)
3911 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3912 for (i = 0; i < COUNTOF(exStyles); ++i) {
3913 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3914 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3919 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3921 static void test_AdjustWindowRect(void)
3926 SHOWSYSMETRIC(SM_CYCAPTION);
3927 SHOWSYSMETRIC(SM_CYSMCAPTION);
3928 SHOWSYSMETRIC(SM_CYMENU);
3929 SHOWSYSMETRIC(SM_CXEDGE);
3930 SHOWSYSMETRIC(SM_CYEDGE);
3931 SHOWSYSMETRIC(SM_CXVSCROLL);
3932 SHOWSYSMETRIC(SM_CYHSCROLL);
3933 SHOWSYSMETRIC(SM_CXFRAME);
3934 SHOWSYSMETRIC(SM_CYFRAME);
3935 SHOWSYSMETRIC(SM_CXDLGFRAME);
3936 SHOWSYSMETRIC(SM_CYDLGFRAME);
3937 SHOWSYSMETRIC(SM_CXBORDER);
3938 SHOWSYSMETRIC(SM_CYBORDER);
3940 test_AWR_window_size(FALSE);
3941 test_AWR_window_size(TRUE);
3945 #undef SHOWSYSMETRIC
3948 /* Global variables to trigger exit from loop */
3949 static int redrawComplete, WMPAINT_count;
3951 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3956 trace("doing WM_PAINT %d\n", WMPAINT_count);
3958 if (WMPAINT_count > 10 && redrawComplete == 0) {
3960 BeginPaint(hwnd, &ps);
3961 EndPaint(hwnd, &ps);
3966 return DefWindowProc(hwnd, msg, wparam, lparam);
3969 /* Ensure we exit from RedrawNow regardless of invalidated area */
3970 static void test_redrawnow(void)
3975 cls.style = CS_DBLCLKS;
3976 cls.lpfnWndProc = redraw_window_procA;
3979 cls.hInstance = GetModuleHandleA(0);
3981 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3982 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3983 cls.lpszMenuName = NULL;
3984 cls.lpszClassName = "RedrawWindowClass";
3986 if(!RegisterClassA(&cls)) {
3987 trace("Register failed %d\n", GetLastError());
3991 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3992 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3994 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3995 ShowWindow(hwndMain, SW_SHOW);
3996 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3997 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3998 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3999 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4000 redrawComplete = TRUE;
4001 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4004 DestroyWindow( hwndMain);
4007 struct parentdc_stat {
4013 struct parentdc_test {
4014 struct parentdc_stat main, main_todo;
4015 struct parentdc_stat child1, child1_todo;
4016 struct parentdc_stat child2, child2_todo;
4019 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4024 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4029 GetClientRect(hwnd, &rc);
4030 CopyRect(&t->client, &rc);
4031 GetWindowRect(hwnd, &rc);
4032 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4033 t->client.left, t->client.top, t->client.right, t->client.bottom,
4034 rc.left, rc.top, rc.right, rc.bottom);
4035 BeginPaint(hwnd, &ps);
4036 CopyRect(&t->paint, &ps.rcPaint);
4037 GetClipBox(ps.hdc, &rc);
4038 CopyRect(&t->clip, &rc);
4039 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4040 rc.left, rc.top, rc.right, rc.bottom,
4041 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4042 EndPaint(hwnd, &ps);
4045 return DefWindowProc(hwnd, msg, wparam, lparam);
4048 static void zero_parentdc_stat(struct parentdc_stat *t)
4050 SetRectEmpty(&t->client);
4051 SetRectEmpty(&t->clip);
4052 SetRectEmpty(&t->paint);
4055 static void zero_parentdc_test(struct parentdc_test *t)
4057 zero_parentdc_stat(&t->main);
4058 zero_parentdc_stat(&t->child1);
4059 zero_parentdc_stat(&t->child2);
4062 #define parentdc_field_ok(t, w, r, f, got) \
4063 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4064 ": expected %d, got %d\n", \
4067 #define parentdc_todo_field_ok(t, w, r, f, got) \
4068 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4069 else parentdc_field_ok(t, w, r, f, got)
4071 #define parentdc_rect_ok(t, w, r, got) \
4072 parentdc_todo_field_ok(t, w, r, left, got); \
4073 parentdc_todo_field_ok(t, w, r, top, got); \
4074 parentdc_todo_field_ok(t, w, r, right, got); \
4075 parentdc_todo_field_ok(t, w, r, bottom, got);
4077 #define parentdc_win_ok(t, w, got) \
4078 parentdc_rect_ok(t, w, client, got); \
4079 parentdc_rect_ok(t, w, clip, got); \
4080 parentdc_rect_ok(t, w, paint, got);
4082 #define parentdc_ok(t, got) \
4083 parentdc_win_ok(t, main, got); \
4084 parentdc_win_ok(t, child1, got); \
4085 parentdc_win_ok(t, child2, got);
4087 static void test_csparentdc(void)
4089 WNDCLASSA clsMain, cls;
4090 HWND hwndMain, hwnd1, hwnd2;
4093 struct parentdc_test test_answer;
4095 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4096 const struct parentdc_test test1 =
4098 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4099 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4100 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4103 const struct parentdc_test test2 =
4105 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4106 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4107 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4110 const struct parentdc_test test3 =
4112 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4113 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4114 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4117 const struct parentdc_test test4 =
4119 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4120 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4121 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4124 const struct parentdc_test test5 =
4126 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4127 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4128 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4131 const struct parentdc_test test6 =
4133 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4134 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4135 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4138 const struct parentdc_test test7 =
4140 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4141 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4142 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4146 clsMain.style = CS_DBLCLKS;
4147 clsMain.lpfnWndProc = parentdc_window_procA;
4148 clsMain.cbClsExtra = 0;
4149 clsMain.cbWndExtra = 0;
4150 clsMain.hInstance = GetModuleHandleA(0);
4152 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4153 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4154 clsMain.lpszMenuName = NULL;
4155 clsMain.lpszClassName = "ParentDcMainWindowClass";
4157 if(!RegisterClassA(&clsMain)) {
4158 trace("Register failed %d\n", GetLastError());
4162 cls.style = CS_DBLCLKS | CS_PARENTDC;
4163 cls.lpfnWndProc = parentdc_window_procA;
4166 cls.hInstance = GetModuleHandleA(0);
4168 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4169 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4170 cls.lpszMenuName = NULL;
4171 cls.lpszClassName = "ParentDcWindowClass";
4173 if(!RegisterClassA(&cls)) {
4174 trace("Register failed %d\n", GetLastError());
4178 SetRect(&rc, 0, 0, 150, 150);
4179 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4180 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4181 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4182 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4183 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4184 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4185 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4186 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4187 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4188 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4189 ShowWindow(hwndMain, SW_SHOW);
4190 ShowWindow(hwnd1, SW_SHOW);
4191 ShowWindow(hwnd2, SW_SHOW);
4192 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4193 flush_events( TRUE );
4195 zero_parentdc_test(&test_answer);
4196 InvalidateRect(hwndMain, NULL, TRUE);
4197 flush_events( TRUE );
4198 parentdc_ok(test1, test_answer);
4200 zero_parentdc_test(&test_answer);
4201 SetRect(&rc, 0, 0, 50, 50);
4202 InvalidateRect(hwndMain, &rc, TRUE);
4203 flush_events( TRUE );
4204 parentdc_ok(test2, test_answer);
4206 zero_parentdc_test(&test_answer);
4207 SetRect(&rc, 0, 0, 10, 10);
4208 InvalidateRect(hwndMain, &rc, TRUE);
4209 flush_events( TRUE );
4210 parentdc_ok(test3, test_answer);
4212 zero_parentdc_test(&test_answer);
4213 SetRect(&rc, 40, 40, 50, 50);
4214 InvalidateRect(hwndMain, &rc, TRUE);
4215 flush_events( TRUE );
4216 parentdc_ok(test4, test_answer);
4218 zero_parentdc_test(&test_answer);
4219 SetRect(&rc, 20, 20, 60, 60);
4220 InvalidateRect(hwndMain, &rc, TRUE);
4221 flush_events( TRUE );
4222 parentdc_ok(test5, test_answer);
4224 zero_parentdc_test(&test_answer);
4225 SetRect(&rc, 0, 0, 10, 10);
4226 InvalidateRect(hwnd1, &rc, TRUE);
4227 flush_events( TRUE );
4228 parentdc_ok(test6, test_answer);
4230 zero_parentdc_test(&test_answer);
4231 SetRect(&rc, -5, -5, 65, 65);
4232 InvalidateRect(hwnd1, &rc, TRUE);
4233 flush_events( TRUE );
4234 parentdc_ok(test7, test_answer);
4236 DestroyWindow(hwndMain);
4237 DestroyWindow(hwnd1);
4238 DestroyWindow(hwnd2);
4241 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4243 return DefWindowProcA(hwnd, msg, wparam, lparam);
4246 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4248 return DefWindowProcW(hwnd, msg, wparam, lparam);
4251 static void test_IsWindowUnicode(void)
4253 static const char ansi_class_nameA[] = "ansi class name";
4254 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4255 static const char unicode_class_nameA[] = "unicode class name";
4256 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4261 memset(&classW, 0, sizeof(classW));
4262 classW.hInstance = GetModuleHandleA(0);
4263 classW.lpfnWndProc = def_window_procW;
4264 classW.lpszClassName = unicode_class_nameW;
4265 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4267 memset(&classA, 0, sizeof(classA));
4268 classA.hInstance = GetModuleHandleA(0);
4269 classA.lpfnWndProc = def_window_procA;
4270 classA.lpszClassName = ansi_class_nameA;
4271 assert(RegisterClassA(&classA));
4273 /* unicode class: window proc */
4274 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4275 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4278 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4279 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4280 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4281 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4282 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4284 DestroyWindow(hwnd);
4286 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4287 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4290 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4291 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4292 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4293 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4294 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4296 DestroyWindow(hwnd);
4298 /* ansi class: window proc */
4299 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4300 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4303 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4304 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4305 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4306 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4307 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4309 DestroyWindow(hwnd);
4311 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4312 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4315 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4316 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4317 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4318 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4319 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4321 DestroyWindow(hwnd);
4323 /* unicode class: class proc */
4324 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4325 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4328 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4329 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4330 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4331 /* do not restore class window proc back to unicode */
4333 DestroyWindow(hwnd);
4335 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4336 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4339 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4340 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4341 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4343 DestroyWindow(hwnd);
4345 /* ansi class: class proc */
4346 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4347 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4350 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4351 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4352 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4353 /* do not restore class window proc back to ansi */
4355 DestroyWindow(hwnd);
4357 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4358 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4361 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4362 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4363 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4365 DestroyWindow(hwnd);
4368 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4372 if (msg != WM_GETMINMAXINFO)
4373 return DefWindowProc(hwnd, msg, wp, lp);
4375 minmax = (MINMAXINFO *)lp;
4377 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4379 minmax->ptReserved.x = 0;
4380 minmax->ptReserved.y = 0;
4381 minmax->ptMaxSize.x = 400;
4382 minmax->ptMaxSize.y = 400;
4383 minmax->ptMaxPosition.x = 300;
4384 minmax->ptMaxPosition.y = 300;
4385 minmax->ptMaxTrackSize.x = 200;
4386 minmax->ptMaxTrackSize.y = 200;
4387 minmax->ptMinTrackSize.x = 100;
4388 minmax->ptMinTrackSize.y = 100;
4391 DefWindowProc(hwnd, msg, wp, lp);
4395 static int expected_cx, expected_cy;
4396 static RECT expected_rect, broken_rect;
4398 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4402 case WM_GETMINMAXINFO:
4405 GetWindowRect( hwnd, &rect );
4406 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4407 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4408 return DefWindowProc(hwnd, msg, wp, lp);
4413 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4415 GetWindowRect( hwnd, &rect );
4416 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4417 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4418 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4419 "wrong x size %d/%d\n", cs->cx, expected_cx );
4420 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4421 "wrong y size %d/%d\n", cs->cy, expected_cy );
4422 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4423 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4424 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4425 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4426 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4427 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4428 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4429 rect.left, rect.top, rect.right, rect.bottom,
4430 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4431 return DefWindowProc(hwnd, msg, wp, lp);
4435 RECT rect, *r = (RECT *)lp;
4436 GetWindowRect( hwnd, &rect );
4437 ok( !memcmp( &rect, r, sizeof(rect) ),
4438 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4439 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4440 return DefWindowProc(hwnd, msg, wp, lp);
4443 return DefWindowProc(hwnd, msg, wp, lp);
4447 static void test_CreateWindow(void)
4455 #define expect_menu(window, menu) \
4456 SetLastError(0xdeadbeef); \
4457 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4459 #define expect_style(window, style)\
4460 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4462 #define expect_ex_style(window, ex_style)\
4463 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4465 #define expect_gle_broken_9x(gle)\
4466 ok(GetLastError() == gle ||\
4467 broken(GetLastError() == 0xdeadbeef),\
4468 "IsMenu set error %d\n", GetLastError())
4470 hmenu = CreateMenu();
4472 parent = GetDesktopWindow();
4473 assert(parent != 0);
4475 SetLastError(0xdeadbeef);
4476 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4479 SetLastError(0xdeadbeef);
4480 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4481 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4482 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4483 expect_menu(hwnd, 1);
4484 expect_style(hwnd, WS_CHILD);
4485 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4486 DestroyWindow(hwnd);
4488 SetLastError(0xdeadbeef);
4489 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4490 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4491 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4492 expect_menu(hwnd, 1);
4493 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4494 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4495 DestroyWindow(hwnd);
4497 SetLastError(0xdeadbeef);
4498 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4499 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4500 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4501 expect_menu(hwnd, 1);
4502 expect_style(hwnd, WS_CHILD);
4503 expect_ex_style(hwnd, 0);
4504 DestroyWindow(hwnd);
4506 SetLastError(0xdeadbeef);
4507 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4508 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4509 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4510 expect_menu(hwnd, 1);
4511 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4512 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4513 DestroyWindow(hwnd);
4516 SetLastError(0xdeadbeef);
4517 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4518 0, 0, 100, 100, parent, hmenu, 0, NULL);
4519 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4520 expect_menu(hwnd, hmenu);
4521 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4522 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4523 DestroyWindow(hwnd);
4524 SetLastError(0xdeadbeef);
4525 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4526 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4528 hmenu = CreateMenu();
4530 SetLastError(0xdeadbeef);
4531 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4532 0, 0, 100, 100, parent, hmenu, 0, NULL);
4533 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4534 expect_menu(hwnd, hmenu);
4535 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4536 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4537 DestroyWindow(hwnd);
4538 SetLastError(0xdeadbeef);
4539 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4540 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4542 hmenu = CreateMenu();
4544 SetLastError(0xdeadbeef);
4545 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4546 0, 0, 100, 100, parent, hmenu, 0, NULL);
4547 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4548 expect_menu(hwnd, hmenu);
4549 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4550 expect_ex_style(hwnd, 0);
4551 DestroyWindow(hwnd);
4552 SetLastError(0xdeadbeef);
4553 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4554 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4556 hmenu = CreateMenu();
4558 SetLastError(0xdeadbeef);
4559 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4560 0, 0, 100, 100, parent, hmenu, 0, NULL);
4561 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4562 expect_menu(hwnd, hmenu);
4563 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4564 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4565 DestroyWindow(hwnd);
4566 SetLastError(0xdeadbeef);
4567 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4568 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4570 /* WS_CHILD | WS_POPUP */
4571 SetLastError(0xdeadbeef);
4572 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4573 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4574 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4575 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4577 DestroyWindow(hwnd);
4579 hmenu = CreateMenu();
4581 SetLastError(0xdeadbeef);
4582 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4583 0, 0, 100, 100, parent, hmenu, 0, NULL);
4584 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4585 expect_menu(hwnd, hmenu);
4586 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4587 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4588 DestroyWindow(hwnd);
4589 SetLastError(0xdeadbeef);
4590 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4591 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4593 SetLastError(0xdeadbeef);
4594 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4595 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4596 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4597 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4599 DestroyWindow(hwnd);
4601 hmenu = CreateMenu();
4603 SetLastError(0xdeadbeef);
4604 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4605 0, 0, 100, 100, parent, hmenu, 0, NULL);
4606 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4607 expect_menu(hwnd, hmenu);
4608 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4609 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4610 DestroyWindow(hwnd);
4611 SetLastError(0xdeadbeef);
4612 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4613 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4615 SetLastError(0xdeadbeef);
4616 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4617 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4618 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4619 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4621 DestroyWindow(hwnd);
4623 hmenu = CreateMenu();
4625 SetLastError(0xdeadbeef);
4626 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4627 0, 0, 100, 100, parent, hmenu, 0, NULL);
4628 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4629 expect_menu(hwnd, hmenu);
4630 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4631 expect_ex_style(hwnd, 0);
4632 DestroyWindow(hwnd);
4633 SetLastError(0xdeadbeef);
4634 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4635 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4637 SetLastError(0xdeadbeef);
4638 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4639 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4640 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4641 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4643 DestroyWindow(hwnd);
4645 hmenu = CreateMenu();
4647 SetLastError(0xdeadbeef);
4648 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4649 0, 0, 100, 100, parent, hmenu, 0, NULL);
4650 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4651 expect_menu(hwnd, hmenu);
4652 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4653 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4654 DestroyWindow(hwnd);
4655 SetLastError(0xdeadbeef);
4656 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4657 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4659 /* test child window sizing */
4661 cls.lpfnWndProc = minmax_wnd_proc;
4664 cls.hInstance = GetModuleHandle(0);
4666 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4667 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4668 cls.lpszMenuName = NULL;
4669 cls.lpszClassName = "MinMax_WndClass";
4670 RegisterClass(&cls);
4672 SetLastError(0xdeadbeef);
4673 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4674 0, 0, 100, 100, 0, 0, 0, NULL);
4675 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4676 expect_menu(parent, 0);
4677 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4678 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4680 memset(&minmax, 0, sizeof(minmax));
4681 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4682 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4683 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4684 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4685 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4687 GetWindowRect(parent, &rc);
4688 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4689 GetClientRect(parent, &rc);
4690 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4692 InflateRect(&rc, 200, 200);
4693 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4695 SetLastError(0xdeadbeef);
4696 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4697 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4698 parent, (HMENU)1, 0, NULL);
4699 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4700 expect_menu(hwnd, 1);
4701 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4702 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4704 memset(&minmax, 0, sizeof(minmax));
4705 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4706 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4708 GetWindowRect(hwnd, &rc);
4709 OffsetRect(&rc, -rc.left, -rc.top);
4710 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4711 rc.left, rc.top, rc.right, rc.bottom,
4712 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4713 DestroyWindow(hwnd);
4715 cls.lpfnWndProc = winsizes_wnd_proc;
4716 cls.lpszClassName = "Sizes_WndClass";
4717 RegisterClass(&cls);
4719 expected_cx = expected_cy = 200000;
4720 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4721 broken_rect = expected_rect;
4722 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4723 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4724 GetClientRect( hwnd, &rc );
4725 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4726 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4727 DestroyWindow(hwnd);
4729 expected_cx = expected_cy = -10;
4730 SetRect( &expected_rect, 0, 0, 0, 0 );
4731 SetRect( &broken_rect, 0, 0, -10, -10 );
4732 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4733 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4734 GetClientRect( hwnd, &rc );
4735 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4736 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4737 DestroyWindow(hwnd);
4739 expected_cx = expected_cy = -200000;
4740 SetRect( &expected_rect, 0, 0, 0, 0 );
4741 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4742 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4743 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4744 GetClientRect( hwnd, &rc );
4745 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4746 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4747 DestroyWindow(hwnd);
4749 /* we need a parent at 0,0 so that child coordinates match */
4750 DestroyWindow(parent);
4751 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4752 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4755 expected_cy = 0x7fffffff;
4756 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4757 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4758 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4759 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4760 GetClientRect( hwnd, &rc );
4761 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4762 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4763 DestroyWindow(hwnd);
4765 expected_cx = 0x7fffffff;
4766 expected_cy = 0x7fffffff;
4767 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4768 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4769 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4770 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4771 GetClientRect( hwnd, &rc );
4772 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4773 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4774 DestroyWindow(hwnd);
4776 /* top level window */
4777 expected_cx = expected_cy = 200000;
4778 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4779 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4780 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4781 GetClientRect( hwnd, &rc );
4782 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4783 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4784 DestroyWindow(hwnd);
4786 DestroyWindow(parent);
4788 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4789 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4791 #undef expect_gle_broken_9x
4794 #undef expect_ex_style
4797 /* function that remembers whether the system the test is running on sets the
4798 * last error for user32 functions to make the tests stricter */
4799 static int check_error(DWORD actual, DWORD expected)
4801 static int sets_last_error = -1;
4802 if (sets_last_error == -1)
4803 sets_last_error = (actual != 0xdeadbeef);
4804 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4807 static void test_SetWindowLong(void)
4810 WNDPROC old_window_procW;
4812 SetLastError(0xdeadbeef);
4813 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4814 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4815 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4816 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4818 SetLastError(0xdeadbeef);
4819 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4820 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4821 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4822 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4824 SetLastError(0xdeadbeef);
4825 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4826 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4827 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4828 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4829 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4830 ok((WNDPROC)retval == main_window_procA,
4831 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4832 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4834 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4835 SetLastError(0xdeadbeef);
4836 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4837 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4839 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4840 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4841 ok((WNDPROC)retval == old_window_procW,
4842 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4843 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4845 /* set it back to ANSI */
4846 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4850 static void test_ShowWindow(void)
4857 SetRect(&rcMain, 120, 120, 210, 210);
4859 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4860 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4861 WS_MAXIMIZEBOX | WS_POPUP,
4862 rcMain.left, rcMain.top,
4863 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4867 style = GetWindowLong(hwnd, GWL_STYLE);
4868 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4869 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4870 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4871 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4872 GetWindowRect(hwnd, &rc);
4873 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4874 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4875 rc.left, rc.top, rc.right, rc.bottom);
4877 ret = ShowWindow(hwnd, SW_SHOW);
4878 ok(!ret, "not expected ret: %lu\n", ret);
4879 style = GetWindowLong(hwnd, GWL_STYLE);
4880 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4881 ok(style & WS_VISIBLE, "window should be visible\n");
4882 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4883 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4884 GetWindowRect(hwnd, &rc);
4885 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4886 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4887 rc.left, rc.top, rc.right, rc.bottom);
4889 ret = ShowWindow(hwnd, SW_MINIMIZE);
4890 ok(ret, "not expected ret: %lu\n", ret);
4891 style = GetWindowLong(hwnd, GWL_STYLE);
4892 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4893 ok(style & WS_VISIBLE, "window should be visible\n");
4894 ok(style & WS_MINIMIZE, "window should be minimized\n");
4895 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4896 GetWindowRect(hwnd, &rc);
4897 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4899 ShowWindow(hwnd, SW_RESTORE);
4900 ok(ret, "not expected ret: %lu\n", ret);
4901 style = GetWindowLong(hwnd, GWL_STYLE);
4902 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4903 ok(style & WS_VISIBLE, "window should be visible\n");
4904 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4905 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4906 GetWindowRect(hwnd, &rc);
4907 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4908 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4909 rc.left, rc.top, rc.right, rc.bottom);
4911 ret = EnableWindow(hwnd, FALSE);
4912 ok(!ret, "not expected ret: %lu\n", ret);
4913 style = GetWindowLong(hwnd, GWL_STYLE);
4914 ok(style & WS_DISABLED, "window should be disabled\n");
4916 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4917 ok(!ret, "not expected ret: %lu\n", ret);
4918 style = GetWindowLong(hwnd, GWL_STYLE);
4919 ok(style & WS_DISABLED, "window should be disabled\n");
4920 ok(style & WS_VISIBLE, "window should be visible\n");
4921 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4922 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4923 GetWindowRect(hwnd, &rc);
4924 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4925 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4926 rc.left, rc.top, rc.right, rc.bottom);
4928 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4929 ok(!ret, "not expected ret: %lu\n", ret);
4930 style = GetWindowLong(hwnd, GWL_STYLE);
4931 ok(style & WS_DISABLED, "window should be disabled\n");
4932 ok(style & WS_VISIBLE, "window should be visible\n");
4933 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4934 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4935 GetWindowRect(hwnd, &rc);
4936 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4937 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4938 rc.left, rc.top, rc.right, rc.bottom);
4940 ret = ShowWindow(hwnd, SW_MINIMIZE);
4941 ok(ret, "not expected ret: %lu\n", ret);
4942 style = GetWindowLong(hwnd, GWL_STYLE);
4943 ok(style & WS_DISABLED, "window should be disabled\n");
4944 ok(style & WS_VISIBLE, "window should be visible\n");
4945 ok(style & WS_MINIMIZE, "window should be minimized\n");
4946 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4947 GetWindowRect(hwnd, &rc);
4948 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4950 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4951 ok(!ret, "not expected ret: %lu\n", ret);
4952 style = GetWindowLong(hwnd, GWL_STYLE);
4953 ok(style & WS_DISABLED, "window should be disabled\n");
4954 ok(style & WS_VISIBLE, "window should be visible\n");
4955 ok(style & WS_MINIMIZE, "window should be minimized\n");
4956 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4957 GetWindowRect(hwnd, &rc);
4958 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4960 ret = ShowWindow(hwnd, SW_RESTORE);
4961 ok(ret, "not expected ret: %lu\n", ret);
4962 style = GetWindowLong(hwnd, GWL_STYLE);
4963 ok(style & WS_DISABLED, "window should be disabled\n");
4964 ok(style & WS_VISIBLE, "window should be visible\n");
4965 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4966 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4967 GetWindowRect(hwnd, &rc);
4968 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4969 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4970 rc.left, rc.top, rc.right, rc.bottom);
4972 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4973 ok(!ret, "not expected ret: %lu\n", ret);
4974 ok(IsWindow(hwnd), "window should exist\n");
4976 ret = EnableWindow(hwnd, TRUE);
4977 ok(ret, "not expected ret: %lu\n", ret);
4979 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4980 ok(!ret, "not expected ret: %lu\n", ret);
4981 ok(!IsWindow(hwnd), "window should not exist\n");
4984 static void test_gettext(void)
4987 LPCSTR clsname = "gettexttest";
4991 memset( &cls, 0, sizeof cls );
4992 cls.lpfnWndProc = DefWindowProc;
4993 cls.lpszClassName = clsname;
4994 cls.hInstance = GetModuleHandle(NULL);
4996 if (!RegisterClass( &cls )) return;
4998 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4999 ok( hwnd != NULL, "window was null\n");
5001 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5002 ok( r == 0, "settext should return zero\n");
5004 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5005 ok( r == 0, "settext should return zero (%ld)\n", r);
5007 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5008 ok( r == 0, "settext should return zero (%ld)\n", r);
5010 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5011 ok( r == 0, "settext should return zero (%ld)\n", r);
5013 DestroyWindow(hwnd);
5014 UnregisterClass( clsname, NULL );
5018 static void test_GetUpdateRect(void)
5021 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5023 HWND hgrandparent, hparent, hchild;
5025 static const char classNameA[] = "GetUpdateRectClass";
5027 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5028 0, 0, 100, 100, NULL, NULL, 0, NULL);
5030 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5031 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5033 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5034 10, 10, 30, 30, hparent, NULL, 0, NULL);
5036 ShowWindow(hgrandparent, SW_SHOW);
5037 UpdateWindow(hgrandparent);
5038 flush_events( TRUE );
5040 ShowWindow(hchild, SW_HIDE);
5041 SetRect(&rc2, 0, 0, 0, 0);
5042 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5043 ok(!ret, "GetUpdateRect returned not empty region\n");
5044 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5045 rc1.left, rc1.top, rc1.right, rc1.bottom,
5046 rc2.left, rc2.top, rc2.right, rc2.bottom);
5048 SetRect(&rc2, 10, 10, 40, 40);
5049 ret = GetUpdateRect(hparent, &rc1, FALSE);
5050 ok(ret, "GetUpdateRect returned empty region\n");
5051 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5052 rc1.left, rc1.top, rc1.right, rc1.bottom,
5053 rc2.left, rc2.top, rc2.right, rc2.bottom);
5055 parent_wm_paint = FALSE;
5056 grandparent_wm_paint = FALSE;
5057 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5059 if (msg.message == WM_PAINT)
5061 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5062 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5064 DispatchMessage(&msg);
5066 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5067 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5069 DestroyWindow(hgrandparent);
5072 cls.lpfnWndProc = DefWindowProcA;
5075 cls.hInstance = GetModuleHandleA(0);
5077 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5078 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5079 cls.lpszMenuName = NULL;
5080 cls.lpszClassName = classNameA;
5082 if(!RegisterClassA(&cls)) {
5083 trace("Register failed %d\n", GetLastError());
5087 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5088 0, 0, 100, 100, NULL, NULL, 0, NULL);
5090 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5091 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5093 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5094 10, 10, 30, 30, hparent, NULL, 0, NULL);
5096 ShowWindow(hgrandparent, SW_SHOW);
5097 UpdateWindow(hgrandparent);
5098 flush_events( TRUE );
5100 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5101 ok(!ret, "GetUpdateRect returned not empty region\n");
5103 ShowWindow(hchild, SW_HIDE);
5105 SetRect(&rc2, 0, 0, 0, 0);
5106 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5107 ok(!ret, "GetUpdateRect returned not empty region\n");
5108 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5109 rc1.left, rc1.top, rc1.right, rc1.bottom,
5110 rc2.left, rc2.top, rc2.right, rc2.bottom);
5112 SetRect(&rc2, 10, 10, 40, 40);
5113 ret = GetUpdateRect(hparent, &rc1, FALSE);
5114 ok(ret, "GetUpdateRect returned empty region\n");
5115 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5116 rc1.left, rc1.top, rc1.right, rc1.bottom,
5117 rc2.left, rc2.top, rc2.right, rc2.bottom);
5119 parent_wm_paint = FALSE;
5120 grandparent_wm_paint = FALSE;
5121 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5123 if (msg.message == WM_PAINT)
5125 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5126 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5128 DispatchMessage(&msg);
5130 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5131 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5133 DestroyWindow(hgrandparent);
5137 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5145 const int waitTime = 2000;
5147 BeginPaint(hwnd, &ps);
5149 /* create and destroy window to create an exposed region on this window */
5150 win = CreateWindowA("static", "win", WS_VISIBLE,
5151 10,10,50,50, NULL, NULL, 0, NULL);
5154 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5156 ValidateRect(hwnd, NULL);
5157 EndPaint(hwnd, &ps);
5159 if(waitResult != WAIT_TIMEOUT)
5161 GetUpdateRect(hwnd, &updateRect, FALSE);
5162 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5167 return DefWindowProc(hwnd, msg, wParam, lParam);
5170 static void test_Expose(void)
5175 memset(&cls, 0, sizeof(WNDCLASSA));
5176 cls.lpfnWndProc = TestExposedRegion_WndProc;
5177 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5178 cls.lpszClassName = "TestExposeClass";
5179 atom = RegisterClassA(&cls);
5181 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5182 0, 0, 200, 100, NULL, NULL, 0, NULL);
5188 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5190 static UINT ncredrawflags;
5196 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5199 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5202 BeginPaint(hwnd, &ps);
5203 EndPaint(hwnd, &ps);
5206 return DefWindowProc(hwnd, msg, wParam, lParam);
5209 static void run_NCRedrawLoop(UINT flags)
5216 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5217 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5218 NULL, NULL, 0, &flags);
5219 ShowWindow(hwnd, SW_SHOW);
5221 flush_events( FALSE );
5222 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5224 if (msg.message == WM_PAINT) loopcount++;
5225 if (loopcount >= 100) break;
5226 TranslateMessage(&msg);
5227 DispatchMessage(&msg);
5228 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5230 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5231 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5233 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5234 DestroyWindow(hwnd);
5237 static void test_NCRedraw(void)
5241 wndclass.lpszClassName = "TestNCRedrawClass";
5242 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5243 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5244 wndclass.cbClsExtra = 0;
5245 wndclass.cbWndExtra = 0;
5246 wndclass.hInstance = 0;
5247 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5248 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5249 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5250 wndclass.lpszMenuName = NULL;
5252 RegisterClassA(&wndclass);
5254 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5255 run_NCRedrawLoop(RDW_INVALIDATE);
5258 static void test_GetWindowModuleFileName(void)
5263 char buf1[MAX_PATH], buf2[MAX_PATH];
5265 if (!pGetWindowModuleFileNameA)
5267 win_skip("GetWindowModuleFileNameA is not available\n");
5271 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5274 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5275 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5278 SetLastError(0xdeadbeef);
5279 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5280 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5283 SetLastError(0xdeadbeef);
5284 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5285 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5286 "GetWindowModuleFileNameA error %u\n", GetLastError());
5290 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5291 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5293 hinst = GetModuleHandle(0);
5295 SetLastError(0xdeadbeef);
5296 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5297 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5298 "expected %u, got %u\n", ret1 - 2, ret2);
5299 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5300 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5301 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5303 SetLastError(0xdeadbeef);
5304 ret2 = GetModuleFileName(hinst, buf2, 0);
5305 ok(!ret2, "GetModuleFileName should return 0\n");
5306 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5307 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5308 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5310 SetLastError(0xdeadbeef);
5311 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5312 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5313 "expected %u, got %u\n", ret1 - 2, ret2);
5314 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5315 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5316 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5318 SetLastError(0xdeadbeef);
5319 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5320 ok(!ret2, "expected 0, got %u\n", ret2);
5321 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5322 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5323 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5325 DestroyWindow(hwnd);
5328 hwnd = (HWND)0xdeadbeef;
5329 SetLastError(0xdeadbeef);
5330 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5331 ok(!ret1, "expected 0, got %u\n", ret1);
5332 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5333 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5335 hwnd = FindWindow("Shell_TrayWnd", NULL);
5336 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5337 SetLastError(0xdeadbeef);
5338 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5339 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5341 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5343 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5344 hwnd = GetDesktopWindow();
5345 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5346 SetLastError(0xdeadbeef);
5347 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5349 ret1 == ret2 || /* vista */
5350 broken(ret2), /* some win98 return user.exe as file name */
5351 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5355 static void test_hwnd_message(void)
5357 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5358 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5360 HWND parent = 0, hwnd, found;
5363 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5364 on CreateWindowExA and crash later in the test.
5365 Use UNICODE here to fail on win9x */
5366 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5367 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5370 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5374 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5378 HWND root, desktop = GetDesktopWindow();
5380 parent = pGetAncestor(hwnd, GA_PARENT);
5381 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5382 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5383 root = pGetAncestor(hwnd, GA_ROOT);
5384 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5385 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5386 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5387 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5388 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5389 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5390 GetWindowRect( parent, &rect );
5391 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5392 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5394 GetWindowRect( hwnd, &rect );
5395 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5396 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5398 /* test FindWindow behavior */
5400 found = FindWindowExA( 0, 0, 0, "message window" );
5401 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5402 SetLastError(0xdeadbeef);
5403 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5404 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5405 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5408 found = FindWindowExA( parent, 0, 0, "message window" );
5409 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5412 /* test IsChild behavior */
5414 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5416 /* test IsWindowVisible behavior */
5418 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5419 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5421 DestroyWindow(hwnd);
5424 static void test_layered_window(void)
5432 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5434 win_skip( "layered windows not supported\n" );
5437 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5438 100, 100, 200, 200, 0, 0, 0, NULL);
5440 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5441 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5442 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5443 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5444 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5445 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5446 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5447 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5448 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5449 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5450 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5451 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5452 ok( alpha == 44, "wrong alpha %u\n", alpha );
5453 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5455 /* clearing WS_EX_LAYERED resets attributes */
5456 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5457 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5458 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5459 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5460 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5461 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5462 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5463 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5464 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5465 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5466 ok( key == 0x654321, "wrong color key %x\n", key );
5467 ok( alpha == 22, "wrong alpha %u\n", alpha );
5468 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5470 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5471 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5473 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5474 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5475 ok( key == 0x888888, "wrong color key %x\n", key );
5476 /* alpha not changed on vista if LWA_ALPHA is not set */
5477 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5478 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5480 /* color key may or may not be changed without LWA_COLORKEY */
5481 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5482 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5484 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5485 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5486 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5487 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5488 ok( flags == 0, "wrong flags %x\n", flags );
5490 /* default alpha and color key is 0 */
5491 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5492 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5493 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5494 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5495 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5496 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5497 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5498 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5499 ok( flags == 0, "wrong flags %x\n", flags );
5501 DestroyWindow( hwnd );
5504 static MONITORINFO mi;
5506 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5512 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5513 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5514 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5515 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5516 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5517 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5518 cs->x, cs->y, cs->cx, cs->cy);
5521 case WM_GETMINMAXINFO:
5523 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5524 dump_minmax_info(minmax);
5525 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5526 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5527 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5528 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5532 return DefWindowProc(hwnd, msg, wp, lp);
5535 static void test_fullscreen(void)
5537 static const DWORD t_style[] = {
5538 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5540 static const DWORD t_ex_style[] = {
5541 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5551 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5553 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5558 SetLastError(0xdeadbeef);
5559 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5560 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5562 mi.cbSize = sizeof(mi);
5563 SetLastError(0xdeadbeef);
5564 ret = pGetMonitorInfoA(hmon, &mi);
5565 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5566 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5567 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5568 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5571 cls.lpfnWndProc = fullscreen_wnd_proc;
5574 cls.hInstance = GetModuleHandle(0);
5576 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5577 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5578 cls.lpszMenuName = NULL;
5579 cls.lpszClassName = "fullscreen_class";
5580 RegisterClass(&cls);
5582 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5584 DWORD style, ex_style;
5586 /* avoid a WM interaction */
5587 assert(!(t_style[i] & WS_VISIBLE));
5589 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5594 ex_style = t_ex_style[j];
5596 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5597 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5598 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5599 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5600 GetWindowRect(hwnd, &rc);
5601 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5602 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5603 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5604 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5605 DestroyWindow(hwnd);
5607 style = t_style[i] | WS_MAXIMIZE;
5608 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5609 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5610 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5611 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5612 GetWindowRect(hwnd, &rc);
5613 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5614 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5615 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5616 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5617 DestroyWindow(hwnd);
5619 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5620 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5621 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5622 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5623 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5624 GetWindowRect(hwnd, &rc);
5625 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5626 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5627 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5628 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5629 DestroyWindow(hwnd);
5631 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5632 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5633 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5634 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5635 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5636 GetWindowRect(hwnd, &rc);
5637 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5638 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5639 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5640 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5641 DestroyWindow(hwnd);
5643 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5644 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5645 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5646 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5647 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5648 GetWindowRect(hwnd, &rc);
5649 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5650 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5651 fixup = min(abs(rc.left), abs(rc.top));
5652 InflateRect(&rc, -fixup, -fixup);
5653 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5654 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5655 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5656 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5657 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5658 DestroyWindow(hwnd);
5660 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5661 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5662 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5663 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5664 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5665 GetWindowRect(hwnd, &rc);
5666 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5667 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5668 fixup = min(abs(rc.left), abs(rc.top));
5669 InflateRect(&rc, -fixup, -fixup);
5670 if (style & (WS_CHILD | WS_POPUP))
5671 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5672 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5673 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5675 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5676 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5677 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5678 DestroyWindow(hwnd);
5682 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5685 static BOOL test_thick_child_got_minmax;
5686 static const char * test_thick_child_name;
5687 static LONG test_thick_child_style;
5688 static LONG test_thick_child_exStyle;
5690 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5693 int expectedMinTrackX;
5694 int expectedMinTrackY;
5695 int actualMinTrackX;
5696 int actualMinTrackY;
5697 int expectedMaxTrackX;
5698 int expectedMaxTrackY;
5699 int actualMaxTrackX;
5700 int actualMaxTrackY;
5701 int expectedMaxSizeX;
5702 int expectedMaxSizeY;
5713 case WM_GETMINMAXINFO:
5715 minmax = (MINMAXINFO *)lparam;
5716 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5717 dump_minmax_info( minmax );
5719 test_thick_child_got_minmax = TRUE;
5722 adjustedStyle = test_thick_child_style;
5723 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5724 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5725 GetClientRect(GetParent(hwnd), &rect);
5726 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5728 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5730 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5731 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5735 expectedMinTrackX = -2 * rect.left;
5736 expectedMinTrackY = -2 * rect.top;
5738 actualMinTrackX = minmax->ptMinTrackSize.x;
5739 actualMinTrackY = minmax->ptMinTrackSize.y;
5741 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5742 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5743 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5744 test_thick_child_name);
5746 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5747 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5748 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5749 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5750 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5751 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5752 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5753 test_thick_child_name);
5755 expectedMaxSizeX = rect.right - rect.left;
5756 expectedMaxSizeY = rect.bottom - rect.top;
5757 actualMaxSizeX = minmax->ptMaxSize.x;
5758 actualMaxSizeY = minmax->ptMaxSize.y;
5760 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5761 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5762 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5763 test_thick_child_name);
5766 expectedPosX = rect.left;
5767 expectedPosY = rect.top;
5768 actualPosX = minmax->ptMaxPosition.x;
5769 actualPosY = minmax->ptMaxPosition.y;
5770 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5771 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5772 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5778 return DefWindowProcA(hwnd, msg, wparam, lparam);
5781 #define NUMBER_OF_THICK_CHILD_TESTS 16
5782 static void test_thick_child_size(HWND parentWindow)
5786 RECT adjustedParentRect;
5791 LONG expectedHeight;
5793 LPCTSTR className = "THICK_CHILD_CLASS";
5796 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5797 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5798 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5799 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5800 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5801 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5802 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5803 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5804 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5805 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5806 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5807 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5808 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5809 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5810 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5811 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5812 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5815 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5820 WS_EX_DLGMODALFRAME,
5821 WS_EX_DLGMODALFRAME,
5822 WS_EX_DLGMODALFRAME,
5823 WS_EX_DLGMODALFRAME,
5828 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5829 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5830 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5831 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5833 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5834 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5835 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5836 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5837 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5838 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5839 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5840 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5841 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5842 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5843 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5844 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5845 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5846 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5847 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5848 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5849 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5853 cls.lpfnWndProc = test_thick_child_size_winproc;
5856 cls.hInstance = GetModuleHandleA(0);
5858 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5859 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5860 cls.lpszMenuName = NULL;
5861 cls.lpszClassName = className;
5862 SetLastError(0xdeadbeef);
5863 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5865 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5867 test_thick_child_name = styleName[i];
5868 test_thick_child_style = styles[i];
5869 test_thick_child_exStyle = exStyles[i];
5870 test_thick_child_got_minmax = FALSE;
5872 SetLastError(0xdeadbeef);
5873 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5874 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5876 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5878 SetLastError(0xdeadbeef);
5879 success = GetWindowRect(childWindow, &childRect);
5880 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5881 childWidth = childRect.right - childRect.left;
5882 childHeight = childRect.bottom - childRect.top;
5884 adjustedStyle = styles[i];
5885 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5886 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5887 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5888 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5891 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5893 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5894 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5898 expectedWidth = -2 * adjustedParentRect.left;
5899 expectedHeight = -2 * adjustedParentRect.top;
5902 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5903 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5904 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5906 SetLastError(0xdeadbeef);
5907 success = DestroyWindow(childWindow);
5908 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5910 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5913 static void test_handles( HWND full_hwnd )
5915 HWND hwnd = full_hwnd;
5919 SetLastError( 0xdeadbeef );
5920 ret = GetWindowRect( hwnd, &rect );
5921 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5924 if ((ULONG_PTR)full_hwnd >> 32)
5925 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5927 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5928 SetLastError( 0xdeadbeef );
5929 ret = GetWindowRect( hwnd, &rect );
5930 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5932 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5933 SetLastError( 0xdeadbeef );
5934 ret = GetWindowRect( hwnd, &rect );
5935 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5937 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5938 SetLastError( 0xdeadbeef );
5939 ret = GetWindowRect( hwnd, &rect );
5940 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5941 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5943 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5944 SetLastError( 0xdeadbeef );
5945 ret = GetWindowRect( hwnd, &rect );
5946 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5947 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5951 static void test_winregion(void)
5958 if (!pGetWindowRgnBox)
5960 win_skip("GetWindowRgnBox not supported\n");
5964 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
5966 SetLastError(0xdeadbeef);
5967 ret = pGetWindowRgnBox(hwnd, NULL);
5968 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5969 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5971 hrgn = CreateRectRgn(2, 3, 10, 15);
5972 ok( hrgn != NULL, "Region creation failed\n");
5975 SetWindowRgn(hwnd, hrgn, FALSE);
5977 SetLastError(0xdeadbeef);
5978 ret = pGetWindowRgnBox(hwnd, NULL);
5979 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5980 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5982 r.left = r.top = r.right = r.bottom = 0;
5983 ret = pGetWindowRgnBox(hwnd, &r);
5984 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
5985 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
5986 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
5990 DestroyWindow(hwnd);
5995 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5996 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5997 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5998 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5999 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
6000 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
6001 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
6002 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
6003 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
6004 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
6006 if (!RegisterWindowClasses()) assert(0);
6008 SetLastError(0xdeafbeef);
6009 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
6010 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
6012 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
6013 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
6015 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
6016 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6017 WS_MAXIMIZEBOX | WS_POPUP,
6019 0, 0, GetModuleHandle(0), NULL);
6020 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
6021 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6022 WS_MAXIMIZEBOX | WS_POPUP,
6024 0, 0, GetModuleHandle(0), NULL);
6026 assert( hwndMain2 );
6028 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
6030 /* Add the tests below this line */
6031 test_thick_child_size(hwndMain);
6033 test_hwnd_message();
6034 test_nonclient_area(hwndMain);
6036 test_GetWindowModuleFileName();
6039 test_capture_3(hwndMain, hwndMain2);
6042 test_CreateWindow();
6043 test_parent_owner();
6045 test_enum_thread_windows();
6049 test_SetWindowPos(hwndMain);
6050 test_SetMenu(hwndMain);
6051 test_SetFocus(hwndMain);
6052 test_SetActiveWindow(hwndMain);
6055 test_children_zorder(hwndMain);
6056 test_popup_zorder(hwndMain2, hwndMain);
6057 test_keyboard_input(hwndMain);
6058 test_mouse_input(hwndMain);
6059 test_validatergn(hwndMain);
6060 test_nccalcscroll( hwndMain);
6061 test_scrollwindow( hwndMain);
6062 test_scrollvalidate( hwndMain);
6063 test_scrolldc( hwndMain);
6065 test_IsWindowUnicode();
6066 test_vis_rgn(hwndMain);
6068 test_AdjustWindowRect();
6069 test_window_styles();
6072 test_SetWindowLong();
6074 if (0) test_gettext(); /* crashes on NT4 */
6075 test_GetUpdateRect();
6077 test_layered_window();
6079 test_SetForegroundWindow(hwndMain);
6080 test_shell_window();
6081 test_handles( hwndMain );
6084 /* add the tests above this line */
6085 if (hhook) UnhookWindowsHookEx(hhook);
6087 DestroyWindow(hwndMain2);
6088 DestroyWindow(hwndMain);