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 );
451 ShowWindow( test, SW_SHOW );
452 ret = SetParent( test, test );
453 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
454 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
455 check_parents( test, child, child, 0, 0, hwndMain, test );
456 DestroyWindow( test );
459 test = create_tool_window( WS_POPUP, hwndMain2 );
460 trace( "created owned popup %p\n", test );
462 ret = SetParent( test, child );
463 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
464 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
466 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
467 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
468 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
469 DestroyWindow( test );
471 /**************** test owner destruction *******************/
473 /* owned child popup */
474 owner = create_tool_window( 0, 0 );
475 test = create_tool_window( WS_POPUP, owner );
476 trace( "created owner %p and popup %p\n", owner, test );
477 ret = SetParent( test, child );
478 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
479 check_parents( test, child, child, owner, owner, hwndMain, owner );
480 /* window is now child of 'child' but owned by 'owner' */
481 DestroyWindow( owner );
482 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
483 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
484 * while Win95, Win2k, WinXP do.
486 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
487 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
490 /* owned top-level popup */
491 owner = create_tool_window( 0, 0 );
492 test = create_tool_window( WS_POPUP, owner );
493 trace( "created owner %p and popup %p\n", owner, test );
494 check_parents( test, desktop, owner, owner, owner, test, owner );
495 DestroyWindow( owner );
496 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
498 /* top-level popup owned by child */
499 owner = create_tool_window( WS_CHILD, hwndMain2 );
500 test = create_tool_window( WS_POPUP, 0 );
501 trace( "created owner %p and popup %p\n", owner, test );
502 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
503 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
504 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
505 DestroyWindow( owner );
506 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
507 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
508 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
509 * while Win95, Win2k, WinXP do.
511 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
515 DestroyWindow(child);
518 owner = create_tool_window( WS_OVERLAPPED, 0 );
519 test = create_tool_window( WS_POPUP, desktop );
521 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
523 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
524 "EnumChildWindows should have returned FALSE\n" );
525 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
527 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
528 ret = SetParent( test, owner );
529 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
532 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
533 "EnumChildWindows should have returned TRUE\n" );
534 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
536 child = create_tool_window( WS_CHILD, owner );
538 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
539 "EnumChildWindows should have returned FALSE\n" );
540 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
541 DestroyWindow( child );
543 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
544 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
546 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
547 "EnumChildWindows should have returned TRUE\n" );
548 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
550 ret = SetParent( child, owner );
551 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
552 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
554 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
555 "EnumChildWindows should have returned FALSE\n" );
556 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
558 ret = SetParent( child, NULL );
559 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
560 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
562 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
563 "EnumChildWindows should have returned TRUE\n" );
564 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
566 /* even GW_OWNER == owner it's still a desktop's child */
567 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
568 "EnumChildWindows should have found %p and returned FALSE\n", child );
570 DestroyWindow( child );
571 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
573 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
574 "EnumChildWindows should have found %p and returned FALSE\n", child );
576 DestroyWindow( child );
577 DestroyWindow( test );
578 DestroyWindow( owner );
581 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
584 if (*(LPINT)lParam > 2) return FALSE;
587 static DWORD CALLBACK enum_thread( void *arg )
594 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
597 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
598 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
599 ok( count == 0, "count should be 0 got %d\n", count );
601 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
602 0, 0, 100, 100, 0, 0, 0, NULL );
604 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
605 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
606 if (count != 2) /* Vista gives us two windows for the price of one */
608 ok( count == 1, "count should be 1 got %d\n", count );
609 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
610 0, 0, 100, 100, 0, 0, 0, NULL );
614 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
615 0, 0, 100, 100, 0, 0, 0, NULL );
617 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
618 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
619 ok( count == 3, "count should be 3 got %d\n", count );
621 if (hwnd[2]) DestroyWindow(hwnd[2]);
622 DestroyWindow(hwnd[1]);
623 DestroyWindow(hwnd[0]);
627 /* test EnumThreadWindows in a separate thread */
628 static void test_enum_thread_windows(void)
631 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
632 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
633 CloseHandle( handle );
636 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
640 case WM_GETMINMAXINFO:
642 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
644 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
645 dump_minmax_info( minmax );
646 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
649 case WM_WINDOWPOSCHANGING:
651 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
652 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
653 winpos->hwnd, winpos->hwndInsertAfter,
654 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
655 if (!(winpos->flags & SWP_NOMOVE))
657 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
658 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
660 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
661 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
663 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
664 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
668 case WM_WINDOWPOSCHANGED:
671 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
672 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
673 winpos->hwnd, winpos->hwndInsertAfter,
674 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
675 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
676 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
678 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
679 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
681 GetWindowRect(hwnd, &rc1);
682 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
683 /* note: winpos coordinates are relative to parent */
684 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
687 /* Uncomment this once the test succeeds in all cases */
688 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
689 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
691 GetClientRect(hwnd, &rc2);
692 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
693 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
694 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
695 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
701 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
702 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
704 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
705 if (got_getminmaxinfo)
706 trace("%p got WM_GETMINMAXINFO\n", hwnd);
708 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
709 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
711 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
715 if (test_lbuttondown_flag)
717 ShowWindow((HWND)wparam, SW_SHOW);
718 flush_events( FALSE );
723 return DefWindowProcA(hwnd, msg, wparam, lparam);
726 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
730 case WM_GETMINMAXINFO:
732 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
734 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
735 dump_minmax_info( minmax );
736 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
741 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
742 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
744 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
745 if (got_getminmaxinfo)
746 trace("%p got WM_GETMINMAXINFO\n", hwnd);
748 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
749 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
751 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
756 return DefWindowProcA(hwnd, msg, wparam, lparam);
759 static BOOL RegisterWindowClasses(void)
763 cls.style = CS_DBLCLKS;
764 cls.lpfnWndProc = main_window_procA;
767 cls.hInstance = GetModuleHandleA(0);
769 cls.hCursor = LoadCursorA(0, IDC_ARROW);
770 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
771 cls.lpszMenuName = NULL;
772 cls.lpszClassName = "MainWindowClass";
774 if(!RegisterClassA(&cls)) return FALSE;
777 cls.lpfnWndProc = tool_window_procA;
780 cls.hInstance = GetModuleHandleA(0);
782 cls.hCursor = LoadCursorA(0, IDC_ARROW);
783 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
784 cls.lpszMenuName = NULL;
785 cls.lpszClassName = "ToolWindowClass";
787 if(!RegisterClassA(&cls)) return FALSE;
792 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
794 RECT rcWindow, rcClient;
797 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
799 GetWindowRect(hwnd, &rcWindow);
800 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
802 GetClientRect(hwnd, &rcClient);
803 /* translate to screen coordinates */
804 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
805 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
807 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
808 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
809 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
810 /* Windows reports some undocumented exstyles in WINDOWINFO, but
811 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
813 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
814 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
815 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
816 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
817 if (GetForegroundWindow())
818 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
819 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
821 /* win2k and XP return broken border info in GetWindowInfo most of
822 * the time, so there is no point in testing it.
826 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
827 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
828 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
829 ok(info->cyWindowBorders == border,
830 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
832 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
834 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
835 info->wCreatorVersion == 0x0500 /* Vista */,
836 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
839 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
841 AdjustWindowRectEx(rc, style, menu, exstyle);
842 /* AdjustWindowRectEx does not include scroll bars */
843 if (style & WS_VSCROLL)
845 if(exstyle & WS_EX_LEFTSCROLLBAR)
846 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
848 rc->right += GetSystemMetrics(SM_CXVSCROLL);
850 if (style & WS_HSCROLL)
851 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
854 static void test_nonclient_area(HWND hwnd)
856 DWORD style, exstyle;
857 RECT rc_window, rc_client, rc;
861 style = GetWindowLongA(hwnd, GWL_STYLE);
862 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
863 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
865 GetWindowRect(hwnd, &rc_window);
866 GetClientRect(hwnd, &rc_client);
868 /* avoid some cases when things go wrong */
869 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
870 rc_window.right > 32768 || rc_window.bottom > 32768) return;
872 CopyRect(&rc, &rc_client);
873 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
874 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
876 ok(EqualRect(&rc, &rc_window),
877 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
878 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
879 rc.left, rc.top, rc.right, rc.bottom);
882 CopyRect(&rc, &rc_window);
883 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
884 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
885 ok(EqualRect(&rc, &rc_client),
886 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
887 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
888 rc.left, rc.top, rc.right, rc.bottom);
890 /* NULL rectangle shouldn't crash */
891 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
892 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
894 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
898 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
899 SetRect(&rc_client, 0, 0, 250, 150);
900 CopyRect(&rc_window, &rc_client);
901 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
902 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
904 CopyRect(&rc, &rc_window);
905 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
906 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
907 ok(EqualRect(&rc, &rc_client),
908 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
909 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
910 rc.left, rc.top, rc.right, rc.bottom);
913 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
915 static const char *CBT_code_name[10] = {
926 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
927 HWND hwnd = (HWND)wParam;
933 static const RECT rc_null;
936 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
937 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
938 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
939 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
944 info.cbSize = sizeof(WINDOWINFO);
945 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
946 verify_window_info(code_name, hwnd, &info);
949 /* WS_VISIBLE should be turned off yet */
950 style = createwnd->lpcs->style & ~WS_VISIBLE;
951 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
952 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
953 GetWindowLongA(hwnd, GWL_STYLE), style);
957 /* Uncomment this once the test succeeds in all cases */
958 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
960 ok(GetParent(hwnd) == hwndMessage,
961 "wrong result from GetParent %p: message window %p\n",
962 GetParent(hwnd), hwndMessage);
965 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
967 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
971 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
972 * Win9x still has them set to 0.
974 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
975 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
977 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
978 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
982 /* Uncomment this once the test succeeds in all cases */
985 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
986 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
987 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
989 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
990 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
991 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
993 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
994 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
997 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
998 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
999 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1000 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1008 if (pGetWindowInfo && IsWindow(hwnd))
1012 /* Win98 actually does check the info.cbSize and doesn't allow
1013 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1014 * WinXP do not check it at all.
1016 info.cbSize = sizeof(WINDOWINFO);
1017 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1018 verify_window_info(code_name, hwnd, &info);
1021 /* on HCBT_DESTROYWND window state is undefined */
1022 case HCBT_DESTROYWND:
1023 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
1029 return CallNextHookEx(hhook, nCode, wParam, lParam);
1032 static void test_shell_window(void)
1036 HMODULE hinst, hUser32;
1037 BOOL (WINAPI*SetShellWindow)(HWND);
1038 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
1039 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1040 HWND shellWindow, nextWnd;
1044 win_skip("Skipping shell window test on Win9x\n");
1048 shellWindow = GetShellWindow();
1049 hinst = GetModuleHandle(0);
1050 hUser32 = GetModuleHandleA("user32");
1052 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1053 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
1055 trace("previous shell window: %p\n", shellWindow);
1061 GetWindowThreadProcessId(shellWindow, &pid);
1062 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1065 skip( "cannot get access to shell process\n" );
1069 SetLastError(0xdeadbeef);
1070 ret = DestroyWindow(shellWindow);
1071 error = GetLastError();
1073 ok(!ret, "DestroyWindow(shellWindow)\n");
1074 /* passes on Win XP, but not on Win98 */
1075 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1076 "got %u after DestroyWindow(shellWindow)\n", error);
1078 /* close old shell instance */
1079 ret = TerminateProcess(hProcess, 0);
1080 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1081 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1082 CloseHandle(hProcess);
1085 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1086 trace("created window 1: %p\n", hwnd1);
1088 ret = SetShellWindow(hwnd1);
1089 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1090 shellWindow = GetShellWindow();
1091 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1093 ret = SetShellWindow(hwnd1);
1094 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1096 ret = SetShellWindow(0);
1097 error = GetLastError();
1098 /* passes on Win XP, but not on Win98
1099 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1100 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1102 ret = SetShellWindow(hwnd1);
1103 /* passes on Win XP, but not on Win98
1104 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1106 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1107 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1108 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1110 ret = DestroyWindow(hwnd1);
1111 ok(ret, "DestroyWindow(hwnd1)\n");
1113 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1114 trace("created window 2: %p\n", hwnd2);
1115 ret = SetShellWindow(hwnd2);
1116 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1118 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1119 trace("created window 3: %p\n", hwnd3);
1121 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1122 trace("created window 4: %p\n", hwnd4);
1124 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1125 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1127 ret = SetShellWindow(hwnd4);
1128 ok(ret, "SetShellWindow(hwnd4)\n");
1129 shellWindow = GetShellWindow();
1130 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1132 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1133 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1135 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1136 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1138 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1139 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1141 ret = SetShellWindow(hwnd3);
1142 ok(!ret, "SetShellWindow(hwnd3)\n");
1143 shellWindow = GetShellWindow();
1144 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1146 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1147 trace("created window 5: %p\n", hwnd5);
1148 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1149 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1153 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1154 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1157 /* destroy test windows */
1158 DestroyWindow(hwnd2);
1159 DestroyWindow(hwnd3);
1160 DestroyWindow(hwnd4);
1161 DestroyWindow(hwnd5);
1164 /************** MDI test ****************/
1166 static char mdi_lParam_test_message[] = "just a test string";
1168 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1170 MDICREATESTRUCTA mdi_cs;
1173 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1174 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1175 BOOL isWin9x = FALSE;
1177 mdi_cs.szClass = "MDI_child_Class_1";
1178 mdi_cs.szTitle = "MDI child";
1179 mdi_cs.hOwner = GetModuleHandle(0);
1180 mdi_cs.x = CW_USEDEFAULT;
1181 mdi_cs.y = CW_USEDEFAULT;
1182 mdi_cs.cx = CW_USEDEFAULT;
1183 mdi_cs.cy = CW_USEDEFAULT;
1185 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1186 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1187 ok(mdi_child != 0, "MDI child creation failed\n");
1188 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1189 ok(id == first_id, "wrong child id %ld\n", id);
1190 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1191 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1193 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1194 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1195 ok(mdi_child != 0, "MDI child creation failed\n");
1196 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1197 ok(id == first_id, "wrong child id %ld\n", id);
1198 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1199 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1201 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1202 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1203 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1205 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1209 ok(mdi_child != 0, "MDI child creation failed\n");
1210 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1211 ok(id == first_id, "wrong child id %ld\n", id);
1212 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1213 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1216 /* test MDICREATESTRUCT A<->W mapping */
1217 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1219 mdi_cs.szClass = (LPCSTR)classW;
1220 mdi_cs.szTitle = (LPCSTR)titleW;
1221 SetLastError(0xdeadbeef);
1222 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1225 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1228 ok(mdi_child != 0, "MDI child creation failed\n");
1232 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1233 ok(id == first_id, "wrong child id %ld\n", id);
1234 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1235 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1238 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1240 CW_USEDEFAULT, CW_USEDEFAULT,
1241 CW_USEDEFAULT, CW_USEDEFAULT,
1242 mdi_client, GetModuleHandle(0),
1243 (LPARAM)mdi_lParam_test_message);
1244 ok(mdi_child != 0, "MDI child creation failed\n");
1245 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1246 ok(id == first_id, "wrong child id %ld\n", id);
1247 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1248 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1250 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1251 0x7fffffff, /* without WS_POPUP */
1252 CW_USEDEFAULT, CW_USEDEFAULT,
1253 CW_USEDEFAULT, CW_USEDEFAULT,
1254 mdi_client, GetModuleHandle(0),
1255 (LPARAM)mdi_lParam_test_message);
1256 ok(mdi_child != 0, "MDI child creation failed\n");
1257 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1258 ok(id == first_id, "wrong child id %ld\n", id);
1259 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1260 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1262 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1263 0xffffffff, /* with WS_POPUP */
1264 CW_USEDEFAULT, CW_USEDEFAULT,
1265 CW_USEDEFAULT, CW_USEDEFAULT,
1266 mdi_client, GetModuleHandle(0),
1267 (LPARAM)mdi_lParam_test_message);
1268 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1270 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1274 ok(mdi_child != 0, "MDI child creation failed\n");
1275 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1276 ok(id == first_id, "wrong child id %ld\n", id);
1277 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1278 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1281 /* test MDICREATESTRUCT A<->W mapping */
1282 SetLastError(0xdeadbeef);
1283 mdi_child = CreateMDIWindowW(classW, titleW,
1285 CW_USEDEFAULT, CW_USEDEFAULT,
1286 CW_USEDEFAULT, CW_USEDEFAULT,
1287 mdi_client, GetModuleHandle(0),
1288 (LPARAM)mdi_lParam_test_message);
1291 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1294 ok(mdi_child != 0, "MDI child creation failed\n");
1298 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1299 ok(id == first_id, "wrong child id %ld\n", id);
1300 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1301 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1304 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1306 CW_USEDEFAULT, CW_USEDEFAULT,
1307 CW_USEDEFAULT, CW_USEDEFAULT,
1308 mdi_client, 0, GetModuleHandle(0),
1309 mdi_lParam_test_message);
1310 ok(mdi_child != 0, "MDI child creation failed\n");
1311 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1312 ok(id == first_id, "wrong child id %ld\n", id);
1313 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1314 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1316 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1317 0x7fffffff, /* without WS_POPUP */
1318 CW_USEDEFAULT, CW_USEDEFAULT,
1319 CW_USEDEFAULT, CW_USEDEFAULT,
1320 mdi_client, 0, GetModuleHandle(0),
1321 mdi_lParam_test_message);
1322 ok(mdi_child != 0, "MDI child creation failed\n");
1323 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1324 ok(id == first_id, "wrong child id %ld\n", id);
1325 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1326 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1328 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1329 0xffffffff, /* with WS_POPUP */
1330 CW_USEDEFAULT, CW_USEDEFAULT,
1331 CW_USEDEFAULT, CW_USEDEFAULT,
1332 mdi_client, 0, GetModuleHandle(0),
1333 mdi_lParam_test_message);
1334 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1336 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1340 ok(mdi_child != 0, "MDI child creation failed\n");
1341 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1342 ok(id == first_id, "wrong child id %ld\n", id);
1343 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1344 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1347 /* test MDICREATESTRUCT A<->W mapping */
1348 SetLastError(0xdeadbeef);
1349 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1351 CW_USEDEFAULT, CW_USEDEFAULT,
1352 CW_USEDEFAULT, CW_USEDEFAULT,
1353 mdi_client, 0, GetModuleHandle(0),
1354 mdi_lParam_test_message);
1357 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1360 ok(mdi_child != 0, "MDI child creation failed\n");
1364 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1365 ok(id == first_id, "wrong child id %ld\n", id);
1366 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1367 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1370 /* This test fails on Win9x */
1373 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1375 CW_USEDEFAULT, CW_USEDEFAULT,
1376 CW_USEDEFAULT, CW_USEDEFAULT,
1377 parent, 0, GetModuleHandle(0),
1378 mdi_lParam_test_message);
1379 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1382 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1383 WS_CHILD, /* without WS_POPUP */
1384 CW_USEDEFAULT, CW_USEDEFAULT,
1385 CW_USEDEFAULT, CW_USEDEFAULT,
1386 mdi_client, 0, GetModuleHandle(0),
1387 mdi_lParam_test_message);
1388 ok(mdi_child != 0, "MDI child creation failed\n");
1389 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1390 ok(id == 0, "wrong child id %ld\n", id);
1391 DestroyWindow(mdi_child);
1393 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1394 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1395 CW_USEDEFAULT, CW_USEDEFAULT,
1396 CW_USEDEFAULT, CW_USEDEFAULT,
1397 mdi_client, 0, GetModuleHandle(0),
1398 mdi_lParam_test_message);
1399 ok(mdi_child != 0, "MDI child creation failed\n");
1400 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1401 ok(id == 0, "wrong child id %ld\n", id);
1402 DestroyWindow(mdi_child);
1404 /* maximized child */
1405 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1406 WS_CHILD | WS_MAXIMIZE,
1407 CW_USEDEFAULT, CW_USEDEFAULT,
1408 CW_USEDEFAULT, CW_USEDEFAULT,
1409 mdi_client, 0, GetModuleHandle(0),
1410 mdi_lParam_test_message);
1411 ok(mdi_child != 0, "MDI child creation failed\n");
1412 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1413 ok(id == 0, "wrong child id %ld\n", id);
1414 DestroyWindow(mdi_child);
1416 trace("Creating maximized child with a caption\n");
1417 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1418 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1419 CW_USEDEFAULT, CW_USEDEFAULT,
1420 CW_USEDEFAULT, CW_USEDEFAULT,
1421 mdi_client, 0, GetModuleHandle(0),
1422 mdi_lParam_test_message);
1423 ok(mdi_child != 0, "MDI child creation failed\n");
1424 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1425 ok(id == 0, "wrong child id %ld\n", id);
1426 DestroyWindow(mdi_child);
1428 trace("Creating maximized child with a caption and a thick frame\n");
1429 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1430 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1431 CW_USEDEFAULT, CW_USEDEFAULT,
1432 CW_USEDEFAULT, CW_USEDEFAULT,
1433 mdi_client, 0, GetModuleHandle(0),
1434 mdi_lParam_test_message);
1435 ok(mdi_child != 0, "MDI child creation failed\n");
1436 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1437 ok(id == 0, "wrong child id %ld\n", id);
1438 DestroyWindow(mdi_child);
1441 /**********************************************************************
1442 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1444 * Note: The rule here is that client rect of the maximized MDI child
1445 * is equal to the client rect of the MDI client window.
1447 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1451 GetClientRect( client, &rect );
1452 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1453 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1455 rect.right -= rect.left;
1456 rect.bottom -= rect.top;
1457 lpMinMax->ptMaxSize.x = rect.right;
1458 lpMinMax->ptMaxSize.y = rect.bottom;
1460 lpMinMax->ptMaxPosition.x = rect.left;
1461 lpMinMax->ptMaxPosition.y = rect.top;
1463 trace("max rect (%d,%d - %d, %d)\n",
1464 rect.left, rect.top, rect.right, rect.bottom);
1467 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1474 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1475 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1477 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1478 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1480 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1481 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1482 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1483 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1484 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1486 /* MDICREATESTRUCT should have original values */
1487 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1488 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1489 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1490 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1491 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1492 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1494 /* CREATESTRUCT should have fixed values */
1495 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1496 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1498 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1499 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1500 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1502 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1504 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1506 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1507 ok(cs->style == style,
1508 "cs->style does not match (%08x)\n", cs->style);
1512 LONG style = mdi_cs->style;
1514 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1515 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1516 ok(cs->style == style,
1517 "cs->style does not match (%08x)\n", cs->style);
1522 case WM_GETMINMAXINFO:
1524 HWND client = GetParent(hwnd);
1526 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1527 MINMAXINFO my_minmax;
1528 LONG style, exstyle;
1530 style = GetWindowLongA(hwnd, GWL_STYLE);
1531 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1533 GetWindowRect(client, &rc);
1534 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1535 GetClientRect(client, &rc);
1536 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1537 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1538 GetSystemMetrics(SM_CYSCREEN));
1540 GetClientRect(client, &rc);
1541 if ((style & WS_CAPTION) == WS_CAPTION)
1542 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1543 AdjustWindowRectEx(&rc, style, 0, exstyle);
1544 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1545 dump_minmax_info( minmax );
1547 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1548 minmax->ptMaxSize.x, rc.right - rc.left);
1549 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1550 minmax->ptMaxSize.y, rc.bottom - rc.top);
1552 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1554 trace("DefMDIChildProc returned:\n");
1555 dump_minmax_info( minmax );
1557 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1558 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1559 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1560 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1561 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1566 case WM_MDIACTIVATE:
1568 HWND active, client = GetParent(hwnd);
1569 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1570 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1571 if (hwnd == (HWND)lparam) /* if we are being activated */
1572 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1574 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1578 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1581 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1588 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1590 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1591 cs->x, cs->y, cs->cx, cs->cy);
1593 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1594 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1596 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1597 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1599 /* CREATESTRUCT should have fixed values */
1600 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1602 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1603 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1605 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1606 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1607 while Win95, Win2k, WinXP do. */
1608 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1609 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1613 case WM_GETMINMAXINFO:
1615 HWND parent = GetParent(hwnd);
1617 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1618 LONG style, exstyle;
1620 style = GetWindowLongA(hwnd, GWL_STYLE);
1621 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1623 GetClientRect(parent, &rc);
1624 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1626 GetClientRect(parent, &rc);
1627 if ((style & WS_CAPTION) == WS_CAPTION)
1628 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1629 AdjustWindowRectEx(&rc, style, 0, exstyle);
1630 dump_minmax_info( minmax );
1632 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1633 minmax->ptMaxSize.x, rc.right - rc.left);
1634 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1635 minmax->ptMaxSize.y, rc.bottom - rc.top);
1639 case WM_WINDOWPOSCHANGED:
1641 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1644 GetWindowRect(hwnd, &rc1);
1645 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1646 /* note: winpos coordinates are relative to parent */
1647 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1648 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1649 rc1.left, rc1.top, rc1.right, rc1.bottom,
1650 rc2.left, rc2.top, rc2.right, rc2.bottom);
1651 GetWindowRect(hwnd, &rc1);
1652 GetClientRect(hwnd, &rc2);
1653 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1654 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1655 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1656 rc1.left, rc1.top, rc1.right, rc1.bottom,
1657 rc2.left, rc2.top, rc2.right, rc2.bottom);
1660 case WM_WINDOWPOSCHANGING:
1662 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1663 WINDOWPOS my_winpos = *winpos;
1665 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1666 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1667 winpos->hwnd, winpos->hwndInsertAfter,
1668 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1670 DefWindowProcA(hwnd, msg, wparam, lparam);
1672 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1673 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1674 winpos->hwnd, winpos->hwndInsertAfter,
1675 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1680 return DefWindowProcA(hwnd, msg, wparam, lparam);
1683 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1685 static HWND mdi_client;
1691 CLIENTCREATESTRUCT client_cs;
1694 GetClientRect(hwnd, &rc);
1696 client_cs.hWindowMenu = 0;
1697 client_cs.idFirstChild = 1;
1699 /* MDIClient without MDIS_ALLCHILDSTYLES */
1700 mdi_client = CreateWindowExA(0, "mdiclient",
1702 WS_CHILD /*| WS_VISIBLE*/,
1703 /* tests depend on a not zero MDIClient size */
1704 0, 0, rc.right, rc.bottom,
1705 hwnd, 0, GetModuleHandle(0),
1708 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1709 DestroyWindow(mdi_client);
1711 /* MDIClient with MDIS_ALLCHILDSTYLES */
1712 mdi_client = CreateWindowExA(0, "mdiclient",
1714 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1715 /* tests depend on a not zero MDIClient size */
1716 0, 0, rc.right, rc.bottom,
1717 hwnd, 0, GetModuleHandle(0),
1720 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1721 DestroyWindow(mdi_client);
1725 case WM_WINDOWPOSCHANGED:
1727 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1730 GetWindowRect(hwnd, &rc1);
1731 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1732 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1733 /* note: winpos coordinates are relative to parent */
1734 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1735 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1736 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1738 GetWindowRect(hwnd, &rc1);
1739 GetClientRect(hwnd, &rc2);
1740 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1741 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1742 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1745 case WM_WINDOWPOSCHANGING:
1747 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1748 WINDOWPOS my_winpos = *winpos;
1750 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1751 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1752 winpos->hwnd, winpos->hwndInsertAfter,
1753 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1755 DefWindowProcA(hwnd, msg, wparam, lparam);
1757 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1758 winpos->hwnd, winpos->hwndInsertAfter,
1759 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1761 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1762 "DefWindowProc should not change WINDOWPOS values\n");
1771 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1774 static BOOL mdi_RegisterWindowClasses(void)
1779 cls.lpfnWndProc = mdi_main_wnd_procA;
1782 cls.hInstance = GetModuleHandleA(0);
1784 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1785 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1786 cls.lpszMenuName = NULL;
1787 cls.lpszClassName = "MDI_parent_Class";
1788 if(!RegisterClassA(&cls)) return FALSE;
1790 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1791 cls.lpszClassName = "MDI_child_Class_1";
1792 if(!RegisterClassA(&cls)) return FALSE;
1794 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1795 cls.lpszClassName = "MDI_child_Class_2";
1796 if(!RegisterClassA(&cls)) return FALSE;
1801 static void test_mdi(void)
1806 if (!mdi_RegisterWindowClasses()) assert(0);
1808 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1809 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1810 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1811 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1812 GetDesktopWindow(), 0,
1813 GetModuleHandle(0), NULL);
1814 assert(mdi_hwndMain);
1816 while(GetMessage(&msg, 0, 0, 0))
1818 TranslateMessage(&msg);
1819 DispatchMessage(&msg);
1822 DestroyWindow(mdi_hwndMain);
1825 static void test_icons(void)
1829 HICON icon = LoadIconA(0, IDI_APPLICATION);
1830 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1831 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1832 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1835 cls.cbSize = sizeof(cls);
1837 cls.lpfnWndProc = DefWindowProcA;
1841 cls.hIcon = LoadIconA(0, IDI_HAND);
1842 cls.hIconSm = small_icon;
1843 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1844 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1845 cls.lpszMenuName = NULL;
1846 cls.lpszClassName = "IconWindowClass";
1848 RegisterClassExA(&cls);
1850 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1851 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1854 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1855 ok( res == 0, "wrong big icon %p/0\n", res );
1856 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1857 ok( res == 0, "wrong previous big icon %p/0\n", res );
1858 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1859 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1860 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1861 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1862 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1863 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1865 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1866 ok( res == 0, "wrong small icon %p/0\n", res );
1867 /* this test is XP specific */
1868 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1869 ok( res != 0, "wrong small icon %p\n", res );*/
1870 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1871 ok( res == 0, "wrong previous small icon %p/0\n", res );
1872 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1873 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1874 /* this test is XP specific */
1875 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1876 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1877 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1878 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1879 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1880 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1881 /* this test is XP specific */
1882 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1883 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1885 /* make sure the big icon hasn't changed */
1886 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1887 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1889 DestroyWindow( hwnd );
1892 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1894 if (msg == WM_NCCALCSIZE)
1896 RECT *rect = (RECT *)lparam;
1897 /* first time around increase the rectangle, next time decrease it */
1898 if (rect->left == 100) InflateRect( rect, 10, 10 );
1899 else InflateRect( rect, -10, -10 );
1902 return DefWindowProc( hwnd, msg, wparam, lparam );
1905 static void test_SetWindowPos(HWND hwnd)
1907 RECT orig_win_rc, rect;
1910 SetRect(&rect, 111, 222, 333, 444);
1911 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1912 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1913 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1915 SetRect(&rect, 111, 222, 333, 444);
1916 ok(!GetClientRect(0, &rect), "GetClientRect 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 GetWindowRect(hwnd, &orig_win_rc);
1922 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1923 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1924 GetWindowRect( hwnd, &rect );
1925 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1926 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1927 GetClientRect( hwnd, &rect );
1928 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1929 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1930 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1932 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1933 GetWindowRect( hwnd, &rect );
1934 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1935 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1936 GetClientRect( hwnd, &rect );
1937 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1938 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1939 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1941 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1942 orig_win_rc.right, orig_win_rc.bottom, 0);
1943 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1945 /* Win9x truncates coordinates to 16-bit irrespectively */
1948 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1949 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1951 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1952 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1955 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1956 orig_win_rc.right, orig_win_rc.bottom, 0);
1958 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1959 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1960 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1961 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1962 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1963 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1964 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1967 static void test_SetMenu(HWND parent)
1974 hMenu = CreateMenu();
1977 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1980 /* fails on (at least) Wine, NT4, XP SP2 */
1981 test_nonclient_area(parent);
1983 ret = GetMenu(parent);
1984 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1985 /* test whether we can destroy a menu assigned to a window */
1986 retok = DestroyMenu(hMenu);
1987 ok( retok, "DestroyMenu error %d\n", GetLastError());
1988 retok = IsMenu(hMenu);
1989 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1990 ret = GetMenu(parent);
1991 /* This test fails on Win9x */
1993 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1994 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1995 test_nonclient_area(parent);
1997 hMenu = CreateMenu();
2001 ret = GetMenu(parent);
2002 ok(ret == 0, "unexpected menu id %p\n", ret);
2004 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2005 test_nonclient_area(parent);
2006 ret = GetMenu(parent);
2007 ok(ret == 0, "unexpected menu id %p\n", ret);
2009 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2012 /* fails on (at least) Wine, NT4, XP SP2 */
2013 test_nonclient_area(parent);
2015 ret = GetMenu(parent);
2016 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2018 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2019 test_nonclient_area(parent);
2020 ret = GetMenu(parent);
2021 ok(ret == 0, "unexpected menu id %p\n", ret);
2024 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2027 ret = GetMenu(child);
2028 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2030 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2031 test_nonclient_area(child);
2032 ret = GetMenu(child);
2033 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2035 ok(!SetMenu(child, hMenu), "SetMenu on a child window 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, 0), "SetMenu(0) 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 style = GetWindowLong(child, GWL_STYLE);
2046 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2047 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2048 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2049 SetWindowLong(child, GWL_STYLE, style);
2051 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2052 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2053 SetWindowLong(child, GWL_STYLE, style);
2055 DestroyWindow(child);
2059 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2061 HWND child[5], hwnd;
2066 hwnd = GetWindow(parent, GW_CHILD);
2067 ok(!hwnd, "have to start without children to perform the test\n");
2069 for (i = 0; i < total; i++)
2071 if (style[i] & DS_CONTROL)
2073 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2074 0,0,0,0, parent, (HMENU)i, 0, NULL);
2075 if (style[i] & WS_VISIBLE)
2076 ShowWindow(child[i], SW_SHOW);
2078 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2081 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2082 parent, (HMENU)i, 0, NULL);
2083 trace("child[%ld] = %p\n", i, child[i]);
2084 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2087 hwnd = GetWindow(parent, GW_CHILD);
2088 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2089 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2090 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2092 for (i = 0; i < total; i++)
2094 trace("hwnd[%ld] = %p\n", i, hwnd);
2095 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2097 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2100 for (i = 0; i < total; i++)
2101 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2104 static void test_children_zorder(HWND parent)
2106 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2108 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2110 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2111 WS_CHILD | WS_VISIBLE, WS_CHILD,
2112 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2113 const int complex_order_1[1] = { 0 };
2114 const int complex_order_2[2] = { 1, 0 };
2115 const int complex_order_3[3] = { 1, 0, 2 };
2116 const int complex_order_4[4] = { 1, 0, 2, 3 };
2117 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2118 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2119 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2120 WS_CHILD | WS_VISIBLE };
2121 const int complex_order_6[3] = { 0, 1, 2 };
2123 /* simple WS_CHILD */
2124 test_window_tree(parent, simple_style, simple_order, 5);
2126 /* complex children styles */
2127 test_window_tree(parent, complex_style, complex_order_1, 1);
2128 test_window_tree(parent, complex_style, complex_order_2, 2);
2129 test_window_tree(parent, complex_style, complex_order_3, 3);
2130 test_window_tree(parent, complex_style, complex_order_4, 4);
2131 test_window_tree(parent, complex_style, complex_order_5, 5);
2133 /* another set of complex children styles */
2134 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2137 #define check_z_order(hwnd, next, prev, owner, topmost) \
2138 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2141 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2142 BOOL topmost, const char *file, int line)
2147 test = GetWindow(hwnd, GW_HWNDNEXT);
2148 /* skip foreign windows */
2149 while (test && test != next &&
2150 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2151 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2152 GetWindow(test, GW_OWNER) == next))
2154 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2155 test = GetWindow(test, GW_HWNDNEXT);
2157 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2159 test = GetWindow(hwnd, GW_HWNDPREV);
2160 /* skip foreign windows */
2161 while (test && test != prev &&
2162 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2163 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2164 GetWindow(test, GW_OWNER) == hwnd))
2166 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2167 test = GetWindow(test, GW_HWNDPREV);
2169 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2171 test = GetWindow(hwnd, GW_OWNER);
2172 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2174 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2175 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2178 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2180 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2182 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2184 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2186 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2187 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2189 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2190 WS_OVERLAPPED | WS_CAPTION,
2192 0, 0, GetModuleHandle(0), NULL);
2193 trace("hwnd_F %p\n", hwnd_F);
2194 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2196 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2197 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2198 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2199 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2201 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2204 hwnd_F, 0, GetModuleHandle(0), NULL);
2205 trace("hwnd_C %p\n", hwnd_C);
2206 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2207 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2208 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2209 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2211 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2214 hwnd_F, 0, GetModuleHandle(0), NULL);
2215 trace("hwnd_B %p\n", hwnd_B);
2216 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2217 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2218 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2219 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2220 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2222 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2225 0, 0, GetModuleHandle(0), NULL);
2226 trace("hwnd_A %p\n", hwnd_A);
2227 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2228 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2229 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2230 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2231 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2232 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2234 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);
2236 /* move hwnd_F and its popups up */
2237 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2238 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2239 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2240 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2241 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2242 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2243 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2245 /* move hwnd_F and its popups down */
2246 #if 0 /* enable once Wine is fixed to pass this test */
2247 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2248 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2249 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2250 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2251 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2252 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2253 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2256 DestroyWindow(hwnd_A);
2257 DestroyWindow(hwnd_B);
2258 DestroyWindow(hwnd_C);
2259 DestroyWindow(hwnd_F);
2262 static void test_vis_rgn( HWND hwnd )
2264 RECT win_rect, rgn_rect;
2265 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2268 ShowWindow(hwnd,SW_SHOW);
2269 hdc = GetDC( hwnd );
2270 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2271 GetWindowRect( hwnd, &win_rect );
2272 GetRgnBox( hrgn, &rgn_rect );
2275 trace("win9x, mapping to screen coords\n");
2276 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2278 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2279 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2280 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2281 rgn_rect.left, win_rect.left );
2282 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2283 rgn_rect.top, win_rect.top );
2284 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2285 rgn_rect.right, win_rect.right );
2286 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2287 rgn_rect.bottom, win_rect.bottom );
2288 ReleaseDC( hwnd, hdc );
2291 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2293 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2295 HWND child = GetWindow(hwnd, GW_CHILD);
2296 ok(child != 0, "couldn't find child window\n");
2298 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2301 return DefWindowProc(hwnd, msg, wp, lp);
2304 static void test_SetFocus(HWND hwnd)
2307 WNDPROC old_wnd_proc;
2309 /* check if we can set focus to non-visible windows */
2311 ShowWindow(hwnd, SW_SHOW);
2314 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2315 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2316 ShowWindow(hwnd, SW_HIDE);
2319 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2320 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2321 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2324 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2325 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2326 ShowWindow(child, SW_SHOW);
2327 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2328 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2329 ShowWindow(child, SW_HIDE);
2330 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2331 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2332 ShowWindow(child, SW_SHOW);
2333 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2335 ShowWindow(child2, SW_SHOW);
2337 ShowWindow(child, SW_HIDE);
2338 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2339 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2340 ShowWindow(child, SW_SHOW);
2342 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2343 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2344 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2346 ShowWindow(child, SW_HIDE);
2348 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2349 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2350 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2351 ShowWindow(child, SW_HIDE);
2352 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2354 ShowWindow(hwnd, SW_SHOW);
2355 ShowWindow(child, SW_SHOW);
2357 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2358 EnableWindow(hwnd, FALSE);
2359 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2360 EnableWindow(hwnd, TRUE);
2362 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2363 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2364 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2366 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2367 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2368 ShowWindow(hwnd, SW_RESTORE);
2369 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2370 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2371 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2372 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2373 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2375 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2376 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2377 ShowWindow(hwnd, SW_RESTORE);
2378 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2380 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2382 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2384 DestroyWindow( child2 );
2385 DestroyWindow( child );
2388 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2389 static void check_wnd_state_(const char *file, int line,
2390 HWND active, HWND foreground, HWND focus, HWND capture)
2392 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2393 /* only check foreground if it belongs to the current thread */
2394 /* foreground can be moved to a different app pretty much at any time */
2395 if (foreground && GetForegroundWindow() &&
2396 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2397 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2398 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2399 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2402 static void test_SetActiveWindow(HWND hwnd)
2406 flush_events( TRUE );
2407 ShowWindow(hwnd, SW_HIDE);
2410 check_wnd_state(0, 0, 0, 0);
2412 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2414 ShowWindow(hwnd, SW_SHOW);
2415 check_wnd_state(hwnd, hwnd, hwnd, 0);
2417 hwnd2 = SetActiveWindow(0);
2418 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2419 if (!GetActiveWindow()) /* doesn't always work on vista */
2421 check_wnd_state(0, 0, 0, 0);
2422 hwnd2 = SetActiveWindow(hwnd);
2423 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2425 check_wnd_state(hwnd, hwnd, hwnd, 0);
2427 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2428 check_wnd_state(hwnd, hwnd, hwnd, 0);
2430 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2431 check_wnd_state(hwnd, hwnd, hwnd, 0);
2433 ShowWindow(hwnd, SW_HIDE);
2434 check_wnd_state(0, 0, 0, 0);
2436 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2437 SetActiveWindow(hwnd);
2438 check_wnd_state(hwnd, hwnd, hwnd, 0);
2440 ShowWindow(hwnd, SW_SHOW);
2441 check_wnd_state(hwnd, hwnd, hwnd, 0);
2443 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2444 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2446 DestroyWindow(hwnd2);
2447 check_wnd_state(hwnd, hwnd, hwnd, 0);
2449 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2450 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2452 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2453 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2455 DestroyWindow(hwnd2);
2456 check_wnd_state(hwnd, hwnd, hwnd, 0);
2459 static void test_SetForegroundWindow(HWND hwnd)
2464 flush_events( TRUE );
2465 ShowWindow(hwnd, SW_HIDE);
2468 check_wnd_state(0, 0, 0, 0);
2470 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2472 ShowWindow(hwnd, SW_SHOW);
2473 check_wnd_state(hwnd, hwnd, hwnd, 0);
2475 hwnd2 = SetActiveWindow(0);
2476 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2477 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2478 check_wnd_state(hwnd, hwnd, hwnd, 0);
2480 check_wnd_state(0, 0, 0, 0);
2482 ret = SetForegroundWindow(hwnd);
2485 skip( "SetForegroundWindow not working\n" );
2488 check_wnd_state(hwnd, hwnd, hwnd, 0);
2490 SetLastError(0xdeadbeef);
2491 ret = SetForegroundWindow(0);
2492 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2493 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2494 broken(GetLastError() == 0xdeadbeef), /* win9x */
2495 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2496 check_wnd_state(hwnd, hwnd, hwnd, 0);
2498 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2499 check_wnd_state(hwnd, hwnd, hwnd, 0);
2501 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2502 check_wnd_state(hwnd, hwnd, hwnd, 0);
2504 hwnd2 = GetForegroundWindow();
2505 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2506 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2507 hwnd2 = GetForegroundWindow();
2508 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2510 ShowWindow(hwnd, SW_HIDE);
2511 check_wnd_state(0, 0, 0, 0);
2513 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2514 ret = SetForegroundWindow(hwnd);
2515 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2516 check_wnd_state(hwnd, hwnd, hwnd, 0);
2518 ShowWindow(hwnd, SW_SHOW);
2519 check_wnd_state(hwnd, hwnd, hwnd, 0);
2521 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2522 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2524 DestroyWindow(hwnd2);
2525 check_wnd_state(hwnd, hwnd, hwnd, 0);
2527 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2528 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2530 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2531 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2533 DestroyWindow(hwnd2);
2534 check_wnd_state(hwnd, hwnd, hwnd, 0);
2537 static WNDPROC old_button_proc;
2539 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2544 key_state = GetKeyState(VK_LBUTTON);
2545 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2547 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2549 if (msg == WM_LBUTTONDOWN)
2553 check_wnd_state(button, button, button, button);
2555 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2557 trace("hwnd %p\n", hwnd);
2559 check_wnd_state(button, button, button, button);
2561 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2563 check_wnd_state(button, button, button, button);
2565 DestroyWindow(hwnd);
2567 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2569 trace("hwnd %p\n", hwnd);
2571 check_wnd_state(button, button, button, button);
2573 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2574 * match internal button state.
2576 SendMessage(button, WM_KILLFOCUS, 0, 0);
2577 check_wnd_state(button, button, button, 0);
2579 ShowWindow(hwnd, SW_SHOW);
2580 check_wnd_state(hwnd, hwnd, hwnd, 0);
2582 capture = SetCapture(hwnd);
2583 ok(capture == 0, "SetCapture() = %p\n", capture);
2585 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2587 DestroyWindow(hwnd);
2589 check_wnd_state(button, 0, button, 0);
2595 static void test_capture_1(void)
2597 HWND button, capture, oldFocus, oldActive;
2599 oldFocus = GetFocus();
2600 oldActive = GetActiveWindow();
2602 capture = GetCapture();
2603 ok(capture == 0, "GetCapture() = %p\n", capture);
2605 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2607 trace("button %p\n", button);
2609 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2611 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2613 capture = SetCapture(button);
2614 ok(capture == 0, "SetCapture() = %p\n", capture);
2615 check_wnd_state(button, 0, button, button);
2617 DestroyWindow(button);
2618 check_wnd_state(oldActive, 0, oldFocus, 0);
2621 static void test_capture_2(void)
2623 HWND button, hwnd, capture, oldFocus, oldActive;
2625 oldFocus = GetFocus();
2626 oldActive = GetActiveWindow();
2627 check_wnd_state(oldActive, 0, oldFocus, 0);
2629 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2631 trace("button %p\n", button);
2633 check_wnd_state(button, button, button, 0);
2635 capture = SetCapture(button);
2636 ok(capture == 0, "SetCapture() = %p\n", capture);
2638 check_wnd_state(button, button, button, button);
2640 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2641 * internal button state.
2643 SendMessage(button, WM_KILLFOCUS, 0, 0);
2644 check_wnd_state(button, button, button, button);
2646 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2648 trace("hwnd %p\n", hwnd);
2650 check_wnd_state(button, button, button, button);
2652 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2654 check_wnd_state(button, button, button, button);
2656 DestroyWindow(hwnd);
2658 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2660 trace("hwnd %p\n", hwnd);
2662 check_wnd_state(button, button, button, button);
2664 ShowWindow(hwnd, SW_SHOW);
2666 check_wnd_state(hwnd, hwnd, hwnd, button);
2668 capture = SetCapture(hwnd);
2669 ok(capture == button, "SetCapture() = %p\n", capture);
2671 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2673 DestroyWindow(hwnd);
2674 check_wnd_state(button, button, button, 0);
2676 DestroyWindow(button);
2677 check_wnd_state(oldActive, 0, oldFocus, 0);
2680 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2684 ShowWindow(hwnd1, SW_HIDE);
2685 ShowWindow(hwnd2, SW_HIDE);
2687 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2688 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2691 check_wnd_state(0, 0, 0, hwnd1);
2694 check_wnd_state(0, 0, 0, hwnd2);
2696 ShowWindow(hwnd1, SW_SHOW);
2697 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2699 ret = ReleaseCapture();
2700 ok (ret, "releasecapture did not return TRUE.\n");
2701 ret = ReleaseCapture();
2702 ok (ret, "releasecapture did not return TRUE after second try.\n");
2705 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2708 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2712 case WM_CAPTURECHANGED:
2714 /* now try to release capture from menu. this should fail */
2715 if (pGetGUIThreadInfo)
2717 memset(>i, 0, sizeof(GUITHREADINFO));
2718 gti.cbSize = sizeof(GUITHREADINFO);
2719 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2720 ok(status, "GetGUIThreadInfo() failed!\n");
2721 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2723 cap_wnd = GetCapture();
2725 /* check that re-setting the capture for the menu fails */
2726 set_cap_wnd = SetCapture(cap_wnd);
2727 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
2728 "SetCapture should have failed!\n");
2731 DestroyWindow(hWnd);
2735 /* check that SetCapture fails for another window and that it does not touch the error code */
2736 set_cap_wnd = SetCapture(hWnd);
2737 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2739 /* check that ReleaseCapture fails and does not touch the error code */
2740 status = ReleaseCapture();
2741 ok(!status, "ReleaseCapture should have failed!\n");
2743 /* check that thread info did not change */
2744 if (pGetGUIThreadInfo)
2746 memset(>i, 0, sizeof(GUITHREADINFO));
2747 gti.cbSize = sizeof(GUITHREADINFO);
2748 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2749 ok(status, "GetGUIThreadInfo() failed!\n");
2750 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2753 /* verify that no capture change took place */
2754 cap_wnd2 = GetCapture();
2755 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2757 /* we are done. kill the window */
2758 DestroyWindow(hWnd);
2762 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2767 /* Test that no-one can mess around with the current capture while a menu is open */
2768 static void test_capture_4(void)
2774 HINSTANCE hInstance = GetModuleHandleA( NULL );
2776 if (!pGetGUIThreadInfo)
2778 win_skip("GetGUIThreadInfo is not available\n");
2781 wclass.lpszClassName = "TestCapture4Class";
2782 wclass.style = CS_HREDRAW | CS_VREDRAW;
2783 wclass.lpfnWndProc = test_capture_4_proc;
2784 wclass.hInstance = hInstance;
2785 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2786 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2787 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2788 wclass.lpszMenuName = 0;
2789 wclass.cbClsExtra = 0;
2790 wclass.cbWndExtra = 0;
2791 assert (RegisterClassA( &wclass ));
2792 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2793 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2794 400, 200, NULL, NULL, hInstance, NULL) );
2795 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2797 hmenu = CreatePopupMenu();
2799 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2800 ok( ret, "AppendMenuA has failed!\n");
2802 /* set main window to have initial capture */
2807 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2811 /* create popup (it will self-destruct) */
2812 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2813 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2818 DestroyWindow(hwnd);
2821 /* PeekMessage wrapper that ignores the messages we don't care about */
2822 static BOOL peek_message( MSG *msg )
2827 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2828 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2832 static void test_keyboard_input(HWND hwnd)
2837 flush_events( TRUE );
2838 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2840 flush_events( TRUE );
2842 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2845 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2847 flush_events( TRUE );
2849 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2850 ret = peek_message(&msg);
2851 ok( ret, "no message available\n");
2852 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2853 ret = peek_message(&msg);
2854 ok( !ret, "message %04x available\n", msg.message);
2856 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2858 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2859 ret = peek_message(&msg);
2860 ok(ret, "no message available\n");
2861 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2862 ret = peek_message(&msg);
2863 ok( !ret, "message %04x available\n", msg.message);
2865 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2867 keybd_event(VK_SPACE, 0, 0, 0);
2868 if (!peek_message(&msg))
2870 skip( "keybd_event didn't work, skipping keyboard test\n" );
2873 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2874 ret = peek_message(&msg);
2875 ok( !ret, "message %04x available\n", msg.message);
2878 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2880 flush_events( TRUE );
2882 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2883 ret = peek_message(&msg);
2884 ok(ret, "no message available\n");
2885 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2886 ret = peek_message(&msg);
2887 ok( !ret, "message %04x available\n", msg.message);
2889 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2891 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2892 ret = peek_message(&msg);
2893 ok(ret, "no message available\n");
2894 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2895 ret = peek_message(&msg);
2896 ok( !ret, "message %04x available\n", msg.message);
2898 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2900 keybd_event(VK_SPACE, 0, 0, 0);
2901 ret = peek_message(&msg);
2902 ok(ret, "no message available\n");
2903 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2904 ret = peek_message(&msg);
2905 ok( !ret, "message %04x available\n", msg.message);
2908 static BOOL wait_for_message( MSG *msg )
2914 ret = peek_message(msg);
2917 if (msg->message == WM_PAINT) DispatchMessage(msg);
2920 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2922 if (!ret) msg->message = 0;
2926 static void test_mouse_input(HWND hwnd)
2936 ShowWindow(hwnd, SW_SHOW);
2938 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2940 GetWindowRect(hwnd, &rc);
2941 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2943 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2944 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2947 ShowWindow(popup, SW_SHOW);
2948 UpdateWindow(popup);
2949 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2951 GetWindowRect(popup, &rc);
2952 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2954 x = rc.left + (rc.right - rc.left) / 2;
2955 y = rc.top + (rc.bottom - rc.top) / 2;
2956 trace("setting cursor to (%d,%d)\n", x, y);
2960 if (x != pt.x || y != pt.y)
2962 skip( "failed to set mouse position, skipping mouse input tests\n" );
2966 flush_events( TRUE );
2968 /* Check that setting the same position may generate WM_MOUSEMOVE */
2971 ret = peek_message(&msg);
2974 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2975 msg.hwnd, msg.message);
2976 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2977 x, y, msg.pt.x, msg.pt.y);
2980 /* force the system to update its internal queue mouse position,
2981 * otherwise it won't generate relative mouse movements below.
2983 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2984 flush_events( TRUE );
2987 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2988 flush_events( FALSE );
2989 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2990 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2992 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
2993 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2994 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2995 DispatchMessage(&msg);
2997 ret = peek_message(&msg);
2998 ok( !ret, "message %04x available\n", msg.message);
3000 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3001 ShowWindow(popup, SW_HIDE);
3002 ret = wait_for_message( &msg );
3004 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3005 flush_events( TRUE );
3007 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3008 ShowWindow(hwnd, SW_HIDE);
3009 ret = wait_for_message( &msg );
3010 ok( !ret, "message %04x available\n", msg.message);
3011 flush_events( TRUE );
3013 /* test mouse clicks */
3015 ShowWindow(hwnd, SW_SHOW);
3016 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3017 flush_events( TRUE );
3018 ShowWindow(popup, SW_SHOW);
3019 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3020 flush_events( TRUE );
3022 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3023 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3024 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3025 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3027 ret = wait_for_message( &msg );
3030 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3033 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3035 ret = wait_for_message( &msg );
3036 ok(ret, "no message available\n");
3039 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3040 msg.hwnd, popup, msg.message);
3042 ret = wait_for_message( &msg );
3043 ok(ret, "no message available\n");
3044 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3045 msg.hwnd, popup, msg.message);
3047 ret = wait_for_message( &msg );
3048 ok(ret, "no message available\n");
3049 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3050 msg.hwnd, popup, msg.message);
3052 ret = wait_for_message( &msg );
3053 ok(ret, "no message available\n");
3054 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3055 msg.hwnd, popup, msg.message);
3057 ret = peek_message(&msg);
3058 ok(!ret, "message %04x available\n", msg.message);
3060 ShowWindow(popup, SW_HIDE);
3061 flush_events( TRUE );
3063 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3064 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3065 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3066 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3068 ret = wait_for_message( &msg );
3069 ok(ret, "no message available\n");
3070 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3071 msg.hwnd, hwnd, msg.message);
3072 ret = wait_for_message( &msg );
3073 ok(ret, "no message available\n");
3074 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3075 msg.hwnd, hwnd, msg.message);
3077 test_lbuttondown_flag = TRUE;
3078 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3079 test_lbuttondown_flag = FALSE;
3081 ret = wait_for_message( &msg );
3082 ok(ret, "no message available\n");
3083 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3084 msg.hwnd, popup, msg.message);
3085 ok(peek_message(&msg), "no message available\n");
3086 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3087 msg.hwnd, popup, msg.message);
3088 ok(peek_message(&msg), "no message available\n");
3090 /* Test WM_MOUSEACTIVATE */
3091 #define TEST_MOUSEACTIVATE(A,B) \
3092 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3093 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3095 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3096 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3097 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3098 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3099 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3100 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3101 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3102 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3103 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3104 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3105 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3106 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3107 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3108 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3109 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3110 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3111 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3112 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3113 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3114 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3115 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3116 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3117 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3118 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3121 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3122 flush_events( TRUE );
3124 DestroyWindow(popup);
3127 static void test_validatergn(HWND hwnd)
3133 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3134 ShowWindow(hwnd, SW_SHOW);
3135 UpdateWindow( hwnd);
3136 /* test that ValidateRect validates children*/
3137 InvalidateRect( child, NULL, 1);
3138 GetWindowRect( child, &rc);
3139 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3140 ret = GetUpdateRect( child, &rc2, 0);
3141 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3142 "Update rectangle is empty!\n");
3143 ValidateRect( hwnd, &rc);
3144 ret = GetUpdateRect( child, &rc2, 0);
3145 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3146 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3147 rc2.right, rc2.bottom);
3149 /* now test ValidateRgn */
3150 InvalidateRect( child, NULL, 1);
3151 GetWindowRect( child, &rc);
3152 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3153 rgn = CreateRectRgnIndirect( &rc);
3154 ValidateRgn( hwnd, rgn);
3155 ret = GetUpdateRect( child, &rc2, 0);
3156 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3157 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3158 rc2.right, rc2.bottom);
3161 DestroyWindow( child );
3164 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3167 MoveWindow( hwnd, 0, 0, x, y, 0);
3168 GetWindowRect( hwnd, prc);
3170 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3171 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3172 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3175 static void test_nccalcscroll(HWND parent)
3178 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3179 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3180 HWND hwnd = CreateWindowExA(0, "static", NULL,
3181 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3182 10, 10, 200, 200, parent, 0, 0, NULL);
3183 ShowWindow( parent, SW_SHOW);
3184 UpdateWindow( parent);
3186 /* test window too low for a horizontal scroll bar */
3187 nccalchelper( hwnd, 100, sbheight, &rc1);
3188 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3189 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3191 /* test window just high enough for a horizontal scroll bar */
3192 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3193 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3194 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3196 /* test window too narrow for a vertical scroll bar */
3197 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3198 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3199 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3201 /* test window just wide enough for a vertical scroll bar */
3202 nccalchelper( hwnd, sbwidth, 100, &rc1);
3203 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3204 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3206 /* same test, but with client edge: not enough width */
3207 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3208 nccalchelper( hwnd, sbwidth, 100, &rc1);
3209 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3210 "Width should be %d size is %d,%d - %d,%d\n",
3211 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3213 DestroyWindow( hwnd);
3216 static void test_SetParent(void)
3219 HWND desktop = GetDesktopWindow();
3221 /* FIXME: This detection is not correct as it also covers (all?) XP+ */
3222 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3223 HWND parent, child1, child2, child3, child4, sibling;
3225 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3226 100, 100, 200, 200, 0, 0, 0, NULL);
3227 assert(parent != 0);
3228 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3229 0, 0, 50, 50, parent, 0, 0, NULL);
3230 assert(child1 != 0);
3231 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3232 0, 0, 50, 50, child1, 0, 0, NULL);
3233 assert(child2 != 0);
3234 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3235 0, 0, 50, 50, child2, 0, 0, NULL);
3236 assert(child3 != 0);
3237 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3238 0, 0, 50, 50, child3, 0, 0, NULL);
3239 assert(child4 != 0);
3241 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3242 parent, child1, child2, child3, child4);
3244 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3245 check_parents(child1, parent, parent, parent, 0, parent, parent);
3246 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3247 check_parents(child3, child2, child2, child2, 0, child2, parent);
3248 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3250 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3251 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3252 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3253 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3254 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3256 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3257 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3258 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3259 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3260 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3261 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3262 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3263 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3264 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3266 if (!is_win9x) /* Win9x doesn't survive this test */
3268 ok(!SetParent(parent, child1), "SetParent should fail\n");
3269 ok(!SetParent(child2, child3), "SetParent should fail\n");
3270 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3271 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3272 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3273 ok(!SetParent(child2, parent), "SetParent should fail\n");
3274 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3276 check_parents(parent, child4, child4, 0, 0, child4, parent);
3277 check_parents(child1, parent, parent, parent, 0, child4, parent);
3278 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3279 check_parents(child3, child2, child2, child2, 0, child2, parent);
3280 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3283 skip("Win9x/WinMe crash\n");
3285 hMenu = CreateMenu();
3286 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3287 100, 100, 200, 200, 0, hMenu, 0, NULL);
3288 assert(sibling != 0);
3290 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3291 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3293 ret = DestroyWindow(parent);
3294 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3296 ok(!IsWindow(parent), "parent still exists\n");
3297 ok(!IsWindow(sibling), "sibling still exists\n");
3298 ok(!IsWindow(child1), "child1 still exists\n");
3299 ok(!IsWindow(child2), "child2 still exists\n");
3300 ok(!IsWindow(child3), "child3 still exists\n");
3301 ok(!IsWindow(child4), "child4 still exists\n");
3304 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3306 LPCREATESTRUCT lpcs;
3313 lpcs = (LPCREATESTRUCT)lparam;
3314 lpss = lpcs->lpCreateParams;
3317 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3318 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3319 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3320 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3322 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3324 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3325 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3326 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3328 ok(lpss->styleNew == lpcs->style,
3329 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3330 lpss->styleNew, lpcs->style);
3334 return DefWindowProc(hwnd, msg, wparam, lparam);
3337 static ATOM atomStyleCheckClass;
3339 static void register_style_check_class(void)
3347 GetModuleHandle(NULL),
3349 LoadCursor(NULL, IDC_ARROW),
3350 (HBRUSH)(COLOR_BTNFACE+1),
3352 TEXT("WineStyleCheck"),
3355 atomStyleCheckClass = RegisterClass(&wc);
3358 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3360 DWORD dwActualStyle;
3361 DWORD dwActualExStyle;
3364 HWND hwndParent = NULL;
3366 ss.styleNew = dwStyleIn;
3367 ss.styleOld = dwExStyleIn;
3369 if (dwStyleIn & WS_CHILD)
3371 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3372 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3375 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3376 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3379 flush_events( TRUE );
3381 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3382 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3383 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3384 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3385 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3387 DestroyWindow(hwnd);
3388 if (hwndParent) DestroyWindow(hwndParent);
3391 /* tests what window styles the window manager automatically adds */
3392 static void test_window_styles(void)
3394 register_style_check_class();
3396 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3397 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3398 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3399 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3400 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3401 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3402 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3403 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3404 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3405 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3406 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3409 static void test_scrollwindow( HWND hwnd)
3415 ShowWindow( hwnd, SW_SHOW);
3416 UpdateWindow( hwnd);
3417 flush_events( TRUE );
3418 GetClientRect( hwnd, &rc);
3420 /* test ScrollWindow(Ex) with no clip rectangle */
3421 /* paint the lower half of the window black */
3423 rc2.top = ( rc2.top + rc2.bottom) / 2;
3424 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3425 /* paint the upper half of the window white */
3426 rc2.bottom = rc2.top;
3428 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3429 /* scroll lower half up */
3431 rc2.top = ( rc2.top + rc2.bottom) / 2;
3432 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3433 flush_events(FALSE);
3434 /* expected: black should have scrolled to the upper half */
3435 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3436 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3437 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3438 /* paint the lower half of the window black */
3440 rc2.top = ( rc2.top + rc2.bottom) / 2;
3441 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3442 /* paint the upper half of the window white */
3443 rc2.bottom = rc2.top;
3445 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3446 /* scroll lower half up */
3448 rc2.top = ( rc2.top + rc2.bottom) / 2;
3450 rc3.left = rc3.right / 4;
3451 rc3.right -= rc3.right / 4;
3452 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3453 flush_events(FALSE);
3454 /* expected: black should have scrolled to the upper half */
3455 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3456 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3459 ReleaseDC( hwnd, hdc);
3462 static void test_scrollvalidate( HWND parent)
3465 HRGN hrgn=CreateRectRgn(0,0,0,0);
3466 HRGN exprgn, tmprgn, clipping;
3467 RECT rc, rcu, cliprc;
3468 /* create two overlapping child windows. The visual region
3469 * of hwnd1 is clipped by the overlapping part of
3470 * hwnd2 because of the WS_CLIPSIBLING style */
3473 clipping = CreateRectRgn(0,0,0,0);
3474 tmprgn = CreateRectRgn(0,0,0,0);
3475 exprgn = CreateRectRgn(0,0,0,0);
3476 hwnd2 = CreateWindowExA(0, "static", NULL,
3477 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3478 75, 30, 100, 100, parent, 0, 0, NULL);
3479 hwnd1 = CreateWindowExA(0, "static", NULL,
3480 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3481 25, 50, 100, 100, parent, 0, 0, NULL);
3482 ShowWindow( parent, SW_SHOW);
3483 UpdateWindow( parent);
3484 GetClientRect( hwnd1, &rc);
3486 SetRectRgn( clipping, 10, 10, 90, 90);
3487 hdc = GetDC( hwnd1);
3488 /* for a visual touch */
3489 TextOut( hdc, 0,10, "0123456789", 10);
3490 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3491 if (winetest_debug > 0) dump_region(hrgn);
3492 /* create a region with what is expected */
3493 SetRectRgn( exprgn, 39,0,49,74);
3494 SetRectRgn( tmprgn, 88,79,98,93);
3495 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3496 SetRectRgn( tmprgn, 0,93,98,98);
3497 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3498 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3499 trace("update rect is %d,%d - %d,%d\n",
3500 rcu.left,rcu.top,rcu.right,rcu.bottom);
3501 /* now with clipping region */
3502 SelectClipRgn( hdc, clipping);
3503 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3504 if (winetest_debug > 0) dump_region(hrgn);
3505 /* create a region with what is expected */
3506 SetRectRgn( exprgn, 39,10,49,74);
3507 SetRectRgn( tmprgn, 80,79,90,85);
3508 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3509 SetRectRgn( tmprgn, 10,85,90,90);
3510 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3511 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3512 trace("update rect is %d,%d - %d,%d\n",
3513 rcu.left,rcu.top,rcu.right,rcu.bottom);
3514 ReleaseDC( hwnd1, hdc);
3516 /* test scrolling a window with an update region */
3517 DestroyWindow( hwnd2);
3518 ValidateRect( hwnd1, NULL);
3519 SetRect( &rc, 40,40, 50,50);
3520 InvalidateRect( hwnd1, &rc, 1);
3521 GetClientRect( hwnd1, &rc);
3523 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3524 SW_SCROLLCHILDREN | SW_INVALIDATE);
3525 if (winetest_debug > 0) dump_region(hrgn);
3526 SetRectRgn( exprgn, 88,0,98,98);
3527 SetRectRgn( tmprgn, 30, 40, 50, 50);
3528 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3529 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3531 /* clear an update region */
3532 UpdateWindow( hwnd1 );
3534 SetRect( &rc, 0,40, 100,60);
3535 SetRect( &cliprc, 0,0, 100,100);
3536 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3537 if (winetest_debug > 0) dump_region( hrgn );
3538 SetRectRgn( exprgn, 0, 40, 98, 60 );
3539 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3541 /* now test ScrollWindowEx with a combination of
3542 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3543 /* make hwnd2 the child of hwnd1 */
3544 hwnd2 = CreateWindowExA(0, "static", NULL,
3545 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3546 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3547 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3548 GetClientRect( hwnd1, &rc);
3551 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3552 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3553 ValidateRect( hwnd1, NULL);
3554 ValidateRect( hwnd2, NULL);
3555 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3556 SW_SCROLLCHILDREN | SW_INVALIDATE);
3557 if (winetest_debug > 0) dump_region(hrgn);
3558 SetRectRgn( exprgn, 88,0,98,88);
3559 SetRectRgn( tmprgn, 0,88,98,98);
3560 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3561 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3563 /* SW_SCROLLCHILDREN */
3564 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3565 ValidateRect( hwnd1, NULL);
3566 ValidateRect( hwnd2, NULL);
3567 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3568 if (winetest_debug > 0) dump_region(hrgn);
3569 /* expected region is the same as in previous test */
3570 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3572 /* no SW_SCROLLCHILDREN */
3573 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3574 ValidateRect( hwnd1, NULL);
3575 ValidateRect( hwnd2, NULL);
3576 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3577 if (winetest_debug > 0) dump_region(hrgn);
3578 /* expected region is the same as in previous test */
3579 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3581 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3582 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3583 ValidateRect( hwnd1, NULL);
3584 ValidateRect( hwnd2, NULL);
3585 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3586 if (winetest_debug > 0) dump_region(hrgn);
3587 SetRectRgn( exprgn, 88,0,98,20);
3588 SetRectRgn( tmprgn, 20,20,98,30);
3589 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3590 SetRectRgn( tmprgn, 20,30,30,88);
3591 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3592 SetRectRgn( tmprgn, 0,88,30,98);
3593 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3594 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3597 DeleteObject( hrgn);
3598 DeleteObject( exprgn);
3599 DeleteObject( tmprgn);
3600 DestroyWindow( hwnd1);
3601 DestroyWindow( hwnd2);
3604 /* couple of tests of return values of scrollbar functions
3605 * called on a scrollbarless window */
3606 static void test_scroll(void)
3611 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3612 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3613 100, 100, 200, 200, 0, 0, 0, NULL);
3615 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3616 if (!ret) /* win9x */
3618 win_skip( "GetScrollRange doesn't work\n" );
3619 DestroyWindow( hwnd);
3622 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3623 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3624 si.cbSize = sizeof( si);
3625 si.fMask = SIF_PAGE;
3626 si.nPage = 0xdeadbeef;
3627 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3628 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3629 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3631 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3632 ok( ret, "GetScrollRange returns FALSE\n");
3633 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3634 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3635 si.cbSize = sizeof( si);
3636 si.fMask = SIF_PAGE;
3637 si.nPage = 0xdeadbeef;
3638 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3639 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3640 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3642 DestroyWindow( hwnd);
3645 static void test_scrolldc( HWND parent)
3648 HRGN exprgn, tmprgn, hrgn;
3649 RECT rc, rc2, rcu, cliprc;
3653 hrgn = CreateRectRgn(0,0,0,0);
3654 tmprgn = CreateRectRgn(0,0,0,0);
3655 exprgn = CreateRectRgn(0,0,0,0);
3657 hwnd1 = CreateWindowExA(0, "static", NULL,
3658 WS_CHILD| WS_VISIBLE,
3659 25, 50, 100, 100, parent, 0, 0, NULL);
3660 ShowWindow( parent, SW_SHOW);
3661 UpdateWindow( parent);
3662 flush_events( TRUE );
3663 GetClientRect( hwnd1, &rc);
3664 hdc = GetDC( hwnd1);
3665 /* paint the upper half of the window black */
3667 rc2.bottom = ( rc.top + rc.bottom) /2;
3668 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3669 /* clip region is the lower half */
3671 cliprc.top = (rc.top + rc.bottom) /2;
3672 /* test whether scrolled pixels are properly clipped */
3673 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3674 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3675 /* this scroll should not cause any visible changes */
3676 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3677 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3678 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3679 /* test with NULL clip rect */
3680 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3681 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3682 trace("update rect: %d,%d - %d,%d\n",
3683 rcu.left, rcu.top, rcu.right, rcu.bottom);
3684 if (winetest_debug > 0) dump_region(hrgn);
3685 SetRect(&rc2, 0, 0, 100, 100);
3686 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3687 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3689 SetRectRgn( exprgn, 0, 0, 20, 80);
3690 SetRectRgn( tmprgn, 0, 80, 100, 100);
3691 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3692 if (winetest_debug > 0) dump_region(exprgn);
3693 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3694 /* test clip rect > scroll rect */
3695 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3697 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3698 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3699 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3700 SetRectRgn( exprgn, 25, 25, 75, 35);
3701 SetRectRgn( tmprgn, 25, 35, 35, 75);
3702 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3703 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3704 trace("update rect: %d,%d - %d,%d\n",
3705 rcu.left, rcu.top, rcu.right, rcu.bottom);
3706 if (winetest_debug > 0) dump_region(hrgn);
3710 DeleteObject(exprgn);
3711 DeleteObject(tmprgn);
3712 DestroyWindow(hwnd1);
3715 static void test_params(void)
3720 /* Just a param check */
3721 if (pGetMonitorInfoA)
3723 SetLastError(0xdeadbeef);
3724 rc = GetWindowText(hwndMain2, NULL, 1024);
3725 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3729 /* Skips actually on Win95 and NT4 */
3730 win_skip("Test would crash on Win95\n");
3733 SetLastError(0xdeadbeef);
3734 hwnd=CreateWindow("LISTBOX", "TestList",
3735 (LBS_STANDARD & ~LBS_SORT),
3737 NULL, (HMENU)1, NULL, 0);
3739 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3740 "CreateWindow with invalid menu handle should fail\n");
3742 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3743 GetLastError() == 0xdeadbeef, /* Win9x */
3744 "wrong last error value %d\n", GetLastError());
3747 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3751 hwnd = CreateWindowEx(exStyle, class, class, style,
3758 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3761 ShowWindow(hwnd, SW_SHOW);
3763 test_nonclient_area(hwnd);
3766 DestroyWindow(hwnd);
3769 static BOOL AWR_init(void)
3773 class.style = CS_HREDRAW | CS_VREDRAW;
3774 class.lpfnWndProc = DefWindowProcA;
3775 class.cbClsExtra = 0;
3776 class.cbWndExtra = 0;
3777 class.hInstance = 0;
3778 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3779 class.hCursor = LoadCursor (0, IDC_ARROW);
3780 class.hbrBackground = 0;
3781 class.lpszMenuName = 0;
3782 class.lpszClassName = szAWRClass;
3784 if (!RegisterClass (&class)) {
3785 ok(FALSE, "RegisterClass failed\n");
3789 hmenu = CreateMenu();
3792 ok(hmenu != 0, "Failed to create menu\n");
3793 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3799 static void test_AWR_window_size(BOOL menu)
3803 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3806 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3807 WS_HSCROLL, WS_VSCROLL
3811 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3814 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3815 WS_EX_DLGMODALFRAME,
3822 /* A exhaustive check of all the styles takes too long
3823 * so just do a (hopefully representative) sample
3825 for (i = 0; i < COUNTOF(styles); ++i)
3826 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3827 for (i = 0; i < COUNTOF(exStyles); ++i) {
3828 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3829 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3834 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3836 static void test_AdjustWindowRect(void)
3841 SHOWSYSMETRIC(SM_CYCAPTION);
3842 SHOWSYSMETRIC(SM_CYSMCAPTION);
3843 SHOWSYSMETRIC(SM_CYMENU);
3844 SHOWSYSMETRIC(SM_CXEDGE);
3845 SHOWSYSMETRIC(SM_CYEDGE);
3846 SHOWSYSMETRIC(SM_CXVSCROLL);
3847 SHOWSYSMETRIC(SM_CYHSCROLL);
3848 SHOWSYSMETRIC(SM_CXFRAME);
3849 SHOWSYSMETRIC(SM_CYFRAME);
3850 SHOWSYSMETRIC(SM_CXDLGFRAME);
3851 SHOWSYSMETRIC(SM_CYDLGFRAME);
3852 SHOWSYSMETRIC(SM_CXBORDER);
3853 SHOWSYSMETRIC(SM_CYBORDER);
3855 test_AWR_window_size(FALSE);
3856 test_AWR_window_size(TRUE);
3860 #undef SHOWSYSMETRIC
3863 /* Global variables to trigger exit from loop */
3864 static int redrawComplete, WMPAINT_count;
3866 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3871 trace("doing WM_PAINT %d\n", WMPAINT_count);
3873 if (WMPAINT_count > 10 && redrawComplete == 0) {
3875 BeginPaint(hwnd, &ps);
3876 EndPaint(hwnd, &ps);
3881 return DefWindowProc(hwnd, msg, wparam, lparam);
3884 /* Ensure we exit from RedrawNow regardless of invalidated area */
3885 static void test_redrawnow(void)
3890 cls.style = CS_DBLCLKS;
3891 cls.lpfnWndProc = redraw_window_procA;
3894 cls.hInstance = GetModuleHandleA(0);
3896 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3897 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3898 cls.lpszMenuName = NULL;
3899 cls.lpszClassName = "RedrawWindowClass";
3901 if(!RegisterClassA(&cls)) {
3902 trace("Register failed %d\n", GetLastError());
3906 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3907 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3909 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3910 ShowWindow(hwndMain, SW_SHOW);
3911 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3912 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3913 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3914 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3915 redrawComplete = TRUE;
3916 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3919 DestroyWindow( hwndMain);
3922 struct parentdc_stat {
3928 struct parentdc_test {
3929 struct parentdc_stat main, main_todo;
3930 struct parentdc_stat child1, child1_todo;
3931 struct parentdc_stat child2, child2_todo;
3934 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3939 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3944 GetClientRect(hwnd, &rc);
3945 CopyRect(&t->client, &rc);
3946 GetWindowRect(hwnd, &rc);
3947 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3948 t->client.left, t->client.top, t->client.right, t->client.bottom,
3949 rc.left, rc.top, rc.right, rc.bottom);
3950 BeginPaint(hwnd, &ps);
3951 CopyRect(&t->paint, &ps.rcPaint);
3952 GetClipBox(ps.hdc, &rc);
3953 CopyRect(&t->clip, &rc);
3954 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3955 rc.left, rc.top, rc.right, rc.bottom,
3956 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3957 EndPaint(hwnd, &ps);
3960 return DefWindowProc(hwnd, msg, wparam, lparam);
3963 static void zero_parentdc_stat(struct parentdc_stat *t)
3965 SetRectEmpty(&t->client);
3966 SetRectEmpty(&t->clip);
3967 SetRectEmpty(&t->paint);
3970 static void zero_parentdc_test(struct parentdc_test *t)
3972 zero_parentdc_stat(&t->main);
3973 zero_parentdc_stat(&t->child1);
3974 zero_parentdc_stat(&t->child2);
3977 #define parentdc_field_ok(t, w, r, f, got) \
3978 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3979 ": expected %d, got %d\n", \
3982 #define parentdc_todo_field_ok(t, w, r, f, got) \
3983 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3984 else parentdc_field_ok(t, w, r, f, got)
3986 #define parentdc_rect_ok(t, w, r, got) \
3987 parentdc_todo_field_ok(t, w, r, left, got); \
3988 parentdc_todo_field_ok(t, w, r, top, got); \
3989 parentdc_todo_field_ok(t, w, r, right, got); \
3990 parentdc_todo_field_ok(t, w, r, bottom, got);
3992 #define parentdc_win_ok(t, w, got) \
3993 parentdc_rect_ok(t, w, client, got); \
3994 parentdc_rect_ok(t, w, clip, got); \
3995 parentdc_rect_ok(t, w, paint, got);
3997 #define parentdc_ok(t, got) \
3998 parentdc_win_ok(t, main, got); \
3999 parentdc_win_ok(t, child1, got); \
4000 parentdc_win_ok(t, child2, got);
4002 static void test_csparentdc(void)
4004 WNDCLASSA clsMain, cls;
4005 HWND hwndMain, hwnd1, hwnd2;
4008 struct parentdc_test test_answer;
4010 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4011 const struct parentdc_test test1 =
4013 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4014 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4015 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4018 const struct parentdc_test test2 =
4020 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4021 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4022 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4025 const struct parentdc_test test3 =
4027 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4028 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4029 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4032 const struct parentdc_test test4 =
4034 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4035 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4036 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4039 const struct parentdc_test test5 =
4041 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4042 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4043 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4046 const struct parentdc_test test6 =
4048 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4049 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4050 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4053 const struct parentdc_test test7 =
4055 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4056 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4057 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4061 clsMain.style = CS_DBLCLKS;
4062 clsMain.lpfnWndProc = parentdc_window_procA;
4063 clsMain.cbClsExtra = 0;
4064 clsMain.cbWndExtra = 0;
4065 clsMain.hInstance = GetModuleHandleA(0);
4067 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4068 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4069 clsMain.lpszMenuName = NULL;
4070 clsMain.lpszClassName = "ParentDcMainWindowClass";
4072 if(!RegisterClassA(&clsMain)) {
4073 trace("Register failed %d\n", GetLastError());
4077 cls.style = CS_DBLCLKS | CS_PARENTDC;
4078 cls.lpfnWndProc = parentdc_window_procA;
4081 cls.hInstance = GetModuleHandleA(0);
4083 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4084 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4085 cls.lpszMenuName = NULL;
4086 cls.lpszClassName = "ParentDcWindowClass";
4088 if(!RegisterClassA(&cls)) {
4089 trace("Register failed %d\n", GetLastError());
4093 SetRect(&rc, 0, 0, 150, 150);
4094 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4095 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4096 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4097 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4098 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4099 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4100 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4101 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4102 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4103 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4104 ShowWindow(hwndMain, SW_SHOW);
4105 ShowWindow(hwnd1, SW_SHOW);
4106 ShowWindow(hwnd2, SW_SHOW);
4107 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4108 flush_events( TRUE );
4110 zero_parentdc_test(&test_answer);
4111 InvalidateRect(hwndMain, NULL, TRUE);
4112 flush_events( TRUE );
4113 parentdc_ok(test1, test_answer);
4115 zero_parentdc_test(&test_answer);
4116 SetRect(&rc, 0, 0, 50, 50);
4117 InvalidateRect(hwndMain, &rc, TRUE);
4118 flush_events( TRUE );
4119 parentdc_ok(test2, test_answer);
4121 zero_parentdc_test(&test_answer);
4122 SetRect(&rc, 0, 0, 10, 10);
4123 InvalidateRect(hwndMain, &rc, TRUE);
4124 flush_events( TRUE );
4125 parentdc_ok(test3, test_answer);
4127 zero_parentdc_test(&test_answer);
4128 SetRect(&rc, 40, 40, 50, 50);
4129 InvalidateRect(hwndMain, &rc, TRUE);
4130 flush_events( TRUE );
4131 parentdc_ok(test4, test_answer);
4133 zero_parentdc_test(&test_answer);
4134 SetRect(&rc, 20, 20, 60, 60);
4135 InvalidateRect(hwndMain, &rc, TRUE);
4136 flush_events( TRUE );
4137 parentdc_ok(test5, test_answer);
4139 zero_parentdc_test(&test_answer);
4140 SetRect(&rc, 0, 0, 10, 10);
4141 InvalidateRect(hwnd1, &rc, TRUE);
4142 flush_events( TRUE );
4143 parentdc_ok(test6, test_answer);
4145 zero_parentdc_test(&test_answer);
4146 SetRect(&rc, -5, -5, 65, 65);
4147 InvalidateRect(hwnd1, &rc, TRUE);
4148 flush_events( TRUE );
4149 parentdc_ok(test7, test_answer);
4151 DestroyWindow(hwndMain);
4152 DestroyWindow(hwnd1);
4153 DestroyWindow(hwnd2);
4156 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4158 return DefWindowProcA(hwnd, msg, wparam, lparam);
4161 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4163 return DefWindowProcW(hwnd, msg, wparam, lparam);
4166 static void test_IsWindowUnicode(void)
4168 static const char ansi_class_nameA[] = "ansi class name";
4169 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4170 static const char unicode_class_nameA[] = "unicode class name";
4171 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4176 memset(&classW, 0, sizeof(classW));
4177 classW.hInstance = GetModuleHandleA(0);
4178 classW.lpfnWndProc = def_window_procW;
4179 classW.lpszClassName = unicode_class_nameW;
4180 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4182 memset(&classA, 0, sizeof(classA));
4183 classA.hInstance = GetModuleHandleA(0);
4184 classA.lpfnWndProc = def_window_procA;
4185 classA.lpszClassName = ansi_class_nameA;
4186 assert(RegisterClassA(&classA));
4188 /* unicode class: window proc */
4189 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4190 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4193 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4194 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4195 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4196 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4197 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4199 DestroyWindow(hwnd);
4201 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4202 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4205 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4206 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4207 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4208 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4209 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4211 DestroyWindow(hwnd);
4213 /* ansi class: window proc */
4214 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4215 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4218 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4219 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4220 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4221 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4222 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4224 DestroyWindow(hwnd);
4226 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4227 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4230 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4231 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4232 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4233 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4234 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4236 DestroyWindow(hwnd);
4238 /* unicode class: class proc */
4239 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4240 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4243 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4244 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4245 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4246 /* do not restore class window proc back to unicode */
4248 DestroyWindow(hwnd);
4250 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4251 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4254 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4255 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4256 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4258 DestroyWindow(hwnd);
4260 /* ansi class: class proc */
4261 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4262 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4265 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4266 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4267 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4268 /* do not restore class window proc back to ansi */
4270 DestroyWindow(hwnd);
4272 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4273 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4276 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4277 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4278 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4280 DestroyWindow(hwnd);
4283 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4287 if (msg != WM_GETMINMAXINFO)
4288 return DefWindowProc(hwnd, msg, wp, lp);
4290 minmax = (MINMAXINFO *)lp;
4292 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4294 minmax->ptReserved.x = 0;
4295 minmax->ptReserved.y = 0;
4296 minmax->ptMaxSize.x = 400;
4297 minmax->ptMaxSize.y = 400;
4298 minmax->ptMaxPosition.x = 300;
4299 minmax->ptMaxPosition.y = 300;
4300 minmax->ptMaxTrackSize.x = 200;
4301 minmax->ptMaxTrackSize.y = 200;
4302 minmax->ptMinTrackSize.x = 100;
4303 minmax->ptMinTrackSize.y = 100;
4306 DefWindowProc(hwnd, msg, wp, lp);
4310 static int expected_cx, expected_cy;
4311 static RECT expected_rect, broken_rect;
4313 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4317 case WM_GETMINMAXINFO:
4320 GetWindowRect( hwnd, &rect );
4321 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4322 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4323 return DefWindowProc(hwnd, msg, wp, lp);
4328 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4330 GetWindowRect( hwnd, &rect );
4331 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4332 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4333 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4334 "wrong x size %d/%d\n", cs->cx, expected_cx );
4335 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4336 "wrong y size %d/%d\n", cs->cy, expected_cy );
4337 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4338 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4339 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4340 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4341 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4342 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4343 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4344 rect.left, rect.top, rect.right, rect.bottom,
4345 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4346 return DefWindowProc(hwnd, msg, wp, lp);
4350 RECT rect, *r = (RECT *)lp;
4351 GetWindowRect( hwnd, &rect );
4352 ok( !memcmp( &rect, r, sizeof(rect) ),
4353 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4354 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4355 return DefWindowProc(hwnd, msg, wp, lp);
4358 return DefWindowProc(hwnd, msg, wp, lp);
4362 static void test_CreateWindow(void)
4370 #define expect_menu(window, menu) \
4371 SetLastError(0xdeadbeef); \
4372 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4374 #define expect_style(window, style)\
4375 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4377 #define expect_ex_style(window, ex_style)\
4378 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4380 #define expect_gle_broken_9x(gle)\
4381 ok(GetLastError() == gle ||\
4382 broken(GetLastError() == 0xdeadbeef),\
4383 "IsMenu set error %d\n", GetLastError())
4385 hmenu = CreateMenu();
4387 parent = GetDesktopWindow();
4388 assert(parent != 0);
4390 SetLastError(0xdeadbeef);
4391 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4394 SetLastError(0xdeadbeef);
4395 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4396 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4397 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4398 expect_menu(hwnd, 1);
4399 expect_style(hwnd, WS_CHILD);
4400 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4401 DestroyWindow(hwnd);
4403 SetLastError(0xdeadbeef);
4404 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4405 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4406 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4407 expect_menu(hwnd, 1);
4408 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4409 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4410 DestroyWindow(hwnd);
4412 SetLastError(0xdeadbeef);
4413 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4414 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4415 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4416 expect_menu(hwnd, 1);
4417 expect_style(hwnd, WS_CHILD);
4418 expect_ex_style(hwnd, 0);
4419 DestroyWindow(hwnd);
4421 SetLastError(0xdeadbeef);
4422 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4423 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4424 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4425 expect_menu(hwnd, 1);
4426 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4427 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4428 DestroyWindow(hwnd);
4431 SetLastError(0xdeadbeef);
4432 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4433 0, 0, 100, 100, parent, hmenu, 0, NULL);
4434 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4435 expect_menu(hwnd, hmenu);
4436 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4437 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4438 DestroyWindow(hwnd);
4439 SetLastError(0xdeadbeef);
4440 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4441 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4443 hmenu = CreateMenu();
4445 SetLastError(0xdeadbeef);
4446 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4447 0, 0, 100, 100, parent, hmenu, 0, NULL);
4448 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4449 expect_menu(hwnd, hmenu);
4450 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4451 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4452 DestroyWindow(hwnd);
4453 SetLastError(0xdeadbeef);
4454 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4455 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4457 hmenu = CreateMenu();
4459 SetLastError(0xdeadbeef);
4460 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4461 0, 0, 100, 100, parent, hmenu, 0, NULL);
4462 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4463 expect_menu(hwnd, hmenu);
4464 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4465 expect_ex_style(hwnd, 0);
4466 DestroyWindow(hwnd);
4467 SetLastError(0xdeadbeef);
4468 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4469 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4471 hmenu = CreateMenu();
4473 SetLastError(0xdeadbeef);
4474 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4475 0, 0, 100, 100, parent, hmenu, 0, NULL);
4476 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4477 expect_menu(hwnd, hmenu);
4478 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4479 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4480 DestroyWindow(hwnd);
4481 SetLastError(0xdeadbeef);
4482 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4483 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4485 /* WS_CHILD | WS_POPUP */
4486 SetLastError(0xdeadbeef);
4487 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4488 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4489 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4490 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4492 DestroyWindow(hwnd);
4494 hmenu = CreateMenu();
4496 SetLastError(0xdeadbeef);
4497 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4498 0, 0, 100, 100, parent, hmenu, 0, NULL);
4499 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4500 expect_menu(hwnd, hmenu);
4501 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4502 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4503 DestroyWindow(hwnd);
4504 SetLastError(0xdeadbeef);
4505 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4506 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4508 SetLastError(0xdeadbeef);
4509 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4510 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4511 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4512 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4514 DestroyWindow(hwnd);
4516 hmenu = CreateMenu();
4518 SetLastError(0xdeadbeef);
4519 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4520 0, 0, 100, 100, parent, hmenu, 0, NULL);
4521 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4522 expect_menu(hwnd, hmenu);
4523 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4524 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4525 DestroyWindow(hwnd);
4526 SetLastError(0xdeadbeef);
4527 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4528 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4530 SetLastError(0xdeadbeef);
4531 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4532 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4533 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4534 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4536 DestroyWindow(hwnd);
4538 hmenu = CreateMenu();
4540 SetLastError(0xdeadbeef);
4541 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4542 0, 0, 100, 100, parent, hmenu, 0, NULL);
4543 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4544 expect_menu(hwnd, hmenu);
4545 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4546 expect_ex_style(hwnd, 0);
4547 DestroyWindow(hwnd);
4548 SetLastError(0xdeadbeef);
4549 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4550 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4552 SetLastError(0xdeadbeef);
4553 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4554 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4555 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4556 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4558 DestroyWindow(hwnd);
4560 hmenu = CreateMenu();
4562 SetLastError(0xdeadbeef);
4563 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4564 0, 0, 100, 100, parent, hmenu, 0, NULL);
4565 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4566 expect_menu(hwnd, hmenu);
4567 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4568 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4569 DestroyWindow(hwnd);
4570 SetLastError(0xdeadbeef);
4571 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4572 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4574 /* test child window sizing */
4576 cls.lpfnWndProc = minmax_wnd_proc;
4579 cls.hInstance = GetModuleHandle(0);
4581 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4582 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4583 cls.lpszMenuName = NULL;
4584 cls.lpszClassName = "MinMax_WndClass";
4585 RegisterClass(&cls);
4587 SetLastError(0xdeadbeef);
4588 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4589 0, 0, 100, 100, 0, 0, 0, NULL);
4590 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4591 expect_menu(parent, 0);
4592 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4593 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4595 memset(&minmax, 0, sizeof(minmax));
4596 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4597 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4598 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4599 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4600 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4602 GetWindowRect(parent, &rc);
4603 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4604 GetClientRect(parent, &rc);
4605 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4607 InflateRect(&rc, 200, 200);
4608 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4610 SetLastError(0xdeadbeef);
4611 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4612 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4613 parent, (HMENU)1, 0, NULL);
4614 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4615 expect_menu(hwnd, 1);
4616 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4617 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4619 memset(&minmax, 0, sizeof(minmax));
4620 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4621 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4623 GetWindowRect(hwnd, &rc);
4624 OffsetRect(&rc, -rc.left, -rc.top);
4625 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4626 rc.left, rc.top, rc.right, rc.bottom,
4627 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4628 DestroyWindow(hwnd);
4630 cls.lpfnWndProc = winsizes_wnd_proc;
4631 cls.lpszClassName = "Sizes_WndClass";
4632 RegisterClass(&cls);
4634 expected_cx = expected_cy = 200000;
4635 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4636 broken_rect = expected_rect;
4637 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4638 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4639 GetClientRect( hwnd, &rc );
4640 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4641 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4642 DestroyWindow(hwnd);
4644 expected_cx = expected_cy = -10;
4645 SetRect( &expected_rect, 0, 0, 0, 0 );
4646 SetRect( &broken_rect, 0, 0, -10, -10 );
4647 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4648 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4649 GetClientRect( hwnd, &rc );
4650 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4651 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4652 DestroyWindow(hwnd);
4654 expected_cx = expected_cy = -200000;
4655 SetRect( &expected_rect, 0, 0, 0, 0 );
4656 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4657 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4658 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4659 GetClientRect( hwnd, &rc );
4660 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4661 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4662 DestroyWindow(hwnd);
4664 /* we need a parent at 0,0 so that child coordinates match */
4665 DestroyWindow(parent);
4666 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4667 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4670 expected_cy = 0x7fffffff;
4671 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4672 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4673 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4674 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4675 GetClientRect( hwnd, &rc );
4676 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4677 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4678 DestroyWindow(hwnd);
4680 expected_cx = 0x7fffffff;
4681 expected_cy = 0x7fffffff;
4682 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4683 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4684 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4685 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4686 GetClientRect( hwnd, &rc );
4687 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4688 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4689 DestroyWindow(hwnd);
4691 /* top level window */
4692 expected_cx = expected_cy = 200000;
4693 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4694 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4695 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4696 GetClientRect( hwnd, &rc );
4697 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4698 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4699 DestroyWindow(hwnd);
4701 DestroyWindow(parent);
4703 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4704 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4706 #undef expect_gle_broken_9x
4709 #undef expect_ex_style
4712 /* function that remembers whether the system the test is running on sets the
4713 * last error for user32 functions to make the tests stricter */
4714 static int check_error(DWORD actual, DWORD expected)
4716 static int sets_last_error = -1;
4717 if (sets_last_error == -1)
4718 sets_last_error = (actual != 0xdeadbeef);
4719 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4722 static void test_SetWindowLong(void)
4725 WNDPROC old_window_procW;
4727 SetLastError(0xdeadbeef);
4728 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4729 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4730 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4731 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4733 SetLastError(0xdeadbeef);
4734 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4735 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4736 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4737 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4739 SetLastError(0xdeadbeef);
4740 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4741 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4742 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4743 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4744 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4745 ok((WNDPROC)retval == main_window_procA,
4746 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4747 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4749 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4750 SetLastError(0xdeadbeef);
4751 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4752 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4754 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4755 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4756 ok((WNDPROC)retval == old_window_procW,
4757 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4758 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4760 /* set it back to ANSI */
4761 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4765 static void test_ShowWindow(void)
4772 SetRect(&rcMain, 120, 120, 210, 210);
4774 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4775 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4776 WS_MAXIMIZEBOX | WS_POPUP,
4777 rcMain.left, rcMain.top,
4778 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4782 style = GetWindowLong(hwnd, GWL_STYLE);
4783 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4784 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4785 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4786 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4787 GetWindowRect(hwnd, &rc);
4788 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4789 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4790 rc.left, rc.top, rc.right, rc.bottom);
4792 ret = ShowWindow(hwnd, SW_SHOW);
4793 ok(!ret, "not expected ret: %lu\n", ret);
4794 style = GetWindowLong(hwnd, GWL_STYLE);
4795 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4796 ok(style & WS_VISIBLE, "window should be visible\n");
4797 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4798 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4799 GetWindowRect(hwnd, &rc);
4800 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4801 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4802 rc.left, rc.top, rc.right, rc.bottom);
4804 ret = ShowWindow(hwnd, SW_MINIMIZE);
4805 ok(ret, "not expected ret: %lu\n", ret);
4806 style = GetWindowLong(hwnd, GWL_STYLE);
4807 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4808 ok(style & WS_VISIBLE, "window should be visible\n");
4809 ok(style & WS_MINIMIZE, "window should be minimized\n");
4810 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4811 GetWindowRect(hwnd, &rc);
4812 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4814 ShowWindow(hwnd, SW_RESTORE);
4815 ok(ret, "not expected ret: %lu\n", ret);
4816 style = GetWindowLong(hwnd, GWL_STYLE);
4817 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4818 ok(style & WS_VISIBLE, "window should be visible\n");
4819 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4820 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4821 GetWindowRect(hwnd, &rc);
4822 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4823 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4824 rc.left, rc.top, rc.right, rc.bottom);
4826 ret = EnableWindow(hwnd, FALSE);
4827 ok(!ret, "not expected ret: %lu\n", ret);
4828 style = GetWindowLong(hwnd, GWL_STYLE);
4829 ok(style & WS_DISABLED, "window should be disabled\n");
4831 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4832 ok(!ret, "not expected ret: %lu\n", ret);
4833 style = GetWindowLong(hwnd, GWL_STYLE);
4834 ok(style & WS_DISABLED, "window should be disabled\n");
4835 ok(style & WS_VISIBLE, "window should be visible\n");
4836 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4837 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4838 GetWindowRect(hwnd, &rc);
4839 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4840 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4841 rc.left, rc.top, rc.right, rc.bottom);
4843 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4844 ok(!ret, "not expected ret: %lu\n", ret);
4845 style = GetWindowLong(hwnd, GWL_STYLE);
4846 ok(style & WS_DISABLED, "window should be disabled\n");
4847 ok(style & WS_VISIBLE, "window should be visible\n");
4848 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4849 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4850 GetWindowRect(hwnd, &rc);
4851 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4852 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4853 rc.left, rc.top, rc.right, rc.bottom);
4855 ret = ShowWindow(hwnd, SW_MINIMIZE);
4856 ok(ret, "not expected ret: %lu\n", ret);
4857 style = GetWindowLong(hwnd, GWL_STYLE);
4858 ok(style & WS_DISABLED, "window should be disabled\n");
4859 ok(style & WS_VISIBLE, "window should be visible\n");
4860 ok(style & WS_MINIMIZE, "window should be minimized\n");
4861 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4862 GetWindowRect(hwnd, &rc);
4863 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4865 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4866 ok(!ret, "not expected ret: %lu\n", ret);
4867 style = GetWindowLong(hwnd, GWL_STYLE);
4868 ok(style & WS_DISABLED, "window should be disabled\n");
4869 ok(style & WS_VISIBLE, "window should be visible\n");
4870 ok(style & WS_MINIMIZE, "window should be minimized\n");
4871 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4872 GetWindowRect(hwnd, &rc);
4873 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4875 ret = ShowWindow(hwnd, SW_RESTORE);
4876 ok(ret, "not expected ret: %lu\n", ret);
4877 style = GetWindowLong(hwnd, GWL_STYLE);
4878 ok(style & WS_DISABLED, "window should be disabled\n");
4879 ok(style & WS_VISIBLE, "window should be visible\n");
4880 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4881 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4882 GetWindowRect(hwnd, &rc);
4883 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4884 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4885 rc.left, rc.top, rc.right, rc.bottom);
4887 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4888 ok(!ret, "not expected ret: %lu\n", ret);
4889 ok(IsWindow(hwnd), "window should exist\n");
4891 ret = EnableWindow(hwnd, TRUE);
4892 ok(ret, "not expected ret: %lu\n", ret);
4894 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4895 ok(!ret, "not expected ret: %lu\n", ret);
4896 ok(!IsWindow(hwnd), "window should not exist\n");
4899 static void test_gettext(void)
4902 LPCSTR clsname = "gettexttest";
4906 memset( &cls, 0, sizeof cls );
4907 cls.lpfnWndProc = DefWindowProc;
4908 cls.lpszClassName = clsname;
4909 cls.hInstance = GetModuleHandle(NULL);
4911 if (!RegisterClass( &cls )) return;
4913 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4914 ok( hwnd != NULL, "window was null\n");
4916 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4917 ok( r == 0, "settext should return zero\n");
4919 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4920 ok( r == 0, "settext should return zero (%ld)\n", r);
4922 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4923 ok( r == 0, "settext should return zero (%ld)\n", r);
4925 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4926 ok( r == 0, "settext should return zero (%ld)\n", r);
4928 DestroyWindow(hwnd);
4929 UnregisterClass( clsname, NULL );
4933 static void test_GetUpdateRect(void)
4936 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4938 HWND hgrandparent, hparent, hchild;
4940 static const char classNameA[] = "GetUpdateRectClass";
4942 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4943 0, 0, 100, 100, NULL, NULL, 0, NULL);
4945 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4946 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4948 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4949 10, 10, 30, 30, hparent, NULL, 0, NULL);
4951 ShowWindow(hgrandparent, SW_SHOW);
4952 UpdateWindow(hgrandparent);
4953 flush_events( TRUE );
4955 ShowWindow(hchild, SW_HIDE);
4956 SetRect(&rc2, 0, 0, 0, 0);
4957 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4958 ok(!ret, "GetUpdateRect returned not empty region\n");
4959 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4960 rc1.left, rc1.top, rc1.right, rc1.bottom,
4961 rc2.left, rc2.top, rc2.right, rc2.bottom);
4963 SetRect(&rc2, 10, 10, 40, 40);
4964 ret = GetUpdateRect(hparent, &rc1, FALSE);
4965 ok(ret, "GetUpdateRect returned empty region\n");
4966 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4967 rc1.left, rc1.top, rc1.right, rc1.bottom,
4968 rc2.left, rc2.top, rc2.right, rc2.bottom);
4970 parent_wm_paint = FALSE;
4971 grandparent_wm_paint = FALSE;
4972 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4974 if (msg.message == WM_PAINT)
4976 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4977 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4979 DispatchMessage(&msg);
4981 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4982 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4984 DestroyWindow(hgrandparent);
4987 cls.lpfnWndProc = DefWindowProcA;
4990 cls.hInstance = GetModuleHandleA(0);
4992 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4993 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4994 cls.lpszMenuName = NULL;
4995 cls.lpszClassName = classNameA;
4997 if(!RegisterClassA(&cls)) {
4998 trace("Register failed %d\n", GetLastError());
5002 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5003 0, 0, 100, 100, NULL, NULL, 0, NULL);
5005 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5006 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5008 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5009 10, 10, 30, 30, hparent, NULL, 0, NULL);
5011 ShowWindow(hgrandparent, SW_SHOW);
5012 UpdateWindow(hgrandparent);
5013 flush_events( TRUE );
5015 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5016 ok(!ret, "GetUpdateRect returned not empty region\n");
5018 ShowWindow(hchild, SW_HIDE);
5020 SetRect(&rc2, 0, 0, 0, 0);
5021 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5022 ok(!ret, "GetUpdateRect returned not empty region\n");
5023 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5024 rc1.left, rc1.top, rc1.right, rc1.bottom,
5025 rc2.left, rc2.top, rc2.right, rc2.bottom);
5027 SetRect(&rc2, 10, 10, 40, 40);
5028 ret = GetUpdateRect(hparent, &rc1, FALSE);
5029 ok(ret, "GetUpdateRect returned empty region\n");
5030 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5031 rc1.left, rc1.top, rc1.right, rc1.bottom,
5032 rc2.left, rc2.top, rc2.right, rc2.bottom);
5034 parent_wm_paint = FALSE;
5035 grandparent_wm_paint = FALSE;
5036 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5038 if (msg.message == WM_PAINT)
5040 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5041 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5043 DispatchMessage(&msg);
5045 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5046 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5048 DestroyWindow(hgrandparent);
5052 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5060 const int waitTime = 2000;
5062 BeginPaint(hwnd, &ps);
5064 /* create and destroy window to create an exposed region on this window */
5065 win = CreateWindowA("static", "win", WS_VISIBLE,
5066 10,10,50,50, NULL, NULL, 0, NULL);
5069 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5071 ValidateRect(hwnd, NULL);
5072 EndPaint(hwnd, &ps);
5074 if(waitResult != WAIT_TIMEOUT)
5076 GetUpdateRect(hwnd, &updateRect, FALSE);
5077 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5082 return DefWindowProc(hwnd, msg, wParam, lParam);
5085 static void test_Expose(void)
5090 memset(&cls, 0, sizeof(WNDCLASSA));
5091 cls.lpfnWndProc = TestExposedRegion_WndProc;
5092 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5093 cls.lpszClassName = "TestExposeClass";
5094 atom = RegisterClassA(&cls);
5096 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5097 0, 0, 200, 100, NULL, NULL, 0, NULL);
5103 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5105 static UINT ncredrawflags;
5111 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5114 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5117 BeginPaint(hwnd, &ps);
5118 EndPaint(hwnd, &ps);
5121 return DefWindowProc(hwnd, msg, wParam, lParam);
5124 static void run_NCRedrawLoop(UINT flags)
5131 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5132 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5133 NULL, NULL, 0, &flags);
5134 ShowWindow(hwnd, SW_SHOW);
5136 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5138 if (msg.message == WM_PAINT) loopcount++;
5139 if (loopcount >= 100) break;
5140 TranslateMessage(&msg);
5141 DispatchMessage(&msg);
5142 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5144 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5145 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5147 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5148 DestroyWindow(hwnd);
5151 static void test_NCRedraw(void)
5155 wndclass.lpszClassName = "TestNCRedrawClass";
5156 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5157 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5158 wndclass.cbClsExtra = 0;
5159 wndclass.cbWndExtra = 0;
5160 wndclass.hInstance = 0;
5161 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5162 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5163 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5164 wndclass.lpszMenuName = NULL;
5166 RegisterClassA(&wndclass);
5168 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5169 run_NCRedrawLoop(RDW_INVALIDATE);
5172 static void test_GetWindowModuleFileName(void)
5177 char buf1[MAX_PATH], buf2[MAX_PATH];
5179 if (!pGetWindowModuleFileNameA)
5181 win_skip("GetWindowModuleFileNameA is not available\n");
5185 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5188 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5189 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5192 SetLastError(0xdeadbeef);
5193 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5194 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5197 SetLastError(0xdeadbeef);
5198 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5199 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5200 "GetWindowModuleFileNameA error %u\n", GetLastError());
5204 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5205 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5207 hinst = GetModuleHandle(0);
5209 SetLastError(0xdeadbeef);
5210 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5211 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5212 "expected %u, got %u\n", ret1 - 2, ret2);
5213 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5214 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5215 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5217 SetLastError(0xdeadbeef);
5218 ret2 = GetModuleFileName(hinst, buf2, 0);
5219 ok(!ret2, "GetModuleFileName should return 0\n");
5220 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5221 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5222 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5224 SetLastError(0xdeadbeef);
5225 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5226 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5227 "expected %u, got %u\n", ret1 - 2, ret2);
5228 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5229 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5230 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5232 SetLastError(0xdeadbeef);
5233 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5234 ok(!ret2, "expected 0, got %u\n", ret2);
5235 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5236 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5237 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5239 DestroyWindow(hwnd);
5242 hwnd = (HWND)0xdeadbeef;
5243 SetLastError(0xdeadbeef);
5244 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5245 ok(!ret1, "expected 0, got %u\n", ret1);
5246 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5247 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5249 hwnd = FindWindow("Shell_TrayWnd", NULL);
5250 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5251 SetLastError(0xdeadbeef);
5252 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5253 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5255 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5257 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5258 hwnd = GetDesktopWindow();
5259 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5260 SetLastError(0xdeadbeef);
5261 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5263 ret1 == ret2 || /* vista */
5264 broken(ret2), /* some win98 return user.exe as file name */
5265 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5269 static void test_hwnd_message(void)
5271 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5272 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5274 HWND parent = 0, hwnd, found;
5277 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5278 on CreateWindowExA and crash later in the test.
5279 Use UNICODE here to fail on win9x */
5280 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5281 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5284 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5288 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5292 HWND root, desktop = GetDesktopWindow();
5294 parent = pGetAncestor(hwnd, GA_PARENT);
5295 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5296 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5297 root = pGetAncestor(hwnd, GA_ROOT);
5298 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5299 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5300 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5301 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5302 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5303 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5304 GetWindowRect( parent, &rect );
5305 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5306 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5308 GetWindowRect( hwnd, &rect );
5309 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5310 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5312 /* test FindWindow behavior */
5314 found = FindWindowExA( 0, 0, 0, "message window" );
5315 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5316 SetLastError(0xdeadbeef);
5317 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5318 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5319 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5322 found = FindWindowExA( parent, 0, 0, "message window" );
5323 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5326 /* test IsChild behavior */
5328 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5330 /* test IsWindowVisible behavior */
5332 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5333 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5335 DestroyWindow(hwnd);
5338 static void test_layered_window(void)
5346 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5348 win_skip( "layered windows not supported\n" );
5351 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5352 100, 100, 200, 200, 0, 0, 0, NULL);
5354 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5355 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5356 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5357 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5358 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5359 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5360 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5361 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5362 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5363 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5364 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5365 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5366 ok( alpha == 44, "wrong alpha %u\n", alpha );
5367 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5369 /* clearing WS_EX_LAYERED resets attributes */
5370 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5371 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5372 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5373 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5374 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5375 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5376 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5377 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5378 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5379 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5380 ok( key == 0x654321, "wrong color key %x\n", key );
5381 ok( alpha == 22, "wrong alpha %u\n", alpha );
5382 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5384 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5385 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5387 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5388 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5389 ok( key == 0x888888, "wrong color key %x\n", key );
5390 /* alpha not changed on vista if LWA_ALPHA is not set */
5391 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5392 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5394 /* color key may or may not be changed without LWA_COLORKEY */
5395 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5396 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5398 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5399 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5400 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5401 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5402 ok( flags == 0, "wrong flags %x\n", flags );
5404 /* default alpha and color key is 0 */
5405 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5406 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5407 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5408 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5409 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5410 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5411 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5412 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5413 ok( flags == 0, "wrong flags %x\n", flags );
5415 DestroyWindow( hwnd );
5418 static MONITORINFO mi;
5420 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5426 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5427 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5428 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5429 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5430 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5431 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5432 cs->x, cs->y, cs->cx, cs->cy);
5435 case WM_GETMINMAXINFO:
5437 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5438 dump_minmax_info(minmax);
5439 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5440 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5441 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5442 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5446 return DefWindowProc(hwnd, msg, wp, lp);
5449 static void test_fullscreen(void)
5451 static const DWORD t_style[] = {
5452 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5454 static const DWORD t_ex_style[] = {
5455 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5465 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5467 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5472 SetLastError(0xdeadbeef);
5473 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5474 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5476 mi.cbSize = sizeof(mi);
5477 SetLastError(0xdeadbeef);
5478 ret = pGetMonitorInfoA(hmon, &mi);
5479 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5480 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5481 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5482 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5485 cls.lpfnWndProc = fullscreen_wnd_proc;
5488 cls.hInstance = GetModuleHandle(0);
5490 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5491 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5492 cls.lpszMenuName = NULL;
5493 cls.lpszClassName = "fullscreen_class";
5494 RegisterClass(&cls);
5496 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5498 DWORD style, ex_style;
5500 /* avoid a WM interaction */
5501 assert(!(t_style[i] & WS_VISIBLE));
5503 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5508 ex_style = t_ex_style[j];
5510 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5511 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5512 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5513 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5514 GetWindowRect(hwnd, &rc);
5515 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5516 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5517 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5518 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5519 DestroyWindow(hwnd);
5521 style = t_style[i] | WS_MAXIMIZE;
5522 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5523 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5524 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5525 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5526 GetWindowRect(hwnd, &rc);
5527 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5528 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5529 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5530 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5531 DestroyWindow(hwnd);
5533 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5534 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5535 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5536 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5537 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5538 GetWindowRect(hwnd, &rc);
5539 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5540 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5541 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5542 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5543 DestroyWindow(hwnd);
5545 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5546 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5547 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5548 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5549 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5550 GetWindowRect(hwnd, &rc);
5551 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5552 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5553 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5554 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5555 DestroyWindow(hwnd);
5557 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5558 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5559 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5560 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5561 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5562 GetWindowRect(hwnd, &rc);
5563 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5564 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5565 fixup = min(abs(rc.left), abs(rc.top));
5566 InflateRect(&rc, -fixup, -fixup);
5567 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5568 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5569 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5570 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5571 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5572 DestroyWindow(hwnd);
5574 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5575 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5576 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5577 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5578 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5579 GetWindowRect(hwnd, &rc);
5580 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5581 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5582 fixup = min(abs(rc.left), abs(rc.top));
5583 InflateRect(&rc, -fixup, -fixup);
5584 if (style & (WS_CHILD | WS_POPUP))
5585 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5586 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5587 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5589 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5590 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5591 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5592 DestroyWindow(hwnd);
5596 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5599 static BOOL test_thick_child_got_minmax;
5600 static const char * test_thick_child_name;
5601 static LONG test_thick_child_style;
5602 static LONG test_thick_child_exStyle;
5604 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5607 int expectedMinTrackX;
5608 int expectedMinTrackY;
5609 int actualMinTrackX;
5610 int actualMinTrackY;
5611 int expectedMaxTrackX;
5612 int expectedMaxTrackY;
5613 int actualMaxTrackX;
5614 int actualMaxTrackY;
5615 int expectedMaxSizeX;
5616 int expectedMaxSizeY;
5627 case WM_GETMINMAXINFO:
5629 minmax = (MINMAXINFO *)lparam;
5630 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5631 dump_minmax_info( minmax );
5633 test_thick_child_got_minmax = TRUE;
5636 adjustedStyle = test_thick_child_style;
5637 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5638 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5639 GetClientRect(GetParent(hwnd), &rect);
5640 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5642 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5644 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5645 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5649 expectedMinTrackX = -2 * rect.left;
5650 expectedMinTrackY = -2 * rect.top;
5652 actualMinTrackX = minmax->ptMinTrackSize.x;
5653 actualMinTrackY = minmax->ptMinTrackSize.y;
5655 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5656 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5657 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5658 test_thick_child_name);
5660 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5661 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5662 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5663 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5664 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5665 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5666 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5667 test_thick_child_name);
5669 expectedMaxSizeX = rect.right - rect.left;
5670 expectedMaxSizeY = rect.bottom - rect.top;
5671 actualMaxSizeX = minmax->ptMaxSize.x;
5672 actualMaxSizeY = minmax->ptMaxSize.y;
5674 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5675 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5676 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5677 test_thick_child_name);
5680 expectedPosX = rect.left;
5681 expectedPosY = rect.top;
5682 actualPosX = minmax->ptMaxPosition.x;
5683 actualPosY = minmax->ptMaxPosition.y;
5684 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5685 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5686 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5692 return DefWindowProcA(hwnd, msg, wparam, lparam);
5695 #define NUMBER_OF_THICK_CHILD_TESTS 16
5696 static void test_thick_child_size(HWND parentWindow)
5700 RECT adjustedParentRect;
5705 LONG expectedHeight;
5707 LPCTSTR className = "THICK_CHILD_CLASS";
5710 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5711 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5712 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5713 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5714 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5715 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5716 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5717 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5718 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5719 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5720 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5721 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5722 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5723 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5724 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5725 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5726 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5729 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5734 WS_EX_DLGMODALFRAME,
5735 WS_EX_DLGMODALFRAME,
5736 WS_EX_DLGMODALFRAME,
5737 WS_EX_DLGMODALFRAME,
5742 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5743 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5744 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5745 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5747 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5748 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5749 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5750 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5751 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5752 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5753 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5754 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5755 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5756 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5757 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5758 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5759 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5760 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5761 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5762 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5763 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5767 cls.lpfnWndProc = test_thick_child_size_winproc;
5770 cls.hInstance = GetModuleHandleA(0);
5772 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5773 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5774 cls.lpszMenuName = NULL;
5775 cls.lpszClassName = className;
5776 SetLastError(0xdeadbeef);
5777 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5779 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5781 test_thick_child_name = styleName[i];
5782 test_thick_child_style = styles[i];
5783 test_thick_child_exStyle = exStyles[i];
5784 test_thick_child_got_minmax = FALSE;
5786 SetLastError(0xdeadbeef);
5787 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5788 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5790 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5792 SetLastError(0xdeadbeef);
5793 success = GetWindowRect(childWindow, &childRect);
5794 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5795 childWidth = childRect.right - childRect.left;
5796 childHeight = childRect.bottom - childRect.top;
5798 adjustedStyle = styles[i];
5799 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5800 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5801 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5802 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5805 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5807 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5808 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5812 expectedWidth = -2 * adjustedParentRect.left;
5813 expectedHeight = -2 * adjustedParentRect.top;
5816 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5817 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5818 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5820 SetLastError(0xdeadbeef);
5821 success = DestroyWindow(childWindow);
5822 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5824 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5827 static void test_handles( HWND full_hwnd )
5829 HWND hwnd = full_hwnd;
5833 SetLastError( 0xdeadbeef );
5834 ret = GetWindowRect( hwnd, &rect );
5835 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5838 if ((ULONG_PTR)full_hwnd >> 32)
5839 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5841 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5842 SetLastError( 0xdeadbeef );
5843 ret = GetWindowRect( hwnd, &rect );
5844 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5846 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5847 SetLastError( 0xdeadbeef );
5848 ret = GetWindowRect( hwnd, &rect );
5849 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5851 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5852 SetLastError( 0xdeadbeef );
5853 ret = GetWindowRect( hwnd, &rect );
5854 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5855 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5857 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5858 SetLastError( 0xdeadbeef );
5859 ret = GetWindowRect( hwnd, &rect );
5860 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5861 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5865 static void test_winregion(void)
5872 if (!pGetWindowRgnBox)
5874 win_skip("GetWindowRgnBox not supported\n");
5878 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
5880 SetLastError(0xdeadbeef);
5881 ret = pGetWindowRgnBox(hwnd, NULL);
5882 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5883 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5885 hrgn = CreateRectRgn(2, 3, 10, 15);
5886 ok( hrgn != NULL, "Region creation failed\n");
5889 SetWindowRgn(hwnd, hrgn, FALSE);
5891 SetLastError(0xdeadbeef);
5892 ret = pGetWindowRgnBox(hwnd, NULL);
5893 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5894 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5896 r.left = r.top = r.right = r.bottom = 0;
5897 ret = pGetWindowRgnBox(hwnd, &r);
5898 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
5899 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
5900 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
5904 DestroyWindow(hwnd);
5909 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5910 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5911 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5912 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5913 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5914 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5915 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5916 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5917 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
5918 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
5920 if (!RegisterWindowClasses()) assert(0);
5922 SetLastError(0xdeafbeef);
5923 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
5924 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
5926 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5927 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5929 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5930 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5931 WS_MAXIMIZEBOX | WS_POPUP,
5933 0, 0, GetModuleHandle(0), NULL);
5934 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5935 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5936 WS_MAXIMIZEBOX | WS_POPUP,
5938 0, 0, GetModuleHandle(0), NULL);
5940 assert( hwndMain2 );
5942 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5944 /* Add the tests below this line */
5945 test_thick_child_size(hwndMain);
5947 test_hwnd_message();
5948 test_nonclient_area(hwndMain);
5950 test_GetWindowModuleFileName();
5953 test_capture_3(hwndMain, hwndMain2);
5956 test_CreateWindow();
5957 test_parent_owner();
5959 test_enum_thread_windows();
5963 test_SetWindowPos(hwndMain);
5964 test_SetMenu(hwndMain);
5965 test_SetFocus(hwndMain);
5966 test_SetActiveWindow(hwndMain);
5969 test_children_zorder(hwndMain);
5970 test_popup_zorder(hwndMain2, hwndMain);
5971 test_keyboard_input(hwndMain);
5972 test_mouse_input(hwndMain);
5973 test_validatergn(hwndMain);
5974 test_nccalcscroll( hwndMain);
5975 test_scrollwindow( hwndMain);
5976 test_scrollvalidate( hwndMain);
5977 test_scrolldc( hwndMain);
5979 test_IsWindowUnicode();
5980 test_vis_rgn(hwndMain);
5982 test_AdjustWindowRect();
5983 test_window_styles();
5986 test_SetWindowLong();
5988 if (0) test_gettext(); /* crashes on NT4 */
5989 test_GetUpdateRect();
5991 test_layered_window();
5993 test_SetForegroundWindow(hwndMain);
5994 test_shell_window();
5995 test_handles( hwndMain );
5998 /* add the tests above this line */
5999 if (hhook) UnhookWindowsHookEx(hhook);
6001 DestroyWindow(hwndMain2);
6002 DestroyWindow(hwndMain);