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 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
68 static void dump_minmax_info( const MINMAXINFO *minmax )
70 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
71 minmax->ptReserved.x, minmax->ptReserved.y,
72 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
73 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
74 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
75 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
78 /* try to make sure pending X events have been processed before continuing */
79 static void flush_events( BOOL remove_messages )
83 int min_timeout = 100;
84 DWORD time = GetTickCount() + diff;
88 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
90 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
91 diff = time - GetTickCount();
96 /* check the values returned by the various parent/owner functions on a given window */
97 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
98 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
104 res = pGetAncestor( hwnd, GA_PARENT );
105 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
107 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
108 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
109 res = GetParent( hwnd );
110 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
111 res = GetWindow( hwnd, GW_OWNER );
112 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
115 res = pGetAncestor( hwnd, GA_ROOT );
116 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
117 res = pGetAncestor( hwnd, GA_ROOTOWNER );
118 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
122 static BOOL ignore_message( UINT message )
124 /* these are always ignored */
125 return (message >= 0xc000 ||
126 message == WM_GETICON ||
127 message == WM_GETOBJECT ||
128 message == WM_TIMECHANGE ||
129 message == WM_DEVICECHANGE);
132 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
135 trace("EnumChildProc on %p\n", hwndChild);
136 if (*(LPINT)lParam > 1) return FALSE;
140 /* will search for the given window */
141 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
143 trace("EnumChildProc1 on %p\n", hwndChild);
144 if ((HWND)lParam == hwndChild) return FALSE;
148 static HWND create_tool_window( LONG style, HWND parent )
150 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
151 0, 0, 100, 100, parent, 0, 0, NULL );
152 ok( ret != 0, "Creation failed\n" );
156 /* test parent and owner values for various combinations */
157 static void test_parent_owner(void)
160 HWND test, owner, ret;
161 HWND desktop = GetDesktopWindow();
162 HWND child = create_tool_window( WS_CHILD, hwndMain );
165 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
167 /* child without parent, should fail */
168 SetLastError(0xdeadbeef);
169 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
170 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
171 ok( !test, "WS_CHILD without parent created\n" );
172 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
173 broken(GetLastError() == 0xdeadbeef), /* win9x */
174 "CreateWindowExA error %u\n", GetLastError() );
177 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
178 style = GetWindowLongA( desktop, GWL_STYLE );
179 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
180 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
181 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
183 /* normal child window */
184 test = create_tool_window( WS_CHILD, hwndMain );
185 trace( "created child %p\n", test );
186 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
187 SetWindowLongA( test, GWL_STYLE, 0 );
188 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
189 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
190 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
191 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
192 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
193 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
194 DestroyWindow( test );
196 /* normal child window with WS_MAXIMIZE */
197 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
198 DestroyWindow( test );
200 /* normal child window with WS_THICKFRAME */
201 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
202 DestroyWindow( test );
204 /* popup window with WS_THICKFRAME */
205 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
206 DestroyWindow( test );
208 /* child of desktop */
209 test = create_tool_window( WS_CHILD, desktop );
210 trace( "created child of desktop %p\n", test );
211 check_parents( test, desktop, 0, desktop, 0, test, desktop );
212 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
213 check_parents( test, desktop, 0, 0, 0, test, test );
214 SetWindowLongA( test, GWL_STYLE, 0 );
215 check_parents( test, desktop, 0, 0, 0, test, test );
216 DestroyWindow( test );
218 /* child of desktop with WS_MAXIMIZE */
219 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
220 DestroyWindow( test );
222 /* child of desktop with WS_MINIMIZE */
223 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
224 DestroyWindow( test );
227 test = create_tool_window( WS_CHILD, child );
228 trace( "created child of child %p\n", test );
229 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
230 SetWindowLongA( test, GWL_STYLE, 0 );
231 check_parents( test, child, child, 0, 0, hwndMain, test );
232 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
233 check_parents( test, child, child, 0, 0, hwndMain, test );
234 DestroyWindow( test );
236 /* child of child with WS_MAXIMIZE */
237 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
238 DestroyWindow( test );
240 /* child of child with WS_MINIMIZE */
241 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
242 DestroyWindow( test );
244 /* not owned top-level window */
245 test = create_tool_window( 0, 0 );
246 trace( "created top-level %p\n", test );
247 check_parents( test, desktop, 0, 0, 0, test, test );
248 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
249 check_parents( test, desktop, 0, 0, 0, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
251 check_parents( test, desktop, 0, desktop, 0, test, desktop );
252 DestroyWindow( test );
254 /* not owned top-level window with WS_MAXIMIZE */
255 test = create_tool_window( WS_MAXIMIZE, 0 );
256 DestroyWindow( test );
258 /* owned top-level window */
259 test = create_tool_window( 0, hwndMain );
260 trace( "created owned top-level %p\n", test );
261 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
262 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
263 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
266 DestroyWindow( test );
268 /* owned top-level window with WS_MAXIMIZE */
269 test = create_tool_window( WS_MAXIMIZE, hwndMain );
270 DestroyWindow( test );
272 /* not owned popup */
273 test = create_tool_window( WS_POPUP, 0 );
274 trace( "created popup %p\n", test );
275 check_parents( test, desktop, 0, 0, 0, test, test );
276 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
277 check_parents( test, desktop, 0, desktop, 0, test, desktop );
278 SetWindowLongA( test, GWL_STYLE, 0 );
279 check_parents( test, desktop, 0, 0, 0, test, test );
280 DestroyWindow( test );
282 /* not owned popup with WS_MAXIMIZE */
283 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
284 DestroyWindow( test );
287 test = create_tool_window( WS_POPUP, hwndMain );
288 trace( "created owned popup %p\n", test );
289 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
290 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
291 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
292 SetWindowLongA( test, GWL_STYLE, 0 );
293 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
294 DestroyWindow( test );
296 /* owned popup with WS_MAXIMIZE */
297 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
298 DestroyWindow( test );
300 /* top-level window owned by child (same as owned by top-level) */
301 test = create_tool_window( 0, child );
302 trace( "created top-level owned by child %p\n", test );
303 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
304 DestroyWindow( test );
306 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
307 test = create_tool_window( WS_MAXIMIZE, child );
308 DestroyWindow( test );
310 /* popup owned by desktop (same as not owned) */
311 test = create_tool_window( WS_POPUP, desktop );
312 trace( "created popup owned by desktop %p\n", test );
313 check_parents( test, desktop, 0, 0, 0, test, test );
314 DestroyWindow( test );
316 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
317 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
318 DestroyWindow( test );
320 /* popup owned by child (same as owned by top-level) */
321 test = create_tool_window( WS_POPUP, child );
322 trace( "created popup owned by child %p\n", test );
323 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
324 DestroyWindow( test );
326 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
327 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
328 DestroyWindow( test );
330 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
331 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
332 trace( "created WS_CHILD popup %p\n", test );
333 check_parents( test, desktop, 0, 0, 0, test, test );
334 DestroyWindow( test );
336 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
337 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
338 DestroyWindow( test );
340 /* owned popup with WS_CHILD (same as WS_POPUP only) */
341 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
342 trace( "created owned WS_CHILD popup %p\n", test );
343 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
344 DestroyWindow( test );
346 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
347 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
348 DestroyWindow( test );
350 /******************** parent changes *************************/
351 trace( "testing parent changes\n" );
354 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
357 /* this test succeeds on NT but crashes on win9x systems */
358 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
359 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
360 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
361 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
362 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
364 /* normal child window */
365 test = create_tool_window( WS_CHILD, hwndMain );
366 trace( "created child %p\n", test );
368 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
369 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
370 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
372 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
373 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
374 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
376 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
377 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
378 check_parents( test, desktop, 0, desktop, 0, test, desktop );
380 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
381 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
382 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
383 check_parents( test, desktop, child, desktop, child, test, desktop );
385 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
386 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
387 check_parents( test, desktop, 0, desktop, 0, test, desktop );
388 DestroyWindow( test );
390 /* not owned top-level window */
391 test = create_tool_window( 0, 0 );
392 trace( "created top-level %p\n", test );
394 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
395 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
396 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
398 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
399 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
400 check_parents( test, desktop, child, 0, child, test, test );
402 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
403 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
404 check_parents( test, desktop, 0, 0, 0, test, test );
405 DestroyWindow( test );
407 /* not owned popup */
408 test = create_tool_window( WS_POPUP, 0 );
409 trace( "created popup %p\n", test );
411 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
412 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
413 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
415 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
416 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
417 check_parents( test, desktop, child, child, child, test, hwndMain );
419 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
420 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
421 check_parents( test, desktop, 0, 0, 0, test, test );
422 DestroyWindow( test );
424 /* normal child window */
425 test = create_tool_window( WS_CHILD, hwndMain );
426 trace( "created child %p\n", test );
428 ret = SetParent( test, desktop );
429 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
430 check_parents( test, desktop, 0, desktop, 0, test, desktop );
432 ret = SetParent( test, child );
433 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
434 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
436 ret = SetParent( test, hwndMain2 );
437 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
438 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
439 DestroyWindow( test );
441 /* not owned top-level window */
442 test = create_tool_window( 0, 0 );
443 trace( "created top-level %p\n", test );
445 ret = SetParent( test, child );
446 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
447 check_parents( test, child, child, 0, 0, hwndMain, test );
448 DestroyWindow( test );
451 test = create_tool_window( WS_POPUP, hwndMain2 );
452 trace( "created owned popup %p\n", test );
454 ret = SetParent( test, child );
455 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
456 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
458 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
459 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
460 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
461 DestroyWindow( test );
463 /**************** test owner destruction *******************/
465 /* owned child popup */
466 owner = create_tool_window( 0, 0 );
467 test = create_tool_window( WS_POPUP, owner );
468 trace( "created owner %p and popup %p\n", owner, test );
469 ret = SetParent( test, child );
470 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
471 check_parents( test, child, child, owner, owner, hwndMain, owner );
472 /* window is now child of 'child' but owned by 'owner' */
473 DestroyWindow( owner );
474 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
475 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
476 * while Win95, Win2k, WinXP do.
478 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
479 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
482 /* owned top-level popup */
483 owner = create_tool_window( 0, 0 );
484 test = create_tool_window( WS_POPUP, owner );
485 trace( "created owner %p and popup %p\n", owner, test );
486 check_parents( test, desktop, owner, owner, owner, test, owner );
487 DestroyWindow( owner );
488 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
490 /* top-level popup owned by child */
491 owner = create_tool_window( WS_CHILD, hwndMain2 );
492 test = create_tool_window( WS_POPUP, 0 );
493 trace( "created owner %p and popup %p\n", owner, test );
494 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
495 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
496 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
497 DestroyWindow( owner );
498 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
499 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
500 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
501 * while Win95, Win2k, WinXP do.
503 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
507 DestroyWindow(child);
510 owner = create_tool_window( WS_OVERLAPPED, 0 );
511 test = create_tool_window( WS_POPUP, desktop );
513 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
515 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
516 "EnumChildWindows should have returned FALSE\n" );
517 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
519 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
520 ret = SetParent( test, owner );
521 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
524 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
525 "EnumChildWindows should have returned TRUE\n" );
526 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
528 child = create_tool_window( WS_CHILD, owner );
530 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
531 "EnumChildWindows should have returned FALSE\n" );
532 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
533 DestroyWindow( child );
535 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
536 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
538 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
539 "EnumChildWindows should have returned TRUE\n" );
540 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
542 ret = SetParent( child, owner );
543 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
544 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
546 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
547 "EnumChildWindows should have returned FALSE\n" );
548 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
550 ret = SetParent( child, NULL );
551 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
552 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
554 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
555 "EnumChildWindows should have returned TRUE\n" );
556 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
558 /* even GW_OWNER == owner it's still a desktop's child */
559 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
560 "EnumChildWindows should have found %p and returned FALSE\n", child );
562 DestroyWindow( child );
563 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
565 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
566 "EnumChildWindows should have found %p and returned FALSE\n", child );
568 DestroyWindow( child );
569 DestroyWindow( test );
570 DestroyWindow( owner );
573 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
576 if (*(LPINT)lParam > 2) return FALSE;
579 static DWORD CALLBACK enum_thread( void *arg )
586 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
589 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
590 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
591 ok( count == 0, "count should be 0 got %d\n", count );
593 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
594 0, 0, 100, 100, 0, 0, 0, NULL );
596 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
597 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
598 if (count != 2) /* Vista gives us two windows for the price of one */
600 ok( count == 1, "count should be 1 got %d\n", count );
601 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
602 0, 0, 100, 100, 0, 0, 0, NULL );
606 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
607 0, 0, 100, 100, 0, 0, 0, NULL );
609 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
610 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
611 ok( count == 3, "count should be 3 got %d\n", count );
613 if (hwnd[2]) DestroyWindow(hwnd[2]);
614 DestroyWindow(hwnd[1]);
615 DestroyWindow(hwnd[0]);
619 /* test EnumThreadWindows in a separate thread */
620 static void test_enum_thread_windows(void)
623 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
624 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
625 CloseHandle( handle );
628 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
632 case WM_GETMINMAXINFO:
634 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
636 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
637 dump_minmax_info( minmax );
638 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
641 case WM_WINDOWPOSCHANGING:
643 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
644 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
645 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
646 winpos->hwnd, winpos->hwndInsertAfter,
647 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
648 if (!(winpos->flags & SWP_NOMOVE))
650 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
651 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
653 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
654 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
656 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
657 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
661 case WM_WINDOWPOSCHANGED:
664 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
665 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
666 winpos->hwnd, winpos->hwndInsertAfter,
667 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
668 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
669 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
671 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
672 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
674 GetWindowRect(hwnd, &rc1);
675 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
676 /* note: winpos coordinates are relative to parent */
677 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
680 /* Uncomment this once the test succeeds in all cases */
681 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
682 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
684 GetClientRect(hwnd, &rc2);
685 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
686 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
687 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
688 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
694 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
695 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
697 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
698 if (got_getminmaxinfo)
699 trace("%p got WM_GETMINMAXINFO\n", hwnd);
701 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
702 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
704 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
708 if (test_lbuttondown_flag)
710 ShowWindow((HWND)wparam, SW_SHOW);
711 flush_events( FALSE );
716 return DefWindowProcA(hwnd, msg, wparam, lparam);
719 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
723 case WM_GETMINMAXINFO:
725 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
727 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
728 dump_minmax_info( minmax );
729 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
734 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
735 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
737 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
738 if (got_getminmaxinfo)
739 trace("%p got WM_GETMINMAXINFO\n", hwnd);
741 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
742 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
744 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
749 return DefWindowProcA(hwnd, msg, wparam, lparam);
752 static BOOL RegisterWindowClasses(void)
756 cls.style = CS_DBLCLKS;
757 cls.lpfnWndProc = main_window_procA;
760 cls.hInstance = GetModuleHandleA(0);
762 cls.hCursor = LoadCursorA(0, IDC_ARROW);
763 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
764 cls.lpszMenuName = NULL;
765 cls.lpszClassName = "MainWindowClass";
767 if(!RegisterClassA(&cls)) return FALSE;
770 cls.lpfnWndProc = tool_window_procA;
773 cls.hInstance = GetModuleHandleA(0);
775 cls.hCursor = LoadCursorA(0, IDC_ARROW);
776 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
777 cls.lpszMenuName = NULL;
778 cls.lpszClassName = "ToolWindowClass";
780 if(!RegisterClassA(&cls)) return FALSE;
785 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
787 RECT rcWindow, rcClient;
790 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
792 GetWindowRect(hwnd, &rcWindow);
793 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
795 GetClientRect(hwnd, &rcClient);
796 /* translate to screen coordinates */
797 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
798 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
800 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
801 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
802 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
803 /* Windows reports some undocumented exstyles in WINDOWINFO, but
804 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
806 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
807 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
808 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
809 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
810 if (GetForegroundWindow())
811 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
812 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
814 /* win2k and XP return broken border info in GetWindowInfo most of
815 * the time, so there is no point in testing it.
819 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
820 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
821 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
822 ok(info->cyWindowBorders == border,
823 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
825 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
827 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
828 info->wCreatorVersion == 0x0500 /* Vista */,
829 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
832 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
834 AdjustWindowRectEx(rc, style, menu, exstyle);
835 /* AdjustWindowRectEx does not include scroll bars */
836 if (style & WS_VSCROLL)
838 if(exstyle & WS_EX_LEFTSCROLLBAR)
839 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
841 rc->right += GetSystemMetrics(SM_CXVSCROLL);
843 if (style & WS_HSCROLL)
844 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
847 static void test_nonclient_area(HWND hwnd)
849 DWORD style, exstyle;
850 RECT rc_window, rc_client, rc;
852 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
855 style = GetWindowLongA(hwnd, GWL_STYLE);
856 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
857 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
859 GetWindowRect(hwnd, &rc_window);
860 GetClientRect(hwnd, &rc_client);
862 /* avoid some cases when things go wrong */
863 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
864 rc_window.right > 32768 || rc_window.bottom > 32768) return;
866 CopyRect(&rc, &rc_client);
867 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
868 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
870 ok(EqualRect(&rc, &rc_window),
871 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
872 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
873 rc.left, rc.top, rc.right, rc.bottom);
876 CopyRect(&rc, &rc_window);
877 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
878 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
879 ok(EqualRect(&rc, &rc_client),
880 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
881 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
882 rc.left, rc.top, rc.right, rc.bottom);
884 /* NULL rectangle shouldn't crash */
885 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
886 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
888 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
892 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
893 SetRect(&rc_client, 0, 0, 250, 150);
894 CopyRect(&rc_window, &rc_client);
895 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
896 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
898 CopyRect(&rc, &rc_window);
899 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
900 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
901 ok(EqualRect(&rc, &rc_client),
902 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
903 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
904 rc.left, rc.top, rc.right, rc.bottom);
907 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
909 static const char *CBT_code_name[10] = {
920 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
921 HWND hwnd = (HWND)wParam;
927 static const RECT rc_null;
930 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
931 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
932 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
933 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
938 info.cbSize = sizeof(WINDOWINFO);
939 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
940 verify_window_info(code_name, hwnd, &info);
943 /* WS_VISIBLE should be turned off yet */
944 style = createwnd->lpcs->style & ~WS_VISIBLE;
945 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
946 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
947 GetWindowLongA(hwnd, GWL_STYLE), style);
951 /* Uncomment this once the test succeeds in all cases */
952 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
954 ok(GetParent(hwnd) == hwndMessage,
955 "wrong result from GetParent %p: message window %p\n",
956 GetParent(hwnd), hwndMessage);
959 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
961 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
965 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
966 * Win9x still has them set to 0.
968 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
969 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
971 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
972 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
976 /* Uncomment this once the test succeeds in all cases */
979 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
980 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
981 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
983 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
984 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
985 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
987 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
988 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
991 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
992 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
993 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
994 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1002 if (pGetWindowInfo && IsWindow(hwnd))
1006 /* Win98 actually does check the info.cbSize and doesn't allow
1007 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1008 * WinXP do not check it at all.
1010 info.cbSize = sizeof(WINDOWINFO);
1011 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1012 verify_window_info(code_name, hwnd, &info);
1015 /* on HCBT_DESTROYWND window state is undefined */
1016 case HCBT_DESTROYWND:
1017 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
1023 return CallNextHookEx(hhook, nCode, wParam, lParam);
1026 static void test_shell_window(void)
1030 HMODULE hinst, hUser32;
1031 BOOL (WINAPI*SetShellWindow)(HWND);
1032 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
1033 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1034 HWND shellWindow, nextWnd;
1036 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
1038 trace("Skipping shell window test on Win9x\n");
1042 shellWindow = GetShellWindow();
1043 hinst = GetModuleHandle(0);
1044 hUser32 = GetModuleHandleA("user32");
1046 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1047 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
1049 trace("previous shell window: %p\n", shellWindow);
1055 GetWindowThreadProcessId(shellWindow, &pid);
1056 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1059 skip( "cannot get access to shell process\n" );
1063 SetLastError(0xdeadbeef);
1064 ret = DestroyWindow(shellWindow);
1065 error = GetLastError();
1067 ok(!ret, "DestroyWindow(shellWindow)\n");
1068 /* passes on Win XP, but not on Win98 */
1069 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1070 "got %u after DestroyWindow(shellWindow)\n", error);
1072 /* close old shell instance */
1073 ret = TerminateProcess(hProcess, 0);
1074 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1075 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1076 CloseHandle(hProcess);
1079 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1080 trace("created window 1: %p\n", hwnd1);
1082 ret = SetShellWindow(hwnd1);
1083 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1084 shellWindow = GetShellWindow();
1085 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1087 ret = SetShellWindow(hwnd1);
1088 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1090 ret = SetShellWindow(0);
1091 error = GetLastError();
1092 /* passes on Win XP, but not on Win98
1093 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1094 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1096 ret = SetShellWindow(hwnd1);
1097 /* passes on Win XP, but not on Win98
1098 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1100 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1101 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1102 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1104 ret = DestroyWindow(hwnd1);
1105 ok(ret, "DestroyWindow(hwnd1)\n");
1107 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1108 trace("created window 2: %p\n", hwnd2);
1109 ret = SetShellWindow(hwnd2);
1110 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1112 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1113 trace("created window 3: %p\n", hwnd3);
1115 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1116 trace("created window 4: %p\n", hwnd4);
1118 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1119 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1121 ret = SetShellWindow(hwnd4);
1122 ok(ret, "SetShellWindow(hwnd4)\n");
1123 shellWindow = GetShellWindow();
1124 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1126 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1127 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1129 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1130 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1132 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1133 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1135 ret = SetShellWindow(hwnd3);
1136 ok(!ret, "SetShellWindow(hwnd3)\n");
1137 shellWindow = GetShellWindow();
1138 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1140 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1141 trace("created window 5: %p\n", hwnd5);
1142 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1143 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1147 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1148 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1151 /* destroy test windows */
1152 DestroyWindow(hwnd2);
1153 DestroyWindow(hwnd3);
1154 DestroyWindow(hwnd4);
1155 DestroyWindow(hwnd5);
1158 /************** MDI test ****************/
1160 static char mdi_lParam_test_message[] = "just a test string";
1162 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1164 MDICREATESTRUCTA mdi_cs;
1167 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1168 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1169 BOOL isWin9x = FALSE;
1171 mdi_cs.szClass = "MDI_child_Class_1";
1172 mdi_cs.szTitle = "MDI child";
1173 mdi_cs.hOwner = GetModuleHandle(0);
1174 mdi_cs.x = CW_USEDEFAULT;
1175 mdi_cs.y = CW_USEDEFAULT;
1176 mdi_cs.cx = CW_USEDEFAULT;
1177 mdi_cs.cy = CW_USEDEFAULT;
1179 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1180 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1181 ok(mdi_child != 0, "MDI child creation failed\n");
1182 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1183 ok(id == first_id, "wrong child id %ld\n", id);
1184 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1185 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1187 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1188 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1189 ok(mdi_child != 0, "MDI child creation failed\n");
1190 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1191 ok(id == first_id, "wrong child id %ld\n", id);
1192 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1193 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1195 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1196 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1197 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1199 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1203 ok(mdi_child != 0, "MDI child creation failed\n");
1204 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1205 ok(id == first_id, "wrong child id %ld\n", id);
1206 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1207 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1210 /* test MDICREATESTRUCT A<->W mapping */
1211 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1213 mdi_cs.szClass = (LPCSTR)classW;
1214 mdi_cs.szTitle = (LPCSTR)titleW;
1215 SetLastError(0xdeadbeef);
1216 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1219 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1226 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1227 ok(id == first_id, "wrong child id %ld\n", id);
1228 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1229 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1232 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1234 CW_USEDEFAULT, CW_USEDEFAULT,
1235 CW_USEDEFAULT, CW_USEDEFAULT,
1236 mdi_client, GetModuleHandle(0),
1237 (LPARAM)mdi_lParam_test_message);
1238 ok(mdi_child != 0, "MDI child creation failed\n");
1239 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1240 ok(id == first_id, "wrong child id %ld\n", id);
1241 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1242 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1244 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1245 0x7fffffff, /* without WS_POPUP */
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 mdi_client, GetModuleHandle(0),
1249 (LPARAM)mdi_lParam_test_message);
1250 ok(mdi_child != 0, "MDI child creation failed\n");
1251 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1252 ok(id == first_id, "wrong child id %ld\n", id);
1253 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1254 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1256 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1257 0xffffffff, /* with WS_POPUP */
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 mdi_client, GetModuleHandle(0),
1261 (LPARAM)mdi_lParam_test_message);
1262 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1264 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1270 ok(id == first_id, "wrong child id %ld\n", id);
1271 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1272 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1275 /* test MDICREATESTRUCT A<->W mapping */
1276 SetLastError(0xdeadbeef);
1277 mdi_child = CreateMDIWindowW(classW, titleW,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 CW_USEDEFAULT, CW_USEDEFAULT,
1281 mdi_client, GetModuleHandle(0),
1282 (LPARAM)mdi_lParam_test_message);
1285 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1288 ok(mdi_child != 0, "MDI child creation failed\n");
1292 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1293 ok(id == first_id, "wrong child id %ld\n", id);
1294 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1295 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1298 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1300 CW_USEDEFAULT, CW_USEDEFAULT,
1301 CW_USEDEFAULT, CW_USEDEFAULT,
1302 mdi_client, 0, GetModuleHandle(0),
1303 mdi_lParam_test_message);
1304 ok(mdi_child != 0, "MDI child creation failed\n");
1305 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1306 ok(id == first_id, "wrong child id %ld\n", id);
1307 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1308 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1310 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1311 0x7fffffff, /* without WS_POPUP */
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 CW_USEDEFAULT, CW_USEDEFAULT,
1314 mdi_client, 0, GetModuleHandle(0),
1315 mdi_lParam_test_message);
1316 ok(mdi_child != 0, "MDI child creation failed\n");
1317 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1318 ok(id == first_id, "wrong child id %ld\n", id);
1319 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1320 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1322 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1323 0xffffffff, /* with WS_POPUP */
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 CW_USEDEFAULT, CW_USEDEFAULT,
1326 mdi_client, 0, GetModuleHandle(0),
1327 mdi_lParam_test_message);
1328 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1330 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1334 ok(mdi_child != 0, "MDI child creation failed\n");
1335 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1336 ok(id == first_id, "wrong child id %ld\n", id);
1337 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1338 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1341 /* test MDICREATESTRUCT A<->W mapping */
1342 SetLastError(0xdeadbeef);
1343 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1345 CW_USEDEFAULT, CW_USEDEFAULT,
1346 CW_USEDEFAULT, CW_USEDEFAULT,
1347 mdi_client, 0, GetModuleHandle(0),
1348 mdi_lParam_test_message);
1351 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1354 ok(mdi_child != 0, "MDI child creation failed\n");
1358 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1359 ok(id == first_id, "wrong child id %ld\n", id);
1360 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1361 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1364 /* This test fails on Win9x */
1367 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1369 CW_USEDEFAULT, CW_USEDEFAULT,
1370 CW_USEDEFAULT, CW_USEDEFAULT,
1371 parent, 0, GetModuleHandle(0),
1372 mdi_lParam_test_message);
1373 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1376 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1377 WS_CHILD, /* without WS_POPUP */
1378 CW_USEDEFAULT, CW_USEDEFAULT,
1379 CW_USEDEFAULT, CW_USEDEFAULT,
1380 mdi_client, 0, GetModuleHandle(0),
1381 mdi_lParam_test_message);
1382 ok(mdi_child != 0, "MDI child creation failed\n");
1383 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1384 ok(id == 0, "wrong child id %ld\n", id);
1385 DestroyWindow(mdi_child);
1387 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1388 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1389 CW_USEDEFAULT, CW_USEDEFAULT,
1390 CW_USEDEFAULT, CW_USEDEFAULT,
1391 mdi_client, 0, GetModuleHandle(0),
1392 mdi_lParam_test_message);
1393 ok(mdi_child != 0, "MDI child creation failed\n");
1394 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1395 ok(id == 0, "wrong child id %ld\n", id);
1396 DestroyWindow(mdi_child);
1398 /* maximized child */
1399 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1400 WS_CHILD | WS_MAXIMIZE,
1401 CW_USEDEFAULT, CW_USEDEFAULT,
1402 CW_USEDEFAULT, CW_USEDEFAULT,
1403 mdi_client, 0, GetModuleHandle(0),
1404 mdi_lParam_test_message);
1405 ok(mdi_child != 0, "MDI child creation failed\n");
1406 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1407 ok(id == 0, "wrong child id %ld\n", id);
1408 DestroyWindow(mdi_child);
1410 trace("Creating maximized child with a caption\n");
1411 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1412 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1413 CW_USEDEFAULT, CW_USEDEFAULT,
1414 CW_USEDEFAULT, CW_USEDEFAULT,
1415 mdi_client, 0, GetModuleHandle(0),
1416 mdi_lParam_test_message);
1417 ok(mdi_child != 0, "MDI child creation failed\n");
1418 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1419 ok(id == 0, "wrong child id %ld\n", id);
1420 DestroyWindow(mdi_child);
1422 trace("Creating maximized child with a caption and a thick frame\n");
1423 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1424 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1425 CW_USEDEFAULT, CW_USEDEFAULT,
1426 CW_USEDEFAULT, CW_USEDEFAULT,
1427 mdi_client, 0, GetModuleHandle(0),
1428 mdi_lParam_test_message);
1429 ok(mdi_child != 0, "MDI child creation failed\n");
1430 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1431 ok(id == 0, "wrong child id %ld\n", id);
1432 DestroyWindow(mdi_child);
1435 /**********************************************************************
1436 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1438 * Note: The rule here is that client rect of the maximized MDI child
1439 * is equal to the client rect of the MDI client window.
1441 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1445 GetClientRect( client, &rect );
1446 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1447 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1449 rect.right -= rect.left;
1450 rect.bottom -= rect.top;
1451 lpMinMax->ptMaxSize.x = rect.right;
1452 lpMinMax->ptMaxSize.y = rect.bottom;
1454 lpMinMax->ptMaxPosition.x = rect.left;
1455 lpMinMax->ptMaxPosition.y = rect.top;
1457 trace("max rect (%d,%d - %d, %d)\n",
1458 rect.left, rect.top, rect.right, rect.bottom);
1461 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1468 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1469 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1471 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1472 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1474 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1475 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1476 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1477 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1478 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1480 /* MDICREATESTRUCT should have original values */
1481 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1482 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1483 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1484 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1485 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1486 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1488 /* CREATESTRUCT should have fixed values */
1489 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1490 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1492 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1493 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1494 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1496 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1498 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1500 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1501 ok(cs->style == style,
1502 "cs->style does not match (%08x)\n", cs->style);
1506 LONG style = mdi_cs->style;
1508 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1509 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1510 ok(cs->style == style,
1511 "cs->style does not match (%08x)\n", cs->style);
1516 case WM_GETMINMAXINFO:
1518 HWND client = GetParent(hwnd);
1520 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1521 MINMAXINFO my_minmax;
1522 LONG style, exstyle;
1524 style = GetWindowLongA(hwnd, GWL_STYLE);
1525 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1527 GetWindowRect(client, &rc);
1528 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1529 GetClientRect(client, &rc);
1530 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1531 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1532 GetSystemMetrics(SM_CYSCREEN));
1534 GetClientRect(client, &rc);
1535 if ((style & WS_CAPTION) == WS_CAPTION)
1536 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1537 AdjustWindowRectEx(&rc, style, 0, exstyle);
1538 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1539 dump_minmax_info( minmax );
1541 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1542 minmax->ptMaxSize.x, rc.right - rc.left);
1543 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1544 minmax->ptMaxSize.y, rc.bottom - rc.top);
1546 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1548 trace("DefMDIChildProc returned:\n");
1549 dump_minmax_info( minmax );
1551 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1552 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1553 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1554 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1555 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1560 case WM_MDIACTIVATE:
1562 HWND active, client = GetParent(hwnd);
1563 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1564 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1565 if (hwnd == (HWND)lparam) /* if we are being activated */
1566 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1568 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1572 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1575 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1582 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1584 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1585 cs->x, cs->y, cs->cx, cs->cy);
1587 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1588 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1590 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1591 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1593 /* CREATESTRUCT should have fixed values */
1594 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1596 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1597 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1599 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1600 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1601 while Win95, Win2k, WinXP do. */
1602 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1603 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1607 case WM_GETMINMAXINFO:
1609 HWND parent = GetParent(hwnd);
1611 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1612 LONG style, exstyle;
1614 style = GetWindowLongA(hwnd, GWL_STYLE);
1615 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1617 GetClientRect(parent, &rc);
1618 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1620 GetClientRect(parent, &rc);
1621 if ((style & WS_CAPTION) == WS_CAPTION)
1622 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1623 AdjustWindowRectEx(&rc, style, 0, exstyle);
1624 dump_minmax_info( minmax );
1626 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1627 minmax->ptMaxSize.x, rc.right - rc.left);
1628 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1629 minmax->ptMaxSize.y, rc.bottom - rc.top);
1633 case WM_WINDOWPOSCHANGED:
1635 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1638 GetWindowRect(hwnd, &rc1);
1639 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1640 /* note: winpos coordinates are relative to parent */
1641 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1642 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1643 rc1.left, rc1.top, rc1.right, rc1.bottom,
1644 rc2.left, rc2.top, rc2.right, rc2.bottom);
1645 GetWindowRect(hwnd, &rc1);
1646 GetClientRect(hwnd, &rc2);
1647 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1648 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1649 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1650 rc1.left, rc1.top, rc1.right, rc1.bottom,
1651 rc2.left, rc2.top, rc2.right, rc2.bottom);
1654 case WM_WINDOWPOSCHANGING:
1656 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1657 WINDOWPOS my_winpos = *winpos;
1659 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1660 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1661 winpos->hwnd, winpos->hwndInsertAfter,
1662 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1664 DefWindowProcA(hwnd, msg, wparam, lparam);
1666 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1667 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1668 winpos->hwnd, winpos->hwndInsertAfter,
1669 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1674 return DefWindowProcA(hwnd, msg, wparam, lparam);
1677 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1679 static HWND mdi_client;
1685 CLIENTCREATESTRUCT client_cs;
1688 GetClientRect(hwnd, &rc);
1690 client_cs.hWindowMenu = 0;
1691 client_cs.idFirstChild = 1;
1693 /* MDIClient without MDIS_ALLCHILDSTYLES */
1694 mdi_client = CreateWindowExA(0, "mdiclient",
1696 WS_CHILD /*| WS_VISIBLE*/,
1697 /* tests depend on a not zero MDIClient size */
1698 0, 0, rc.right, rc.bottom,
1699 hwnd, 0, GetModuleHandle(0),
1702 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1703 DestroyWindow(mdi_client);
1705 /* MDIClient with MDIS_ALLCHILDSTYLES */
1706 mdi_client = CreateWindowExA(0, "mdiclient",
1708 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1709 /* tests depend on a not zero MDIClient size */
1710 0, 0, rc.right, rc.bottom,
1711 hwnd, 0, GetModuleHandle(0),
1714 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1715 DestroyWindow(mdi_client);
1719 case WM_WINDOWPOSCHANGED:
1721 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1724 GetWindowRect(hwnd, &rc1);
1725 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1726 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1727 /* note: winpos coordinates are relative to parent */
1728 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1729 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1730 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1732 GetWindowRect(hwnd, &rc1);
1733 GetClientRect(hwnd, &rc2);
1734 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1735 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1736 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1739 case WM_WINDOWPOSCHANGING:
1741 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1742 WINDOWPOS my_winpos = *winpos;
1744 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1745 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1746 winpos->hwnd, winpos->hwndInsertAfter,
1747 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1749 DefWindowProcA(hwnd, msg, wparam, lparam);
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 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1756 "DefWindowProc should not change WINDOWPOS values\n");
1765 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1768 static BOOL mdi_RegisterWindowClasses(void)
1773 cls.lpfnWndProc = mdi_main_wnd_procA;
1776 cls.hInstance = GetModuleHandleA(0);
1778 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1779 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1780 cls.lpszMenuName = NULL;
1781 cls.lpszClassName = "MDI_parent_Class";
1782 if(!RegisterClassA(&cls)) return FALSE;
1784 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1785 cls.lpszClassName = "MDI_child_Class_1";
1786 if(!RegisterClassA(&cls)) return FALSE;
1788 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1789 cls.lpszClassName = "MDI_child_Class_2";
1790 if(!RegisterClassA(&cls)) return FALSE;
1795 static void test_mdi(void)
1800 if (!mdi_RegisterWindowClasses()) assert(0);
1802 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1803 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1804 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1805 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1806 GetDesktopWindow(), 0,
1807 GetModuleHandle(0), NULL);
1808 assert(mdi_hwndMain);
1810 while(GetMessage(&msg, 0, 0, 0))
1812 TranslateMessage(&msg);
1813 DispatchMessage(&msg);
1816 DestroyWindow(mdi_hwndMain);
1819 static void test_icons(void)
1823 HICON icon = LoadIconA(0, IDI_APPLICATION);
1824 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1825 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1826 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1829 cls.cbSize = sizeof(cls);
1831 cls.lpfnWndProc = DefWindowProcA;
1835 cls.hIcon = LoadIconA(0, IDI_HAND);
1836 cls.hIconSm = small_icon;
1837 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1838 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1839 cls.lpszMenuName = NULL;
1840 cls.lpszClassName = "IconWindowClass";
1842 RegisterClassExA(&cls);
1844 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1845 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1848 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1849 ok( res == 0, "wrong big icon %p/0\n", res );
1850 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1851 ok( res == 0, "wrong previous big icon %p/0\n", res );
1852 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1853 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1854 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1855 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1856 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1857 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1859 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1860 ok( res == 0, "wrong small icon %p/0\n", res );
1861 /* this test is XP specific */
1862 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1863 ok( res != 0, "wrong small icon %p\n", res );*/
1864 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1865 ok( res == 0, "wrong previous small icon %p/0\n", res );
1866 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1867 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1868 /* this test is XP specific */
1869 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1870 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1871 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1872 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1873 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1874 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1875 /* this test is XP specific */
1876 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1877 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1879 /* make sure the big icon hasn't changed */
1880 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1881 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1883 DestroyWindow( hwnd );
1886 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1888 if (msg == WM_NCCALCSIZE)
1890 RECT *rect = (RECT *)lparam;
1891 /* first time around increase the rectangle, next time decrease it */
1892 if (rect->left == 100) InflateRect( rect, 10, 10 );
1893 else InflateRect( rect, -10, -10 );
1896 return DefWindowProc( hwnd, msg, wparam, lparam );
1899 static void test_SetWindowPos(HWND hwnd)
1901 RECT orig_win_rc, rect;
1903 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1905 SetRect(&rect, 111, 222, 333, 444);
1906 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1907 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1908 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1910 SetRect(&rect, 111, 222, 333, 444);
1911 ok(!GetClientRect(0, &rect), "GetClientRect 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 GetWindowRect(hwnd, &orig_win_rc);
1917 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1918 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1919 GetWindowRect( hwnd, &rect );
1920 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1921 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1922 GetClientRect( hwnd, &rect );
1923 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1924 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1925 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1927 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1928 GetWindowRect( hwnd, &rect );
1929 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1930 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1931 GetClientRect( hwnd, &rect );
1932 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1933 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1934 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1936 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1937 orig_win_rc.right, orig_win_rc.bottom, 0);
1938 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1940 /* Win9x truncates coordinates to 16-bit irrespectively */
1943 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1944 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1946 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1947 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1950 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1951 orig_win_rc.right, orig_win_rc.bottom, 0);
1953 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1954 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1955 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1956 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1957 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1958 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1959 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1962 static void test_SetMenu(HWND parent)
1966 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1970 hMenu = CreateMenu();
1973 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1976 /* fails on (at least) Wine, NT4, XP SP2 */
1977 test_nonclient_area(parent);
1979 ret = GetMenu(parent);
1980 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1981 /* test whether we can destroy a menu assigned to a window */
1982 retok = DestroyMenu(hMenu);
1983 ok( retok, "DestroyMenu error %d\n", GetLastError());
1984 retok = IsMenu(hMenu);
1985 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1986 ret = GetMenu(parent);
1987 /* This test fails on Win9x */
1989 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1990 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1991 test_nonclient_area(parent);
1993 hMenu = CreateMenu();
1997 ret = GetMenu(parent);
1998 ok(ret == 0, "unexpected menu id %p\n", ret);
2000 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2001 test_nonclient_area(parent);
2002 ret = GetMenu(parent);
2003 ok(ret == 0, "unexpected menu id %p\n", ret);
2005 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2008 /* fails on (at least) Wine, NT4, XP SP2 */
2009 test_nonclient_area(parent);
2011 ret = GetMenu(parent);
2012 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2014 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2015 test_nonclient_area(parent);
2016 ret = GetMenu(parent);
2017 ok(ret == 0, "unexpected menu id %p\n", ret);
2020 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2023 ret = GetMenu(child);
2024 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2026 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2027 test_nonclient_area(child);
2028 ret = GetMenu(child);
2029 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2031 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2032 test_nonclient_area(child);
2033 ret = GetMenu(child);
2034 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2036 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2037 test_nonclient_area(child);
2038 ret = GetMenu(child);
2039 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2041 style = GetWindowLong(child, GWL_STYLE);
2042 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2043 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2044 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2045 SetWindowLong(child, GWL_STYLE, style);
2047 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2048 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2049 SetWindowLong(child, GWL_STYLE, style);
2051 DestroyWindow(child);
2055 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2057 HWND child[5], hwnd;
2062 hwnd = GetWindow(parent, GW_CHILD);
2063 ok(!hwnd, "have to start without children to perform the test\n");
2065 for (i = 0; i < total; i++)
2067 if (style[i] & DS_CONTROL)
2069 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2070 0,0,0,0, parent, (HMENU)i, 0, NULL);
2071 if (style[i] & WS_VISIBLE)
2072 ShowWindow(child[i], SW_SHOW);
2074 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2077 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2078 parent, (HMENU)i, 0, NULL);
2079 trace("child[%ld] = %p\n", i, child[i]);
2080 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2083 hwnd = GetWindow(parent, GW_CHILD);
2084 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2085 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2086 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2088 for (i = 0; i < total; i++)
2090 trace("hwnd[%ld] = %p\n", i, hwnd);
2091 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2093 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2096 for (i = 0; i < total; i++)
2097 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2100 static void test_children_zorder(HWND parent)
2102 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2104 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2106 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2107 WS_CHILD | WS_VISIBLE, WS_CHILD,
2108 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2109 const int complex_order_1[1] = { 0 };
2110 const int complex_order_2[2] = { 1, 0 };
2111 const int complex_order_3[3] = { 1, 0, 2 };
2112 const int complex_order_4[4] = { 1, 0, 2, 3 };
2113 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2114 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2115 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2116 WS_CHILD | WS_VISIBLE };
2117 const int complex_order_6[3] = { 0, 1, 2 };
2119 /* simple WS_CHILD */
2120 test_window_tree(parent, simple_style, simple_order, 5);
2122 /* complex children styles */
2123 test_window_tree(parent, complex_style, complex_order_1, 1);
2124 test_window_tree(parent, complex_style, complex_order_2, 2);
2125 test_window_tree(parent, complex_style, complex_order_3, 3);
2126 test_window_tree(parent, complex_style, complex_order_4, 4);
2127 test_window_tree(parent, complex_style, complex_order_5, 5);
2129 /* another set of complex children styles */
2130 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2133 #define check_z_order(hwnd, next, prev, owner, topmost) \
2134 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2137 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2138 BOOL topmost, const char *file, int line)
2143 test = GetWindow(hwnd, GW_HWNDNEXT);
2144 /* skip foreign windows */
2145 while (test && test != next &&
2146 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2147 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2148 GetWindow(test, GW_OWNER) == next))
2150 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2151 test = GetWindow(test, GW_HWNDNEXT);
2153 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2155 test = GetWindow(hwnd, GW_HWNDPREV);
2156 /* skip foreign windows */
2157 while (test && test != prev &&
2158 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2159 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2160 GetWindow(test, GW_OWNER) == hwnd))
2162 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2163 test = GetWindow(test, GW_HWNDPREV);
2165 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2167 test = GetWindow(hwnd, GW_OWNER);
2168 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2170 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2171 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2174 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2176 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2178 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2180 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2182 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2183 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2185 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2186 WS_OVERLAPPED | WS_CAPTION,
2188 0, 0, GetModuleHandle(0), NULL);
2189 trace("hwnd_F %p\n", hwnd_F);
2190 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2192 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2193 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2194 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2195 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2197 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2200 hwnd_F, 0, GetModuleHandle(0), NULL);
2201 trace("hwnd_C %p\n", hwnd_C);
2202 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2203 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2204 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2205 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2207 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2210 hwnd_F, 0, GetModuleHandle(0), NULL);
2211 trace("hwnd_B %p\n", hwnd_B);
2212 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2213 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2214 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2215 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2216 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2218 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2221 0, 0, GetModuleHandle(0), NULL);
2222 trace("hwnd_A %p\n", hwnd_A);
2223 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2224 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2225 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2226 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2227 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2228 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2230 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);
2232 /* move hwnd_F and its popups up */
2233 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2234 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2235 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2236 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2237 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2238 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2239 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2241 /* move hwnd_F and its popups down */
2242 #if 0 /* enable once Wine is fixed to pass this test */
2243 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2244 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2245 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2246 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2247 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2248 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2249 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2252 DestroyWindow(hwnd_A);
2253 DestroyWindow(hwnd_B);
2254 DestroyWindow(hwnd_C);
2255 DestroyWindow(hwnd_F);
2258 static void test_vis_rgn( HWND hwnd )
2260 RECT win_rect, rgn_rect;
2261 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2264 ShowWindow(hwnd,SW_SHOW);
2265 hdc = GetDC( hwnd );
2266 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2267 GetWindowRect( hwnd, &win_rect );
2268 GetRgnBox( hrgn, &rgn_rect );
2269 if (GetVersion() & 0x80000000)
2271 trace("win9x, mapping to screen coords\n");
2272 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2274 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2275 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2276 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2277 rgn_rect.left, win_rect.left );
2278 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2279 rgn_rect.top, win_rect.top );
2280 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2281 rgn_rect.right, win_rect.right );
2282 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2283 rgn_rect.bottom, win_rect.bottom );
2284 ReleaseDC( hwnd, hdc );
2287 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2289 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2291 HWND child = GetWindow(hwnd, GW_CHILD);
2292 ok(child != 0, "couldn't find child window\n");
2294 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2297 return DefWindowProc(hwnd, msg, wp, lp);
2300 static void test_SetFocus(HWND hwnd)
2303 WNDPROC old_wnd_proc;
2305 /* check if we can set focus to non-visible windows */
2307 ShowWindow(hwnd, SW_SHOW);
2310 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2311 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2312 ShowWindow(hwnd, SW_HIDE);
2315 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2316 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2317 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2320 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2321 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2322 ShowWindow(child, SW_SHOW);
2323 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2324 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2325 ShowWindow(child, SW_HIDE);
2326 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2327 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2328 ShowWindow(child, SW_SHOW);
2329 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2331 ShowWindow(child2, SW_SHOW);
2333 ShowWindow(child, SW_HIDE);
2334 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2335 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2336 ShowWindow(child, SW_SHOW);
2338 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2339 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2340 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2342 ShowWindow(child, SW_HIDE);
2344 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2345 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2346 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2347 ShowWindow(child, SW_HIDE);
2348 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2350 ShowWindow(hwnd, SW_SHOW);
2351 ShowWindow(child, SW_SHOW);
2353 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2354 EnableWindow(hwnd, FALSE);
2355 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2356 EnableWindow(hwnd, TRUE);
2358 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2359 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2360 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2362 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2363 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2364 ShowWindow(hwnd, SW_RESTORE);
2365 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2366 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2367 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2368 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2369 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2371 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2372 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2373 ShowWindow(hwnd, SW_RESTORE);
2374 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2376 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2378 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2380 DestroyWindow( child2 );
2381 DestroyWindow( child );
2384 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2385 static void check_wnd_state_(const char *file, int line,
2386 HWND active, HWND foreground, HWND focus, HWND capture)
2388 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2389 /* only check foreground if it belongs to the current thread */
2390 /* foreground can be moved to a different app pretty much at any time */
2391 if (foreground && GetForegroundWindow() &&
2392 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
2393 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2394 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2395 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2398 static void test_SetActiveWindow(HWND hwnd)
2402 flush_events( TRUE );
2403 ShowWindow(hwnd, SW_HIDE);
2406 check_wnd_state(0, 0, 0, 0);
2408 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2410 ShowWindow(hwnd, SW_SHOW);
2411 check_wnd_state(hwnd, hwnd, hwnd, 0);
2413 hwnd2 = SetActiveWindow(0);
2414 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2415 if (!GetActiveWindow()) /* doesn't always work on vista */
2417 check_wnd_state(0, 0, 0, 0);
2418 hwnd2 = SetActiveWindow(hwnd);
2419 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2421 check_wnd_state(hwnd, hwnd, hwnd, 0);
2423 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2424 check_wnd_state(hwnd, hwnd, hwnd, 0);
2426 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2427 check_wnd_state(hwnd, hwnd, hwnd, 0);
2429 ShowWindow(hwnd, SW_HIDE);
2430 check_wnd_state(0, 0, 0, 0);
2432 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2433 SetActiveWindow(hwnd);
2434 check_wnd_state(hwnd, hwnd, hwnd, 0);
2436 ShowWindow(hwnd, SW_SHOW);
2437 check_wnd_state(hwnd, hwnd, hwnd, 0);
2439 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2440 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2442 DestroyWindow(hwnd2);
2443 check_wnd_state(hwnd, hwnd, hwnd, 0);
2445 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2446 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2448 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2449 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2451 DestroyWindow(hwnd2);
2452 check_wnd_state(hwnd, hwnd, hwnd, 0);
2455 static void test_SetForegroundWindow(HWND hwnd)
2460 flush_events( TRUE );
2461 ShowWindow(hwnd, SW_HIDE);
2464 check_wnd_state(0, 0, 0, 0);
2466 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2468 ShowWindow(hwnd, SW_SHOW);
2469 check_wnd_state(hwnd, hwnd, hwnd, 0);
2471 hwnd2 = SetActiveWindow(0);
2472 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2473 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2474 check_wnd_state(hwnd, hwnd, hwnd, 0);
2476 check_wnd_state(0, 0, 0, 0);
2478 ret = SetForegroundWindow(hwnd);
2481 skip( "SetForegroundWindow not working\n" );
2484 check_wnd_state(hwnd, hwnd, hwnd, 0);
2486 SetLastError(0xdeadbeef);
2487 ret = SetForegroundWindow(0);
2488 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2489 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2490 broken(GetLastError() == 0xdeadbeef), /* win9x */
2491 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2492 check_wnd_state(hwnd, hwnd, hwnd, 0);
2494 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2495 check_wnd_state(hwnd, hwnd, hwnd, 0);
2497 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2498 check_wnd_state(hwnd, hwnd, hwnd, 0);
2500 hwnd2 = GetForegroundWindow();
2501 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2502 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2503 hwnd2 = GetForegroundWindow();
2504 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2506 ShowWindow(hwnd, SW_HIDE);
2507 check_wnd_state(0, 0, 0, 0);
2509 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2510 ret = SetForegroundWindow(hwnd);
2511 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2512 check_wnd_state(hwnd, hwnd, hwnd, 0);
2514 ShowWindow(hwnd, SW_SHOW);
2515 check_wnd_state(hwnd, hwnd, hwnd, 0);
2517 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2518 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2520 DestroyWindow(hwnd2);
2521 check_wnd_state(hwnd, hwnd, hwnd, 0);
2523 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2524 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2526 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2527 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2529 DestroyWindow(hwnd2);
2530 check_wnd_state(hwnd, hwnd, hwnd, 0);
2533 static WNDPROC old_button_proc;
2535 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2540 key_state = GetKeyState(VK_LBUTTON);
2541 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2543 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2545 if (msg == WM_LBUTTONDOWN)
2549 check_wnd_state(button, button, button, button);
2551 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2553 trace("hwnd %p\n", hwnd);
2555 check_wnd_state(button, button, button, button);
2557 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2559 check_wnd_state(button, button, button, button);
2561 DestroyWindow(hwnd);
2563 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2565 trace("hwnd %p\n", hwnd);
2567 check_wnd_state(button, button, button, button);
2569 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2570 * match internal button state.
2572 SendMessage(button, WM_KILLFOCUS, 0, 0);
2573 check_wnd_state(button, button, button, 0);
2575 ShowWindow(hwnd, SW_SHOW);
2576 check_wnd_state(hwnd, hwnd, hwnd, 0);
2578 capture = SetCapture(hwnd);
2579 ok(capture == 0, "SetCapture() = %p\n", capture);
2581 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2583 DestroyWindow(hwnd);
2585 check_wnd_state(button, 0, button, 0);
2591 static void test_capture_1(void)
2593 HWND button, capture, oldFocus, oldActive;
2595 oldFocus = GetFocus();
2596 oldActive = GetActiveWindow();
2598 capture = GetCapture();
2599 ok(capture == 0, "GetCapture() = %p\n", capture);
2601 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2603 trace("button %p\n", button);
2605 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2607 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2609 capture = SetCapture(button);
2610 ok(capture == 0, "SetCapture() = %p\n", capture);
2611 check_wnd_state(button, 0, button, button);
2613 DestroyWindow(button);
2614 check_wnd_state(oldActive, 0, oldFocus, 0);
2617 static void test_capture_2(void)
2619 HWND button, hwnd, capture, oldFocus, oldActive;
2621 oldFocus = GetFocus();
2622 oldActive = GetActiveWindow();
2623 check_wnd_state(oldActive, 0, oldFocus, 0);
2625 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2627 trace("button %p\n", button);
2629 check_wnd_state(button, button, button, 0);
2631 capture = SetCapture(button);
2632 ok(capture == 0, "SetCapture() = %p\n", capture);
2634 check_wnd_state(button, button, button, button);
2636 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2637 * internal button state.
2639 SendMessage(button, WM_KILLFOCUS, 0, 0);
2640 check_wnd_state(button, button, button, button);
2642 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2644 trace("hwnd %p\n", hwnd);
2646 check_wnd_state(button, button, button, button);
2648 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2650 check_wnd_state(button, button, button, button);
2652 DestroyWindow(hwnd);
2654 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2656 trace("hwnd %p\n", hwnd);
2658 check_wnd_state(button, button, button, button);
2660 ShowWindow(hwnd, SW_SHOW);
2662 check_wnd_state(hwnd, hwnd, hwnd, button);
2664 capture = SetCapture(hwnd);
2665 ok(capture == button, "SetCapture() = %p\n", capture);
2667 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2669 DestroyWindow(hwnd);
2670 check_wnd_state(button, button, button, 0);
2672 DestroyWindow(button);
2673 check_wnd_state(oldActive, 0, oldFocus, 0);
2676 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2680 ShowWindow(hwnd1, SW_HIDE);
2681 ShowWindow(hwnd2, SW_HIDE);
2683 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2684 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2687 check_wnd_state(0, 0, 0, hwnd1);
2690 check_wnd_state(0, 0, 0, hwnd2);
2692 ShowWindow(hwnd1, SW_SHOW);
2693 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2695 ret = ReleaseCapture();
2696 ok (ret, "releasecapture did not return TRUE.\n");
2697 ret = ReleaseCapture();
2698 ok (ret, "releasecapture did not return TRUE after second try.\n");
2701 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2704 HWND cap_wnd, cap_wnd2, set_cap_wnd;
2708 case WM_CAPTURECHANGED:
2710 /* now try to release capture from menu. this should fail */
2711 if (pGetGUIThreadInfo)
2713 memset(>i, 0, sizeof(GUITHREADINFO));
2714 gti.cbSize = sizeof(GUITHREADINFO);
2715 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2716 ok(status, "GetGUIThreadInfo() failed!\n");
2717 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2719 cap_wnd = GetCapture();
2721 /* check that re-setting the capture for the menu fails */
2722 set_cap_wnd = SetCapture(cap_wnd);
2723 ok(!set_cap_wnd, "SetCapture should have failed!\n");
2725 /* check that SetCapture fails for another window and that it does not touch the error code */
2726 set_cap_wnd = SetCapture(hWnd);
2727 ok(!set_cap_wnd, "ReleaseCapture should have failed!\n");
2729 /* check that ReleaseCapture fails and does not touch the error code */
2730 status = ReleaseCapture();
2731 ok(!status, "ReleaseCapture should have failed!\n");
2733 /* check that thread info did not change */
2734 if (pGetGUIThreadInfo)
2736 memset(>i, 0, sizeof(GUITHREADINFO));
2737 gti.cbSize = sizeof(GUITHREADINFO);
2738 status = pGetGUIThreadInfo(GetCurrentThreadId(), >i);
2739 ok(status, "GetGUIThreadInfo() failed!\n");
2740 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
2743 /* verify that no capture change took place */
2744 cap_wnd2 = GetCapture();
2745 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
2747 /* we are done. kill the window */
2748 DestroyWindow(hWnd);
2752 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
2757 /* Test that no-one can mess around with the current capture while a menu is open */
2758 static void test_capture_4(void)
2764 HINSTANCE hInstance = GetModuleHandleA( NULL );
2766 if (!pGetGUIThreadInfo)
2767 win_skip("GetGUIThreadInfo is not available\n");
2769 wclass.lpszClassName = "TestCapture4Class";
2770 wclass.style = CS_HREDRAW | CS_VREDRAW;
2771 wclass.lpfnWndProc = test_capture_4_proc;
2772 wclass.hInstance = hInstance;
2773 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
2774 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
2775 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
2776 wclass.lpszMenuName = 0;
2777 wclass.cbClsExtra = 0;
2778 wclass.cbWndExtra = 0;
2779 assert (RegisterClassA( &wclass ));
2780 assert (hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
2781 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
2782 400, 200, NULL, NULL, hInstance, NULL) );
2783 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
2785 hmenu = CreatePopupMenu();
2787 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
2788 ok( ret, "AppendMenuA has failed!\n");
2790 /* set main window to have initial capture */
2793 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
2795 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
2799 /* create popup (it will self-destruct) */
2800 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
2801 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
2806 DestroyWindow(hwnd);
2809 /* PeekMessage wrapper that ignores the messages we don't care about */
2810 static BOOL peek_message( MSG *msg )
2815 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2816 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
2820 static void test_keyboard_input(HWND hwnd)
2825 flush_events( TRUE );
2826 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2828 flush_events( TRUE );
2830 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2833 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2835 flush_events( TRUE );
2837 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2838 ret = peek_message(&msg);
2839 ok( ret, "no message available\n");
2840 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2841 ret = peek_message(&msg);
2842 ok( !ret, "message %04x available\n", msg.message);
2844 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2846 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2847 ret = peek_message(&msg);
2848 ok(ret, "no message available\n");
2849 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2850 ret = peek_message(&msg);
2851 ok( !ret, "message %04x available\n", msg.message);
2853 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2855 keybd_event(VK_SPACE, 0, 0, 0);
2856 if (!peek_message(&msg))
2858 skip( "keybd_event didn't work, skipping keyboard test\n" );
2861 ok(msg.hwnd == 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);
2866 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2868 flush_events( TRUE );
2870 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2871 ret = peek_message(&msg);
2872 ok(ret, "no message available\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);
2877 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2879 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2880 ret = peek_message(&msg);
2881 ok(ret, "no message available\n");
2882 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2883 ret = peek_message(&msg);
2884 ok( !ret, "message %04x available\n", msg.message);
2886 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2888 keybd_event(VK_SPACE, 0, 0, 0);
2889 ret = peek_message(&msg);
2890 ok(ret, "no message available\n");
2891 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2892 ret = peek_message(&msg);
2893 ok( !ret, "message %04x available\n", msg.message);
2896 static BOOL wait_for_message( MSG *msg )
2902 ret = peek_message(msg);
2905 if (msg->message == WM_PAINT) DispatchMessage(msg);
2908 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2910 if (!ret) msg->message = 0;
2914 static void test_mouse_input(HWND hwnd)
2924 ShowWindow(hwnd, SW_SHOW);
2926 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2928 GetWindowRect(hwnd, &rc);
2929 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2931 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2932 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2935 ShowWindow(popup, SW_SHOW);
2936 UpdateWindow(popup);
2937 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2939 GetWindowRect(popup, &rc);
2940 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2942 x = rc.left + (rc.right - rc.left) / 2;
2943 y = rc.top + (rc.bottom - rc.top) / 2;
2944 trace("setting cursor to (%d,%d)\n", x, y);
2948 if (x != pt.x || y != pt.y)
2950 skip( "failed to set mouse position, skipping mouse input tests\n" );
2954 flush_events( TRUE );
2956 /* Check that setting the same position may generate WM_MOUSEMOVE */
2959 ret = peek_message(&msg);
2962 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2963 msg.hwnd, msg.message);
2964 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2965 x, y, msg.pt.x, msg.pt.y);
2968 /* force the system to update its internal queue mouse position,
2969 * otherwise it won't generate relative mouse movements below.
2971 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2972 flush_events( TRUE );
2975 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2976 flush_events( FALSE );
2977 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2978 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2980 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
2981 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2982 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2983 DispatchMessage(&msg);
2985 ret = peek_message(&msg);
2986 ok( !ret, "message %04x available\n", msg.message);
2988 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2989 ShowWindow(popup, SW_HIDE);
2990 ret = wait_for_message( &msg );
2992 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2993 flush_events( TRUE );
2995 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2996 ShowWindow(hwnd, SW_HIDE);
2997 ret = wait_for_message( &msg );
2998 ok( !ret, "message %04x available\n", msg.message);
2999 flush_events( TRUE );
3001 /* test mouse clicks */
3003 ShowWindow(hwnd, SW_SHOW);
3004 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3005 flush_events( TRUE );
3006 ShowWindow(popup, SW_SHOW);
3007 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3008 flush_events( TRUE );
3010 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3011 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3012 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3013 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3015 ret = wait_for_message( &msg );
3018 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3021 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3023 ret = wait_for_message( &msg );
3024 ok(ret, "no message available\n");
3027 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3028 msg.hwnd, popup, msg.message);
3030 ret = wait_for_message( &msg );
3031 ok(ret, "no message available\n");
3032 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3033 msg.hwnd, popup, msg.message);
3035 ret = wait_for_message( &msg );
3036 ok(ret, "no message available\n");
3037 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3038 msg.hwnd, popup, msg.message);
3040 ret = wait_for_message( &msg );
3041 ok(ret, "no message available\n");
3042 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3043 msg.hwnd, popup, msg.message);
3045 ret = peek_message(&msg);
3046 ok(!ret, "message %04x available\n", msg.message);
3048 ShowWindow(popup, SW_HIDE);
3049 flush_events( TRUE );
3051 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3052 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3053 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3054 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3056 ret = wait_for_message( &msg );
3057 ok(ret, "no message available\n");
3058 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3059 msg.hwnd, hwnd, msg.message);
3060 ret = wait_for_message( &msg );
3061 ok(ret, "no message available\n");
3062 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3063 msg.hwnd, hwnd, msg.message);
3065 test_lbuttondown_flag = TRUE;
3066 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3067 test_lbuttondown_flag = FALSE;
3069 ret = wait_for_message( &msg );
3070 ok(ret, "no message available\n");
3071 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3072 msg.hwnd, popup, msg.message);
3073 ok(peek_message(&msg), "no message available\n");
3074 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3075 msg.hwnd, popup, msg.message);
3076 ok(peek_message(&msg), "no message available\n");
3078 /* Test WM_MOUSEACTIVATE */
3079 #define TEST_MOUSEACTIVATE(A,B) \
3080 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3081 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3083 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3084 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3085 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3086 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3087 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3088 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3089 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3090 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3091 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3092 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3093 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3094 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3095 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3096 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3097 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3098 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3099 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3100 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3101 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3102 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3103 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3104 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3105 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3106 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3109 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3110 flush_events( TRUE );
3112 DestroyWindow(popup);
3115 static void test_validatergn(HWND hwnd)
3121 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3122 ShowWindow(hwnd, SW_SHOW);
3123 UpdateWindow( hwnd);
3124 /* test that ValidateRect validates children*/
3125 InvalidateRect( child, NULL, 1);
3126 GetWindowRect( child, &rc);
3127 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3128 ret = GetUpdateRect( child, &rc2, 0);
3129 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3130 "Update rectangle is empty!\n");
3131 ValidateRect( hwnd, &rc);
3132 ret = GetUpdateRect( child, &rc2, 0);
3133 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3134 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3135 rc2.right, rc2.bottom);
3137 /* now test ValidateRgn */
3138 InvalidateRect( child, NULL, 1);
3139 GetWindowRect( child, &rc);
3140 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3141 rgn = CreateRectRgnIndirect( &rc);
3142 ValidateRgn( hwnd, rgn);
3143 ret = GetUpdateRect( child, &rc2, 0);
3144 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3145 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3146 rc2.right, rc2.bottom);
3149 DestroyWindow( child );
3152 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3155 MoveWindow( hwnd, 0, 0, x, y, 0);
3156 GetWindowRect( hwnd, prc);
3158 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3159 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3160 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3163 static void test_nccalcscroll(HWND parent)
3166 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3167 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3168 HWND hwnd = CreateWindowExA(0, "static", NULL,
3169 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3170 10, 10, 200, 200, parent, 0, 0, NULL);
3171 ShowWindow( parent, SW_SHOW);
3172 UpdateWindow( parent);
3174 /* test window too low for a horizontal scroll bar */
3175 nccalchelper( hwnd, 100, sbheight, &rc1);
3176 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3177 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3179 /* test window just high enough for a horizontal scroll bar */
3180 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3181 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3182 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3184 /* test window too narrow for a vertical scroll bar */
3185 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3186 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3187 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3189 /* test window just wide enough for a vertical scroll bar */
3190 nccalchelper( hwnd, sbwidth, 100, &rc1);
3191 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3192 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3194 /* same test, but with client edge: not enough width */
3195 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3196 nccalchelper( hwnd, sbwidth, 100, &rc1);
3197 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3198 "Width should be %d size is %d,%d - %d,%d\n",
3199 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3201 DestroyWindow( hwnd);
3204 static void test_SetParent(void)
3207 HWND desktop = GetDesktopWindow();
3209 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3210 HWND parent, child1, child2, child3, child4, sibling;
3212 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3213 100, 100, 200, 200, 0, 0, 0, NULL);
3214 assert(parent != 0);
3215 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3216 0, 0, 50, 50, parent, 0, 0, NULL);
3217 assert(child1 != 0);
3218 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3219 0, 0, 50, 50, child1, 0, 0, NULL);
3220 assert(child2 != 0);
3221 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3222 0, 0, 50, 50, child2, 0, 0, NULL);
3223 assert(child3 != 0);
3224 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3225 0, 0, 50, 50, child3, 0, 0, NULL);
3226 assert(child4 != 0);
3228 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3229 parent, child1, child2, child3, child4);
3231 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3232 check_parents(child1, parent, parent, parent, 0, parent, parent);
3233 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3234 check_parents(child3, child2, child2, child2, 0, child2, parent);
3235 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3237 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3238 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3239 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3240 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3241 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3243 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3244 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3245 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3246 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3247 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3248 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3249 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3250 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3251 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3253 if (!is_win9x) /* Win9x doesn't survive this test */
3255 ok(!SetParent(parent, child1), "SetParent should fail\n");
3256 ok(!SetParent(child2, child3), "SetParent should fail\n");
3257 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3258 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3259 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3260 ok(!SetParent(child2, parent), "SetParent should fail\n");
3261 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3263 check_parents(parent, child4, child4, 0, 0, child4, parent);
3264 check_parents(child1, parent, parent, parent, 0, child4, parent);
3265 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3266 check_parents(child3, child2, child2, child2, 0, child2, parent);
3267 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3270 hMenu = CreateMenu();
3271 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3272 100, 100, 200, 200, 0, hMenu, 0, NULL);
3273 assert(sibling != 0);
3275 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3276 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3278 ret = DestroyWindow(parent);
3279 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3281 ok(!IsWindow(parent), "parent still exists\n");
3282 ok(!IsWindow(sibling), "sibling still exists\n");
3283 ok(!IsWindow(child1), "child1 still exists\n");
3284 ok(!IsWindow(child2), "child2 still exists\n");
3285 ok(!IsWindow(child3), "child3 still exists\n");
3286 ok(!IsWindow(child4), "child4 still exists\n");
3289 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3291 LPCREATESTRUCT lpcs;
3298 lpcs = (LPCREATESTRUCT)lparam;
3299 lpss = lpcs->lpCreateParams;
3302 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3303 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3304 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3305 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3307 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3309 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3310 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3311 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3313 ok(lpss->styleNew == lpcs->style,
3314 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3315 lpss->styleNew, lpcs->style);
3319 return DefWindowProc(hwnd, msg, wparam, lparam);
3322 static ATOM atomStyleCheckClass;
3324 static void register_style_check_class(void)
3332 GetModuleHandle(NULL),
3334 LoadCursor(NULL, IDC_ARROW),
3335 (HBRUSH)(COLOR_BTNFACE+1),
3337 TEXT("WineStyleCheck"),
3340 atomStyleCheckClass = RegisterClass(&wc);
3343 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3345 DWORD dwActualStyle;
3346 DWORD dwActualExStyle;
3349 HWND hwndParent = NULL;
3351 ss.styleNew = dwStyleIn;
3352 ss.styleOld = dwExStyleIn;
3354 if (dwStyleIn & WS_CHILD)
3356 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3357 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3360 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3361 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3364 flush_events( TRUE );
3366 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3367 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3368 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3369 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3370 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3372 DestroyWindow(hwnd);
3373 if (hwndParent) DestroyWindow(hwndParent);
3376 /* tests what window styles the window manager automatically adds */
3377 static void test_window_styles(void)
3379 register_style_check_class();
3381 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3382 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3383 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3384 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3385 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3386 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3387 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3388 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3389 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3390 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3391 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3394 static void test_scrollwindow( HWND hwnd)
3400 ShowWindow( hwnd, SW_SHOW);
3401 UpdateWindow( hwnd);
3402 flush_events( TRUE );
3403 GetClientRect( hwnd, &rc);
3405 /* test ScrollWindow(Ex) with no clip rectangle */
3406 /* paint the lower half of the window black */
3408 rc2.top = ( rc2.top + rc2.bottom) / 2;
3409 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3410 /* paint the upper half of the window white */
3411 rc2.bottom = rc2.top;
3413 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3414 /* scroll lower half up */
3416 rc2.top = ( rc2.top + rc2.bottom) / 2;
3417 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
3418 flush_events(FALSE);
3419 /* expected: black should have scrolled to the upper half */
3420 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3421 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3422 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
3423 /* paint the lower half of the window black */
3425 rc2.top = ( rc2.top + rc2.bottom) / 2;
3426 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3427 /* paint the upper half of the window white */
3428 rc2.bottom = rc2.top;
3430 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
3431 /* scroll lower half up */
3433 rc2.top = ( rc2.top + rc2.bottom) / 2;
3435 rc3.left = rc3.right / 4;
3436 rc3.right -= rc3.right / 4;
3437 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
3438 flush_events(FALSE);
3439 /* expected: black should have scrolled to the upper half */
3440 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
3441 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3444 ReleaseDC( hwnd, hdc);
3447 static void test_scrollvalidate( HWND parent)
3450 HRGN hrgn=CreateRectRgn(0,0,0,0);
3451 HRGN exprgn, tmprgn, clipping;
3452 RECT rc, rcu, cliprc;
3453 /* create two overlapping child windows. The visual region
3454 * of hwnd1 is clipped by the overlapping part of
3455 * hwnd2 because of the WS_CLIPSIBLING style */
3458 clipping = CreateRectRgn(0,0,0,0);
3459 tmprgn = CreateRectRgn(0,0,0,0);
3460 exprgn = CreateRectRgn(0,0,0,0);
3461 hwnd2 = CreateWindowExA(0, "static", NULL,
3462 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3463 75, 30, 100, 100, parent, 0, 0, NULL);
3464 hwnd1 = CreateWindowExA(0, "static", NULL,
3465 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3466 25, 50, 100, 100, parent, 0, 0, NULL);
3467 ShowWindow( parent, SW_SHOW);
3468 UpdateWindow( parent);
3469 GetClientRect( hwnd1, &rc);
3471 SetRectRgn( clipping, 10, 10, 90, 90);
3472 hdc = GetDC( hwnd1);
3473 /* for a visual touch */
3474 TextOut( hdc, 0,10, "0123456789", 10);
3475 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3476 if (winetest_debug > 0) dump_region(hrgn);
3477 /* create a region with what is expected */
3478 SetRectRgn( exprgn, 39,0,49,74);
3479 SetRectRgn( tmprgn, 88,79,98,93);
3480 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3481 SetRectRgn( tmprgn, 0,93,98,98);
3482 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3483 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3484 trace("update rect is %d,%d - %d,%d\n",
3485 rcu.left,rcu.top,rcu.right,rcu.bottom);
3486 /* now with clipping region */
3487 SelectClipRgn( hdc, clipping);
3488 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3489 if (winetest_debug > 0) dump_region(hrgn);
3490 /* create a region with what is expected */
3491 SetRectRgn( exprgn, 39,10,49,74);
3492 SetRectRgn( tmprgn, 80,79,90,85);
3493 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3494 SetRectRgn( tmprgn, 10,85,90,90);
3495 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3496 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3497 trace("update rect is %d,%d - %d,%d\n",
3498 rcu.left,rcu.top,rcu.right,rcu.bottom);
3499 ReleaseDC( hwnd1, hdc);
3501 /* test scrolling a window with an update region */
3502 DestroyWindow( hwnd2);
3503 ValidateRect( hwnd1, NULL);
3504 SetRect( &rc, 40,40, 50,50);
3505 InvalidateRect( hwnd1, &rc, 1);
3506 GetClientRect( hwnd1, &rc);
3508 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3509 SW_SCROLLCHILDREN | SW_INVALIDATE);
3510 if (winetest_debug > 0) dump_region(hrgn);
3511 SetRectRgn( exprgn, 88,0,98,98);
3512 SetRectRgn( tmprgn, 30, 40, 50, 50);
3513 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3514 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3516 /* clear an update region */
3517 UpdateWindow( hwnd1 );
3519 SetRect( &rc, 0,40, 100,60);
3520 SetRect( &cliprc, 0,0, 100,100);
3521 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3522 if (winetest_debug > 0) dump_region( hrgn );
3523 SetRectRgn( exprgn, 0, 40, 98, 60 );
3524 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3526 /* now test ScrollWindowEx with a combination of
3527 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3528 /* make hwnd2 the child of hwnd1 */
3529 hwnd2 = CreateWindowExA(0, "static", NULL,
3530 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3531 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3532 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3533 GetClientRect( hwnd1, &rc);
3536 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3537 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3538 ValidateRect( hwnd1, NULL);
3539 ValidateRect( hwnd2, NULL);
3540 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3541 SW_SCROLLCHILDREN | SW_INVALIDATE);
3542 if (winetest_debug > 0) dump_region(hrgn);
3543 SetRectRgn( exprgn, 88,0,98,88);
3544 SetRectRgn( tmprgn, 0,88,98,98);
3545 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3546 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3548 /* SW_SCROLLCHILDREN */
3549 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3550 ValidateRect( hwnd1, NULL);
3551 ValidateRect( hwnd2, NULL);
3552 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3553 if (winetest_debug > 0) dump_region(hrgn);
3554 /* expected region is the same as in previous test */
3555 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3557 /* no SW_SCROLLCHILDREN */
3558 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3559 ValidateRect( hwnd1, NULL);
3560 ValidateRect( hwnd2, NULL);
3561 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3562 if (winetest_debug > 0) dump_region(hrgn);
3563 /* expected region is the same as in previous test */
3564 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3566 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3567 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3568 ValidateRect( hwnd1, NULL);
3569 ValidateRect( hwnd2, NULL);
3570 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3571 if (winetest_debug > 0) dump_region(hrgn);
3572 SetRectRgn( exprgn, 88,0,98,20);
3573 SetRectRgn( tmprgn, 20,20,98,30);
3574 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3575 SetRectRgn( tmprgn, 20,30,30,88);
3576 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3577 SetRectRgn( tmprgn, 0,88,30,98);
3578 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3579 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3582 DeleteObject( hrgn);
3583 DeleteObject( exprgn);
3584 DeleteObject( tmprgn);
3585 DestroyWindow( hwnd1);
3586 DestroyWindow( hwnd2);
3589 /* couple of tests of return values of scrollbar functions
3590 * called on a scrollbarless window */
3591 static void test_scroll(void)
3596 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3597 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3598 100, 100, 200, 200, 0, 0, 0, NULL);
3600 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3601 if (!ret) /* win9x */
3603 win_skip( "GetScrollRange doesn't work\n" );
3604 DestroyWindow( hwnd);
3607 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3608 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3609 si.cbSize = sizeof( si);
3610 si.fMask = SIF_PAGE;
3611 si.nPage = 0xdeadbeef;
3612 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3613 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3614 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3616 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3617 ok( ret, "GetScrollRange returns FALSE\n");
3618 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3619 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3620 si.cbSize = sizeof( si);
3621 si.fMask = SIF_PAGE;
3622 si.nPage = 0xdeadbeef;
3623 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3624 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3625 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3627 DestroyWindow( hwnd);
3630 static void test_scrolldc( HWND parent)
3633 HRGN exprgn, tmprgn, hrgn;
3634 RECT rc, rc2, rcu, cliprc;
3638 hrgn = CreateRectRgn(0,0,0,0);
3639 tmprgn = CreateRectRgn(0,0,0,0);
3640 exprgn = CreateRectRgn(0,0,0,0);
3642 hwnd1 = CreateWindowExA(0, "static", NULL,
3643 WS_CHILD| WS_VISIBLE,
3644 25, 50, 100, 100, parent, 0, 0, NULL);
3645 ShowWindow( parent, SW_SHOW);
3646 UpdateWindow( parent);
3647 flush_events( TRUE );
3648 GetClientRect( hwnd1, &rc);
3649 hdc = GetDC( hwnd1);
3650 /* paint the upper half of the window black */
3652 rc2.bottom = ( rc.top + rc.bottom) /2;
3653 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3654 /* clip region is the lower half */
3656 cliprc.top = (rc.top + rc.bottom) /2;
3657 /* test whether scrolled pixels are properly clipped */
3658 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3659 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3660 /* this scroll should not cause any visible changes */
3661 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3662 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3663 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3664 /* test with NULL clip rect */
3665 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3666 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3667 trace("update rect: %d,%d - %d,%d\n",
3668 rcu.left, rcu.top, rcu.right, rcu.bottom);
3669 if (winetest_debug > 0) dump_region(hrgn);
3670 SetRect(&rc2, 0, 0, 100, 100);
3671 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3672 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3674 SetRectRgn( exprgn, 0, 0, 20, 80);
3675 SetRectRgn( tmprgn, 0, 80, 100, 100);
3676 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3677 if (winetest_debug > 0) dump_region(exprgn);
3678 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3679 /* test clip rect > scroll rect */
3680 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3682 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3683 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3684 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3685 SetRectRgn( exprgn, 25, 25, 75, 35);
3686 SetRectRgn( tmprgn, 25, 35, 35, 75);
3687 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3688 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3689 trace("update rect: %d,%d - %d,%d\n",
3690 rcu.left, rcu.top, rcu.right, rcu.bottom);
3691 if (winetest_debug > 0) dump_region(hrgn);
3695 DeleteObject(exprgn);
3696 DeleteObject(tmprgn);
3697 DestroyWindow(hwnd1);
3700 static void test_params(void)
3705 /* Just a param check */
3706 if (pGetMonitorInfoA)
3708 SetLastError(0xdeadbeef);
3709 rc = GetWindowText(hwndMain2, NULL, 1024);
3710 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3714 /* Skips actually on Win95 and NT4 */
3715 win_skip("Test would crash on Win95\n");
3718 SetLastError(0xdeadbeef);
3719 hwnd=CreateWindow("LISTBOX", "TestList",
3720 (LBS_STANDARD & ~LBS_SORT),
3722 NULL, (HMENU)1, NULL, 0);
3724 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3725 "CreateWindow with invalid menu handle should fail\n");
3727 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3728 GetLastError() == 0xdeadbeef, /* Win9x */
3729 "wrong last error value %d\n", GetLastError());
3732 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3736 hwnd = CreateWindowEx(exStyle, class, class, style,
3743 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3746 ShowWindow(hwnd, SW_SHOW);
3748 test_nonclient_area(hwnd);
3751 DestroyWindow(hwnd);
3754 static BOOL AWR_init(void)
3758 class.style = CS_HREDRAW | CS_VREDRAW;
3759 class.lpfnWndProc = DefWindowProcA;
3760 class.cbClsExtra = 0;
3761 class.cbWndExtra = 0;
3762 class.hInstance = 0;
3763 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3764 class.hCursor = LoadCursor (0, IDC_ARROW);
3765 class.hbrBackground = 0;
3766 class.lpszMenuName = 0;
3767 class.lpszClassName = szAWRClass;
3769 if (!RegisterClass (&class)) {
3770 ok(FALSE, "RegisterClass failed\n");
3774 hmenu = CreateMenu();
3777 ok(hmenu != 0, "Failed to create menu\n");
3778 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3784 static void test_AWR_window_size(BOOL menu)
3788 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3791 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3792 WS_HSCROLL, WS_VSCROLL
3796 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3799 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3800 WS_EX_DLGMODALFRAME,
3807 /* A exhaustive check of all the styles takes too long
3808 * so just do a (hopefully representative) sample
3810 for (i = 0; i < COUNTOF(styles); ++i)
3811 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3812 for (i = 0; i < COUNTOF(exStyles); ++i) {
3813 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3814 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3819 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3821 static void test_AdjustWindowRect(void)
3826 SHOWSYSMETRIC(SM_CYCAPTION);
3827 SHOWSYSMETRIC(SM_CYSMCAPTION);
3828 SHOWSYSMETRIC(SM_CYMENU);
3829 SHOWSYSMETRIC(SM_CXEDGE);
3830 SHOWSYSMETRIC(SM_CYEDGE);
3831 SHOWSYSMETRIC(SM_CXVSCROLL);
3832 SHOWSYSMETRIC(SM_CYHSCROLL);
3833 SHOWSYSMETRIC(SM_CXFRAME);
3834 SHOWSYSMETRIC(SM_CYFRAME);
3835 SHOWSYSMETRIC(SM_CXDLGFRAME);
3836 SHOWSYSMETRIC(SM_CYDLGFRAME);
3837 SHOWSYSMETRIC(SM_CXBORDER);
3838 SHOWSYSMETRIC(SM_CYBORDER);
3840 test_AWR_window_size(FALSE);
3841 test_AWR_window_size(TRUE);
3845 #undef SHOWSYSMETRIC
3848 /* Global variables to trigger exit from loop */
3849 static int redrawComplete, WMPAINT_count;
3851 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3856 trace("doing WM_PAINT %d\n", WMPAINT_count);
3858 if (WMPAINT_count > 10 && redrawComplete == 0) {
3860 BeginPaint(hwnd, &ps);
3861 EndPaint(hwnd, &ps);
3866 return DefWindowProc(hwnd, msg, wparam, lparam);
3869 /* Ensure we exit from RedrawNow regardless of invalidated area */
3870 static void test_redrawnow(void)
3875 cls.style = CS_DBLCLKS;
3876 cls.lpfnWndProc = redraw_window_procA;
3879 cls.hInstance = GetModuleHandleA(0);
3881 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3882 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3883 cls.lpszMenuName = NULL;
3884 cls.lpszClassName = "RedrawWindowClass";
3886 if(!RegisterClassA(&cls)) {
3887 trace("Register failed %d\n", GetLastError());
3891 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3892 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3894 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3895 ShowWindow(hwndMain, SW_SHOW);
3896 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3897 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3898 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3899 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3900 redrawComplete = TRUE;
3901 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3904 DestroyWindow( hwndMain);
3907 struct parentdc_stat {
3913 struct parentdc_test {
3914 struct parentdc_stat main, main_todo;
3915 struct parentdc_stat child1, child1_todo;
3916 struct parentdc_stat child2, child2_todo;
3919 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3924 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3929 GetClientRect(hwnd, &rc);
3930 CopyRect(&t->client, &rc);
3931 GetWindowRect(hwnd, &rc);
3932 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3933 t->client.left, t->client.top, t->client.right, t->client.bottom,
3934 rc.left, rc.top, rc.right, rc.bottom);
3935 BeginPaint(hwnd, &ps);
3936 CopyRect(&t->paint, &ps.rcPaint);
3937 GetClipBox(ps.hdc, &rc);
3938 CopyRect(&t->clip, &rc);
3939 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3940 rc.left, rc.top, rc.right, rc.bottom,
3941 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3942 EndPaint(hwnd, &ps);
3945 return DefWindowProc(hwnd, msg, wparam, lparam);
3948 static void zero_parentdc_stat(struct parentdc_stat *t)
3950 SetRectEmpty(&t->client);
3951 SetRectEmpty(&t->clip);
3952 SetRectEmpty(&t->paint);
3955 static void zero_parentdc_test(struct parentdc_test *t)
3957 zero_parentdc_stat(&t->main);
3958 zero_parentdc_stat(&t->child1);
3959 zero_parentdc_stat(&t->child2);
3962 #define parentdc_field_ok(t, w, r, f, got) \
3963 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3964 ": expected %d, got %d\n", \
3967 #define parentdc_todo_field_ok(t, w, r, f, got) \
3968 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3969 else parentdc_field_ok(t, w, r, f, got)
3971 #define parentdc_rect_ok(t, w, r, got) \
3972 parentdc_todo_field_ok(t, w, r, left, got); \
3973 parentdc_todo_field_ok(t, w, r, top, got); \
3974 parentdc_todo_field_ok(t, w, r, right, got); \
3975 parentdc_todo_field_ok(t, w, r, bottom, got);
3977 #define parentdc_win_ok(t, w, got) \
3978 parentdc_rect_ok(t, w, client, got); \
3979 parentdc_rect_ok(t, w, clip, got); \
3980 parentdc_rect_ok(t, w, paint, got);
3982 #define parentdc_ok(t, got) \
3983 parentdc_win_ok(t, main, got); \
3984 parentdc_win_ok(t, child1, got); \
3985 parentdc_win_ok(t, child2, got);
3987 static void test_csparentdc(void)
3989 WNDCLASSA clsMain, cls;
3990 HWND hwndMain, hwnd1, hwnd2;
3993 struct parentdc_test test_answer;
3995 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3996 const struct parentdc_test test1 =
3998 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3999 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4000 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4003 const struct parentdc_test test2 =
4005 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4006 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4007 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4010 const struct parentdc_test test3 =
4012 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4013 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4014 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4017 const struct parentdc_test test4 =
4019 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4020 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4021 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4024 const struct parentdc_test test5 =
4026 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4027 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4028 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4031 const struct parentdc_test test6 =
4033 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4034 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4035 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4038 const struct parentdc_test test7 =
4040 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4041 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4042 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4046 clsMain.style = CS_DBLCLKS;
4047 clsMain.lpfnWndProc = parentdc_window_procA;
4048 clsMain.cbClsExtra = 0;
4049 clsMain.cbWndExtra = 0;
4050 clsMain.hInstance = GetModuleHandleA(0);
4052 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4053 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4054 clsMain.lpszMenuName = NULL;
4055 clsMain.lpszClassName = "ParentDcMainWindowClass";
4057 if(!RegisterClassA(&clsMain)) {
4058 trace("Register failed %d\n", GetLastError());
4062 cls.style = CS_DBLCLKS | CS_PARENTDC;
4063 cls.lpfnWndProc = parentdc_window_procA;
4066 cls.hInstance = GetModuleHandleA(0);
4068 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4069 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4070 cls.lpszMenuName = NULL;
4071 cls.lpszClassName = "ParentDcWindowClass";
4073 if(!RegisterClassA(&cls)) {
4074 trace("Register failed %d\n", GetLastError());
4078 SetRect(&rc, 0, 0, 150, 150);
4079 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4080 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4081 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4082 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4083 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4084 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4085 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4086 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4087 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4088 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4089 ShowWindow(hwndMain, SW_SHOW);
4090 ShowWindow(hwnd1, SW_SHOW);
4091 ShowWindow(hwnd2, SW_SHOW);
4092 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4093 flush_events( TRUE );
4095 zero_parentdc_test(&test_answer);
4096 InvalidateRect(hwndMain, NULL, TRUE);
4097 flush_events( TRUE );
4098 parentdc_ok(test1, test_answer);
4100 zero_parentdc_test(&test_answer);
4101 SetRect(&rc, 0, 0, 50, 50);
4102 InvalidateRect(hwndMain, &rc, TRUE);
4103 flush_events( TRUE );
4104 parentdc_ok(test2, test_answer);
4106 zero_parentdc_test(&test_answer);
4107 SetRect(&rc, 0, 0, 10, 10);
4108 InvalidateRect(hwndMain, &rc, TRUE);
4109 flush_events( TRUE );
4110 parentdc_ok(test3, test_answer);
4112 zero_parentdc_test(&test_answer);
4113 SetRect(&rc, 40, 40, 50, 50);
4114 InvalidateRect(hwndMain, &rc, TRUE);
4115 flush_events( TRUE );
4116 parentdc_ok(test4, test_answer);
4118 zero_parentdc_test(&test_answer);
4119 SetRect(&rc, 20, 20, 60, 60);
4120 InvalidateRect(hwndMain, &rc, TRUE);
4121 flush_events( TRUE );
4122 parentdc_ok(test5, test_answer);
4124 zero_parentdc_test(&test_answer);
4125 SetRect(&rc, 0, 0, 10, 10);
4126 InvalidateRect(hwnd1, &rc, TRUE);
4127 flush_events( TRUE );
4128 parentdc_ok(test6, test_answer);
4130 zero_parentdc_test(&test_answer);
4131 SetRect(&rc, -5, -5, 65, 65);
4132 InvalidateRect(hwnd1, &rc, TRUE);
4133 flush_events( TRUE );
4134 parentdc_ok(test7, test_answer);
4136 DestroyWindow(hwndMain);
4137 DestroyWindow(hwnd1);
4138 DestroyWindow(hwnd2);
4141 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4143 return DefWindowProcA(hwnd, msg, wparam, lparam);
4146 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4148 return DefWindowProcW(hwnd, msg, wparam, lparam);
4151 static void test_IsWindowUnicode(void)
4153 static const char ansi_class_nameA[] = "ansi class name";
4154 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4155 static const char unicode_class_nameA[] = "unicode class name";
4156 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4161 memset(&classW, 0, sizeof(classW));
4162 classW.hInstance = GetModuleHandleA(0);
4163 classW.lpfnWndProc = def_window_procW;
4164 classW.lpszClassName = unicode_class_nameW;
4165 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4167 memset(&classA, 0, sizeof(classA));
4168 classA.hInstance = GetModuleHandleA(0);
4169 classA.lpfnWndProc = def_window_procA;
4170 classA.lpszClassName = ansi_class_nameA;
4171 assert(RegisterClassA(&classA));
4173 /* unicode class: window proc */
4174 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4175 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4178 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4179 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4180 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4181 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4182 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4184 DestroyWindow(hwnd);
4186 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4187 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4190 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4191 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4192 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4193 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4194 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4196 DestroyWindow(hwnd);
4198 /* ansi class: window proc */
4199 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4200 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4203 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4204 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
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");
4209 DestroyWindow(hwnd);
4211 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4212 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4215 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4216 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4217 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4218 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4219 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4221 DestroyWindow(hwnd);
4223 /* unicode class: class proc */
4224 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4225 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4228 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4229 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4230 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4231 /* do not restore class window proc back to unicode */
4233 DestroyWindow(hwnd);
4235 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4236 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4239 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4240 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4241 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4243 DestroyWindow(hwnd);
4245 /* ansi class: class proc */
4246 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4247 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4250 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4251 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4252 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4253 /* do not restore class window proc back to ansi */
4255 DestroyWindow(hwnd);
4257 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4258 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4261 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4262 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4263 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4265 DestroyWindow(hwnd);
4268 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4272 if (msg != WM_GETMINMAXINFO)
4273 return DefWindowProc(hwnd, msg, wp, lp);
4275 minmax = (MINMAXINFO *)lp;
4277 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4279 minmax->ptReserved.x = 0;
4280 minmax->ptReserved.y = 0;
4281 minmax->ptMaxSize.x = 400;
4282 minmax->ptMaxSize.y = 400;
4283 minmax->ptMaxPosition.x = 300;
4284 minmax->ptMaxPosition.y = 300;
4285 minmax->ptMaxTrackSize.x = 200;
4286 minmax->ptMaxTrackSize.y = 200;
4287 minmax->ptMinTrackSize.x = 100;
4288 minmax->ptMinTrackSize.y = 100;
4291 DefWindowProc(hwnd, msg, wp, lp);
4295 static int expected_cx, expected_cy;
4296 static RECT expected_rect, broken_rect;
4298 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4302 case WM_GETMINMAXINFO:
4305 GetWindowRect( hwnd, &rect );
4306 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4307 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4308 return DefWindowProc(hwnd, msg, wp, lp);
4313 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4315 GetWindowRect( hwnd, &rect );
4316 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4317 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4318 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4319 "wrong x size %d/%d\n", cs->cx, expected_cx );
4320 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4321 "wrong y size %d/%d\n", cs->cy, expected_cy );
4322 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4323 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4324 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4325 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4326 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4327 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4328 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4329 rect.left, rect.top, rect.right, rect.bottom,
4330 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4331 return DefWindowProc(hwnd, msg, wp, lp);
4335 RECT rect, *r = (RECT *)lp;
4336 GetWindowRect( hwnd, &rect );
4337 ok( !memcmp( &rect, r, sizeof(rect) ),
4338 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4339 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4340 return DefWindowProc(hwnd, msg, wp, lp);
4343 return DefWindowProc(hwnd, msg, wp, lp);
4347 static void test_CreateWindow(void)
4355 #define expect_menu(window, menu) \
4356 SetLastError(0xdeadbeef); \
4357 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4359 #define expect_style(window, style)\
4360 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4362 #define expect_ex_style(window, ex_style)\
4363 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4365 #define expect_gle_broken_9x(gle)\
4366 ok(GetLastError() == gle ||\
4367 broken(GetLastError() == 0xdeadbeef),\
4368 "IsMenu set error %d\n", GetLastError())
4370 hmenu = CreateMenu();
4372 parent = GetDesktopWindow();
4373 assert(parent != 0);
4375 SetLastError(0xdeadbeef);
4376 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4379 SetLastError(0xdeadbeef);
4380 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4381 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4382 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4383 expect_menu(hwnd, 1);
4384 expect_style(hwnd, WS_CHILD);
4385 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4386 DestroyWindow(hwnd);
4388 SetLastError(0xdeadbeef);
4389 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4390 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4391 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4392 expect_menu(hwnd, 1);
4393 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4394 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4395 DestroyWindow(hwnd);
4397 SetLastError(0xdeadbeef);
4398 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4399 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4400 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4401 expect_menu(hwnd, 1);
4402 expect_style(hwnd, WS_CHILD);
4403 expect_ex_style(hwnd, 0);
4404 DestroyWindow(hwnd);
4406 SetLastError(0xdeadbeef);
4407 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4408 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4409 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4410 expect_menu(hwnd, 1);
4411 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4412 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4413 DestroyWindow(hwnd);
4416 SetLastError(0xdeadbeef);
4417 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4418 0, 0, 100, 100, parent, hmenu, 0, NULL);
4419 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4420 expect_menu(hwnd, hmenu);
4421 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4422 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4423 DestroyWindow(hwnd);
4424 SetLastError(0xdeadbeef);
4425 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4426 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4428 hmenu = CreateMenu();
4430 SetLastError(0xdeadbeef);
4431 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4432 0, 0, 100, 100, parent, hmenu, 0, NULL);
4433 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4434 expect_menu(hwnd, hmenu);
4435 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4436 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4437 DestroyWindow(hwnd);
4438 SetLastError(0xdeadbeef);
4439 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4440 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4442 hmenu = CreateMenu();
4444 SetLastError(0xdeadbeef);
4445 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4446 0, 0, 100, 100, parent, hmenu, 0, NULL);
4447 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4448 expect_menu(hwnd, hmenu);
4449 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4450 expect_ex_style(hwnd, 0);
4451 DestroyWindow(hwnd);
4452 SetLastError(0xdeadbeef);
4453 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4454 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4456 hmenu = CreateMenu();
4458 SetLastError(0xdeadbeef);
4459 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4460 0, 0, 100, 100, parent, hmenu, 0, NULL);
4461 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4462 expect_menu(hwnd, hmenu);
4463 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4464 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4465 DestroyWindow(hwnd);
4466 SetLastError(0xdeadbeef);
4467 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4468 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4470 /* WS_CHILD | WS_POPUP */
4471 SetLastError(0xdeadbeef);
4472 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4473 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4474 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4475 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4477 DestroyWindow(hwnd);
4479 hmenu = CreateMenu();
4481 SetLastError(0xdeadbeef);
4482 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4483 0, 0, 100, 100, parent, hmenu, 0, NULL);
4484 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4485 expect_menu(hwnd, hmenu);
4486 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4487 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4488 DestroyWindow(hwnd);
4489 SetLastError(0xdeadbeef);
4490 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4491 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4493 SetLastError(0xdeadbeef);
4494 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4495 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4496 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4497 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4499 DestroyWindow(hwnd);
4501 hmenu = CreateMenu();
4503 SetLastError(0xdeadbeef);
4504 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4505 0, 0, 100, 100, parent, hmenu, 0, NULL);
4506 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4507 expect_menu(hwnd, hmenu);
4508 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4509 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4510 DestroyWindow(hwnd);
4511 SetLastError(0xdeadbeef);
4512 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4513 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4515 SetLastError(0xdeadbeef);
4516 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4517 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4518 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4519 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4521 DestroyWindow(hwnd);
4523 hmenu = CreateMenu();
4525 SetLastError(0xdeadbeef);
4526 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4527 0, 0, 100, 100, parent, hmenu, 0, NULL);
4528 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4529 expect_menu(hwnd, hmenu);
4530 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4531 expect_ex_style(hwnd, 0);
4532 DestroyWindow(hwnd);
4533 SetLastError(0xdeadbeef);
4534 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4535 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4537 SetLastError(0xdeadbeef);
4538 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4539 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4540 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4541 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4543 DestroyWindow(hwnd);
4545 hmenu = CreateMenu();
4547 SetLastError(0xdeadbeef);
4548 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4549 0, 0, 100, 100, parent, hmenu, 0, NULL);
4550 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4551 expect_menu(hwnd, hmenu);
4552 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4553 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4554 DestroyWindow(hwnd);
4555 SetLastError(0xdeadbeef);
4556 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4557 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4559 /* test child window sizing */
4561 cls.lpfnWndProc = minmax_wnd_proc;
4564 cls.hInstance = GetModuleHandle(0);
4566 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4567 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4568 cls.lpszMenuName = NULL;
4569 cls.lpszClassName = "MinMax_WndClass";
4570 RegisterClass(&cls);
4572 SetLastError(0xdeadbeef);
4573 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4574 0, 0, 100, 100, 0, 0, 0, NULL);
4575 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4576 expect_menu(parent, 0);
4577 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4578 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4580 memset(&minmax, 0, sizeof(minmax));
4581 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4582 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4583 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4584 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4585 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4587 GetWindowRect(parent, &rc);
4588 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4589 GetClientRect(parent, &rc);
4590 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4592 InflateRect(&rc, 200, 200);
4593 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4595 SetLastError(0xdeadbeef);
4596 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4597 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4598 parent, (HMENU)1, 0, NULL);
4599 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4600 expect_menu(hwnd, 1);
4601 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4602 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4604 memset(&minmax, 0, sizeof(minmax));
4605 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4606 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4608 GetWindowRect(hwnd, &rc);
4609 OffsetRect(&rc, -rc.left, -rc.top);
4610 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4611 rc.left, rc.top, rc.right, rc.bottom,
4612 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4613 DestroyWindow(hwnd);
4615 cls.lpfnWndProc = winsizes_wnd_proc;
4616 cls.lpszClassName = "Sizes_WndClass";
4617 RegisterClass(&cls);
4619 expected_cx = expected_cy = 200000;
4620 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4621 broken_rect = expected_rect;
4622 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4623 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4624 GetClientRect( hwnd, &rc );
4625 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4626 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4627 DestroyWindow(hwnd);
4629 expected_cx = expected_cy = -10;
4630 SetRect( &expected_rect, 0, 0, 0, 0 );
4631 SetRect( &broken_rect, 0, 0, -10, -10 );
4632 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4633 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4634 GetClientRect( hwnd, &rc );
4635 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4636 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4637 DestroyWindow(hwnd);
4639 expected_cx = expected_cy = -200000;
4640 SetRect( &expected_rect, 0, 0, 0, 0 );
4641 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4642 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4643 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4644 GetClientRect( hwnd, &rc );
4645 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4646 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4647 DestroyWindow(hwnd);
4649 /* we need a parent at 0,0 so that child coordinates match */
4650 DestroyWindow(parent);
4651 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4652 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4655 expected_cy = 0x7fffffff;
4656 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4657 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4658 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4659 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4660 GetClientRect( hwnd, &rc );
4661 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4662 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4663 DestroyWindow(hwnd);
4665 expected_cx = 0x7fffffff;
4666 expected_cy = 0x7fffffff;
4667 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4668 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4669 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4670 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4671 GetClientRect( hwnd, &rc );
4672 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4673 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4674 DestroyWindow(hwnd);
4676 /* top level window */
4677 expected_cx = expected_cy = 200000;
4678 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4679 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4680 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4681 GetClientRect( hwnd, &rc );
4682 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4683 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4684 DestroyWindow(hwnd);
4686 DestroyWindow(parent);
4688 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4689 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4691 #undef expect_gle_broken_9x
4694 #undef expect_ex_style
4697 /* function that remembers whether the system the test is running on sets the
4698 * last error for user32 functions to make the tests stricter */
4699 static int check_error(DWORD actual, DWORD expected)
4701 static int sets_last_error = -1;
4702 if (sets_last_error == -1)
4703 sets_last_error = (actual != 0xdeadbeef);
4704 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4707 static void test_SetWindowLong(void)
4710 WNDPROC old_window_procW;
4712 SetLastError(0xdeadbeef);
4713 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4714 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4715 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4716 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4718 SetLastError(0xdeadbeef);
4719 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4720 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4721 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4722 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4724 SetLastError(0xdeadbeef);
4725 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4726 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4727 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4728 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4729 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4730 ok((WNDPROC)retval == main_window_procA,
4731 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4732 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4734 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4735 SetLastError(0xdeadbeef);
4736 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4737 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4739 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4740 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4741 ok((WNDPROC)retval == old_window_procW,
4742 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4743 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4745 /* set it back to ANSI */
4746 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4750 static void test_ShowWindow(void)
4757 SetRect(&rcMain, 120, 120, 210, 210);
4759 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4760 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4761 WS_MAXIMIZEBOX | WS_POPUP,
4762 rcMain.left, rcMain.top,
4763 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4767 style = GetWindowLong(hwnd, GWL_STYLE);
4768 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4769 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4770 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4771 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4772 GetWindowRect(hwnd, &rc);
4773 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4774 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4775 rc.left, rc.top, rc.right, rc.bottom);
4777 ret = ShowWindow(hwnd, SW_SHOW);
4778 ok(!ret, "not expected ret: %lu\n", ret);
4779 style = GetWindowLong(hwnd, GWL_STYLE);
4780 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4781 ok(style & WS_VISIBLE, "window should be visible\n");
4782 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4783 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4784 GetWindowRect(hwnd, &rc);
4785 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4786 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4787 rc.left, rc.top, rc.right, rc.bottom);
4789 ret = ShowWindow(hwnd, SW_MINIMIZE);
4790 ok(ret, "not expected ret: %lu\n", ret);
4791 style = GetWindowLong(hwnd, GWL_STYLE);
4792 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4793 ok(style & WS_VISIBLE, "window should be visible\n");
4794 ok(style & WS_MINIMIZE, "window should be minimized\n");
4795 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4796 GetWindowRect(hwnd, &rc);
4797 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4799 ShowWindow(hwnd, SW_RESTORE);
4800 ok(ret, "not expected ret: %lu\n", ret);
4801 style = GetWindowLong(hwnd, GWL_STYLE);
4802 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4803 ok(style & WS_VISIBLE, "window should be visible\n");
4804 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4805 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4806 GetWindowRect(hwnd, &rc);
4807 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4808 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4809 rc.left, rc.top, rc.right, rc.bottom);
4811 ret = EnableWindow(hwnd, FALSE);
4812 ok(!ret, "not expected ret: %lu\n", ret);
4813 style = GetWindowLong(hwnd, GWL_STYLE);
4814 ok(style & WS_DISABLED, "window should be disabled\n");
4816 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4817 ok(!ret, "not expected ret: %lu\n", ret);
4818 style = GetWindowLong(hwnd, GWL_STYLE);
4819 ok(style & WS_DISABLED, "window should be disabled\n");
4820 ok(style & WS_VISIBLE, "window should be visible\n");
4821 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4822 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4823 GetWindowRect(hwnd, &rc);
4824 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4825 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4826 rc.left, rc.top, rc.right, rc.bottom);
4828 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4829 ok(!ret, "not expected ret: %lu\n", ret);
4830 style = GetWindowLong(hwnd, GWL_STYLE);
4831 ok(style & WS_DISABLED, "window should be disabled\n");
4832 ok(style & WS_VISIBLE, "window should be visible\n");
4833 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4834 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4835 GetWindowRect(hwnd, &rc);
4836 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4837 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4838 rc.left, rc.top, rc.right, rc.bottom);
4840 ret = ShowWindow(hwnd, SW_MINIMIZE);
4841 ok(ret, "not expected ret: %lu\n", ret);
4842 style = GetWindowLong(hwnd, GWL_STYLE);
4843 ok(style & WS_DISABLED, "window should be disabled\n");
4844 ok(style & WS_VISIBLE, "window should be visible\n");
4845 ok(style & WS_MINIMIZE, "window should be minimized\n");
4846 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4847 GetWindowRect(hwnd, &rc);
4848 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4850 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4851 ok(!ret, "not expected ret: %lu\n", ret);
4852 style = GetWindowLong(hwnd, GWL_STYLE);
4853 ok(style & WS_DISABLED, "window should be disabled\n");
4854 ok(style & WS_VISIBLE, "window should be visible\n");
4855 ok(style & WS_MINIMIZE, "window should be minimized\n");
4856 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4857 GetWindowRect(hwnd, &rc);
4858 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4860 ret = ShowWindow(hwnd, SW_RESTORE);
4861 ok(ret, "not expected ret: %lu\n", ret);
4862 style = GetWindowLong(hwnd, GWL_STYLE);
4863 ok(style & WS_DISABLED, "window should be disabled\n");
4864 ok(style & WS_VISIBLE, "window should be visible\n");
4865 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4866 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4867 GetWindowRect(hwnd, &rc);
4868 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4869 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4870 rc.left, rc.top, rc.right, rc.bottom);
4872 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4873 ok(!ret, "not expected ret: %lu\n", ret);
4874 ok(IsWindow(hwnd), "window should exist\n");
4876 ret = EnableWindow(hwnd, TRUE);
4877 ok(ret, "not expected ret: %lu\n", ret);
4879 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4880 ok(!ret, "not expected ret: %lu\n", ret);
4881 ok(!IsWindow(hwnd), "window should not exist\n");
4884 static void test_gettext(void)
4887 LPCSTR clsname = "gettexttest";
4891 memset( &cls, 0, sizeof cls );
4892 cls.lpfnWndProc = DefWindowProc;
4893 cls.lpszClassName = clsname;
4894 cls.hInstance = GetModuleHandle(NULL);
4896 if (!RegisterClass( &cls )) return;
4898 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4899 ok( hwnd != NULL, "window was null\n");
4901 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4902 ok( r == 0, "settext should return zero\n");
4904 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4905 ok( r == 0, "settext should return zero (%ld)\n", r);
4907 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4908 ok( r == 0, "settext should return zero (%ld)\n", r);
4910 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4911 ok( r == 0, "settext should return zero (%ld)\n", r);
4913 DestroyWindow(hwnd);
4914 UnregisterClass( clsname, NULL );
4918 static void test_GetUpdateRect(void)
4921 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4923 HWND hgrandparent, hparent, hchild;
4925 static const char classNameA[] = "GetUpdateRectClass";
4927 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4928 0, 0, 100, 100, NULL, NULL, 0, NULL);
4930 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4931 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4933 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4934 10, 10, 30, 30, hparent, NULL, 0, NULL);
4936 ShowWindow(hgrandparent, SW_SHOW);
4937 UpdateWindow(hgrandparent);
4938 flush_events( TRUE );
4940 ShowWindow(hchild, SW_HIDE);
4941 SetRect(&rc2, 0, 0, 0, 0);
4942 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4943 ok(!ret, "GetUpdateRect returned not empty region\n");
4944 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4945 rc1.left, rc1.top, rc1.right, rc1.bottom,
4946 rc2.left, rc2.top, rc2.right, rc2.bottom);
4948 SetRect(&rc2, 10, 10, 40, 40);
4949 ret = GetUpdateRect(hparent, &rc1, FALSE);
4950 ok(ret, "GetUpdateRect returned empty region\n");
4951 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4952 rc1.left, rc1.top, rc1.right, rc1.bottom,
4953 rc2.left, rc2.top, rc2.right, rc2.bottom);
4955 parent_wm_paint = FALSE;
4956 grandparent_wm_paint = FALSE;
4957 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4959 if (msg.message == WM_PAINT)
4961 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4962 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4964 DispatchMessage(&msg);
4966 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4967 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4969 DestroyWindow(hgrandparent);
4972 cls.lpfnWndProc = DefWindowProcA;
4975 cls.hInstance = GetModuleHandleA(0);
4977 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4978 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4979 cls.lpszMenuName = NULL;
4980 cls.lpszClassName = classNameA;
4982 if(!RegisterClassA(&cls)) {
4983 trace("Register failed %d\n", GetLastError());
4987 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4988 0, 0, 100, 100, NULL, NULL, 0, NULL);
4990 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4991 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4993 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4994 10, 10, 30, 30, hparent, NULL, 0, NULL);
4996 ShowWindow(hgrandparent, SW_SHOW);
4997 UpdateWindow(hgrandparent);
4998 flush_events( TRUE );
5000 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5001 ok(!ret, "GetUpdateRect returned not empty region\n");
5003 ShowWindow(hchild, SW_HIDE);
5005 SetRect(&rc2, 0, 0, 0, 0);
5006 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5007 ok(!ret, "GetUpdateRect returned not empty region\n");
5008 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5009 rc1.left, rc1.top, rc1.right, rc1.bottom,
5010 rc2.left, rc2.top, rc2.right, rc2.bottom);
5012 SetRect(&rc2, 10, 10, 40, 40);
5013 ret = GetUpdateRect(hparent, &rc1, FALSE);
5014 ok(ret, "GetUpdateRect returned empty region\n");
5015 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5016 rc1.left, rc1.top, rc1.right, rc1.bottom,
5017 rc2.left, rc2.top, rc2.right, rc2.bottom);
5019 parent_wm_paint = FALSE;
5020 grandparent_wm_paint = FALSE;
5021 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5023 if (msg.message == WM_PAINT)
5025 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5026 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5028 DispatchMessage(&msg);
5030 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5031 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5033 DestroyWindow(hgrandparent);
5037 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5045 const int waitTime = 2000;
5047 BeginPaint(hwnd, &ps);
5049 /* create and destroy window to create an exposed region on this window */
5050 win = CreateWindowA("static", "win", WS_VISIBLE,
5051 10,10,50,50, NULL, NULL, 0, NULL);
5054 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5056 ValidateRect(hwnd, NULL);
5057 EndPaint(hwnd, &ps);
5059 if(waitResult != WAIT_TIMEOUT)
5061 GetUpdateRect(hwnd, &updateRect, FALSE);
5062 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5067 return DefWindowProc(hwnd, msg, wParam, lParam);
5070 static void test_Expose(void)
5075 memset(&cls, 0, sizeof(WNDCLASSA));
5076 cls.lpfnWndProc = TestExposedRegion_WndProc;
5077 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5078 cls.lpszClassName = "TestExposeClass";
5079 atom = RegisterClassA(&cls);
5081 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5082 0, 0, 200, 100, NULL, NULL, 0, NULL);
5088 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5090 static UINT ncredrawflags;
5096 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5099 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5102 BeginPaint(hwnd, &ps);
5103 EndPaint(hwnd, &ps);
5106 return DefWindowProc(hwnd, msg, wParam, lParam);
5109 static void run_NCRedrawLoop(UINT flags)
5116 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5117 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5118 NULL, NULL, 0, &flags);
5119 ShowWindow(hwnd, SW_SHOW);
5121 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5123 if (msg.message == WM_PAINT) loopcount++;
5124 if (loopcount >= 100) break;
5125 TranslateMessage(&msg);
5126 DispatchMessage(&msg);
5127 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5129 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5130 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5132 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5133 DestroyWindow(hwnd);
5136 static void test_NCRedraw(void)
5140 wndclass.lpszClassName = "TestNCRedrawClass";
5141 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5142 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5143 wndclass.cbClsExtra = 0;
5144 wndclass.cbWndExtra = 0;
5145 wndclass.hInstance = 0;
5146 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5147 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5148 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5149 wndclass.lpszMenuName = NULL;
5151 RegisterClassA(&wndclass);
5153 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5154 run_NCRedrawLoop(RDW_INVALIDATE);
5157 static void test_GetWindowModuleFileName(void)
5162 char buf1[MAX_PATH], buf2[MAX_PATH];
5164 if (!pGetWindowModuleFileNameA)
5166 win_skip("GetWindowModuleFileNameA is not available\n");
5170 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5173 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5174 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5177 SetLastError(0xdeadbeef);
5178 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5179 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5182 SetLastError(0xdeadbeef);
5183 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5184 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5185 "GetWindowModuleFileNameA error %u\n", GetLastError());
5189 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5190 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5192 hinst = GetModuleHandle(0);
5194 SetLastError(0xdeadbeef);
5195 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5196 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5197 "expected %u, got %u\n", ret1 - 2, ret2);
5198 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5199 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5200 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5202 SetLastError(0xdeadbeef);
5203 ret2 = GetModuleFileName(hinst, buf2, 0);
5204 ok(!ret2, "GetModuleFileName should return 0\n");
5205 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5206 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5207 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5209 SetLastError(0xdeadbeef);
5210 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5211 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
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 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5219 ok(!ret2, "expected 0, got %u\n", ret2);
5220 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5221 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5222 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5224 DestroyWindow(hwnd);
5227 hwnd = (HWND)0xdeadbeef;
5228 SetLastError(0xdeadbeef);
5229 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5230 ok(!ret1, "expected 0, got %u\n", ret1);
5231 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5232 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
5234 hwnd = FindWindow("Shell_TrayWnd", NULL);
5235 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
5236 SetLastError(0xdeadbeef);
5237 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5238 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
5240 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
5242 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
5243 hwnd = GetDesktopWindow();
5244 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
5245 SetLastError(0xdeadbeef);
5246 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5248 ret1 == ret2 || /* vista */
5249 broken(ret2), /* some win98 return user.exe as file name */
5250 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
5254 static void test_hwnd_message(void)
5256 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
5257 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
5259 HWND parent = 0, hwnd, found;
5262 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
5263 on CreateWindowExA and crash later in the test.
5264 Use UNICODE here to fail on win9x */
5265 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
5266 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
5269 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
5273 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
5277 HWND root, desktop = GetDesktopWindow();
5279 parent = pGetAncestor(hwnd, GA_PARENT);
5280 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
5281 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
5282 root = pGetAncestor(hwnd, GA_ROOT);
5283 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
5284 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
5285 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
5286 trace("parent %p root %p desktop %p\n", parent, root, desktop);
5287 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
5288 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
5289 GetWindowRect( parent, &rect );
5290 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
5291 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5293 GetWindowRect( hwnd, &rect );
5294 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
5295 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5297 /* test FindWindow behavior */
5299 found = FindWindowExA( 0, 0, 0, "message window" );
5300 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5301 SetLastError(0xdeadbeef);
5302 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
5303 ok( found == 0, "found message window %p/%p\n", found, hwnd );
5304 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
5307 found = FindWindowExA( parent, 0, 0, "message window" );
5308 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
5311 /* test IsChild behavior */
5313 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
5315 /* test IsWindowVisible behavior */
5317 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5318 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5320 DestroyWindow(hwnd);
5323 static void test_layered_window(void)
5331 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5333 win_skip( "layered windows not supported\n" );
5336 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5337 100, 100, 200, 200, 0, 0, 0, NULL);
5339 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5340 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5341 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5342 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5343 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5344 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5345 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5346 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5347 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5348 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5349 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5350 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5351 ok( alpha == 44, "wrong alpha %u\n", alpha );
5352 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5354 /* clearing WS_EX_LAYERED resets attributes */
5355 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5356 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5357 ok( !ret, "GetLayeredWindowAttributes should fail on no longer 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, 0x654321, 22, LWA_COLORKEY | 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 == 0x654321, "wrong color key %x\n", key );
5366 ok( alpha == 22, "wrong alpha %u\n", alpha );
5367 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5369 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5370 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5372 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5373 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5374 ok( key == 0x888888, "wrong color key %x\n", key );
5375 /* alpha not changed on vista if LWA_ALPHA is not set */
5376 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5377 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5379 /* color key may or may not be changed without LWA_COLORKEY */
5380 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5381 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5383 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5384 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5385 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5386 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5387 ok( flags == 0, "wrong flags %x\n", flags );
5389 /* default alpha and color key is 0 */
5390 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5391 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5392 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5393 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5394 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5395 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5396 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5397 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5398 ok( flags == 0, "wrong flags %x\n", flags );
5400 DestroyWindow( hwnd );
5403 static MONITORINFO mi;
5405 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5411 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5412 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5413 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5414 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5415 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5416 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5417 cs->x, cs->y, cs->cx, cs->cy);
5420 case WM_GETMINMAXINFO:
5422 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5423 dump_minmax_info(minmax);
5424 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5425 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5426 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5427 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5431 return DefWindowProc(hwnd, msg, wp, lp);
5434 static void test_fullscreen(void)
5436 static const DWORD t_style[] = {
5437 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5439 static const DWORD t_ex_style[] = {
5440 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5450 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5452 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5457 SetLastError(0xdeadbeef);
5458 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5459 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5461 mi.cbSize = sizeof(mi);
5462 SetLastError(0xdeadbeef);
5463 ret = pGetMonitorInfoA(hmon, &mi);
5464 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5465 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5466 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5467 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5470 cls.lpfnWndProc = fullscreen_wnd_proc;
5473 cls.hInstance = GetModuleHandle(0);
5475 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5476 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5477 cls.lpszMenuName = NULL;
5478 cls.lpszClassName = "fullscreen_class";
5479 RegisterClass(&cls);
5481 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5483 DWORD style, ex_style;
5485 /* avoid a WM interaction */
5486 assert(!(t_style[i] & WS_VISIBLE));
5488 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5493 ex_style = t_ex_style[j];
5495 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5496 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5497 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5498 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5499 GetWindowRect(hwnd, &rc);
5500 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5501 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5502 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5503 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5504 DestroyWindow(hwnd);
5506 style = t_style[i] | WS_MAXIMIZE;
5507 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5508 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5509 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5510 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5511 GetWindowRect(hwnd, &rc);
5512 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5513 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5514 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5515 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5516 DestroyWindow(hwnd);
5518 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5519 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5520 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5521 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5522 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5523 GetWindowRect(hwnd, &rc);
5524 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5525 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5526 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5527 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5528 DestroyWindow(hwnd);
5530 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5531 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5532 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5533 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5534 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5535 GetWindowRect(hwnd, &rc);
5536 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5537 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5538 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5539 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5540 DestroyWindow(hwnd);
5542 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5543 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5544 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5545 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5546 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5547 GetWindowRect(hwnd, &rc);
5548 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5549 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5550 fixup = min(abs(rc.left), abs(rc.top));
5551 InflateRect(&rc, -fixup, -fixup);
5552 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5553 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5554 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5555 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5556 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5557 DestroyWindow(hwnd);
5559 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5560 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5561 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5562 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5563 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5564 GetWindowRect(hwnd, &rc);
5565 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5566 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5567 fixup = min(abs(rc.left), abs(rc.top));
5568 InflateRect(&rc, -fixup, -fixup);
5569 if (style & (WS_CHILD | WS_POPUP))
5570 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5571 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5572 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5574 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5575 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5576 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5577 DestroyWindow(hwnd);
5581 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5584 static BOOL test_thick_child_got_minmax;
5585 static const char * test_thick_child_name;
5586 static LONG test_thick_child_style;
5587 static LONG test_thick_child_exStyle;
5589 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5592 int expectedMinTrackX;
5593 int expectedMinTrackY;
5594 int actualMinTrackX;
5595 int actualMinTrackY;
5596 int expectedMaxTrackX;
5597 int expectedMaxTrackY;
5598 int actualMaxTrackX;
5599 int actualMaxTrackY;
5600 int expectedMaxSizeX;
5601 int expectedMaxSizeY;
5612 case WM_GETMINMAXINFO:
5614 minmax = (MINMAXINFO *)lparam;
5615 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5616 dump_minmax_info( minmax );
5618 test_thick_child_got_minmax = TRUE;
5621 adjustedStyle = test_thick_child_style;
5622 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5623 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5624 GetClientRect(GetParent(hwnd), &rect);
5625 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5627 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5629 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5630 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5634 expectedMinTrackX = -2 * rect.left;
5635 expectedMinTrackY = -2 * rect.top;
5637 actualMinTrackX = minmax->ptMinTrackSize.x;
5638 actualMinTrackY = minmax->ptMinTrackSize.y;
5640 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5641 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5642 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5643 test_thick_child_name);
5645 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5646 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5647 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5648 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5649 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5650 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5651 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5652 test_thick_child_name);
5654 expectedMaxSizeX = rect.right - rect.left;
5655 expectedMaxSizeY = rect.bottom - rect.top;
5656 actualMaxSizeX = minmax->ptMaxSize.x;
5657 actualMaxSizeY = minmax->ptMaxSize.y;
5659 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5660 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5661 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5662 test_thick_child_name);
5665 expectedPosX = rect.left;
5666 expectedPosY = rect.top;
5667 actualPosX = minmax->ptMaxPosition.x;
5668 actualPosY = minmax->ptMaxPosition.y;
5669 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5670 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5671 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5677 return DefWindowProcA(hwnd, msg, wparam, lparam);
5680 #define NUMBER_OF_THICK_CHILD_TESTS 16
5681 static void test_thick_child_size(HWND parentWindow)
5685 RECT adjustedParentRect;
5690 LONG expectedHeight;
5692 LPCTSTR className = "THICK_CHILD_CLASS";
5695 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5696 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5697 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5698 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5699 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5700 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5701 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5702 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5703 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5704 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5705 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5706 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5707 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5708 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5709 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5710 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5711 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5714 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5719 WS_EX_DLGMODALFRAME,
5720 WS_EX_DLGMODALFRAME,
5721 WS_EX_DLGMODALFRAME,
5722 WS_EX_DLGMODALFRAME,
5727 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5728 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5729 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5730 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5732 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5733 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5734 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5735 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5736 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5737 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5738 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5739 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5740 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5741 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5742 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5743 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5744 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5745 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5746 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5747 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5748 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5752 cls.lpfnWndProc = test_thick_child_size_winproc;
5755 cls.hInstance = GetModuleHandleA(0);
5757 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5758 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5759 cls.lpszMenuName = NULL;
5760 cls.lpszClassName = className;
5761 SetLastError(0xdeadbeef);
5762 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5764 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5766 test_thick_child_name = styleName[i];
5767 test_thick_child_style = styles[i];
5768 test_thick_child_exStyle = exStyles[i];
5769 test_thick_child_got_minmax = FALSE;
5771 SetLastError(0xdeadbeef);
5772 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5773 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5775 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5777 SetLastError(0xdeadbeef);
5778 success = GetWindowRect(childWindow, &childRect);
5779 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5780 childWidth = childRect.right - childRect.left;
5781 childHeight = childRect.bottom - childRect.top;
5783 adjustedStyle = styles[i];
5784 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5785 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5786 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5787 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5790 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5792 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5793 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5797 expectedWidth = -2 * adjustedParentRect.left;
5798 expectedHeight = -2 * adjustedParentRect.top;
5801 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5802 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5803 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5805 SetLastError(0xdeadbeef);
5806 success = DestroyWindow(childWindow);
5807 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5809 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5812 static void test_handles( HWND full_hwnd )
5814 HWND hwnd = full_hwnd;
5818 SetLastError( 0xdeadbeef );
5819 ret = GetWindowRect( hwnd, &rect );
5820 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5823 if ((ULONG_PTR)full_hwnd >> 32)
5824 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5826 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5827 SetLastError( 0xdeadbeef );
5828 ret = GetWindowRect( hwnd, &rect );
5829 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5831 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5832 SetLastError( 0xdeadbeef );
5833 ret = GetWindowRect( hwnd, &rect );
5834 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5836 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5837 SetLastError( 0xdeadbeef );
5838 ret = GetWindowRect( hwnd, &rect );
5839 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5840 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5842 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5843 SetLastError( 0xdeadbeef );
5844 ret = GetWindowRect( hwnd, &rect );
5845 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5846 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5850 static void test_winregion(void)
5857 if (!pGetWindowRgnBox)
5859 win_skip("GetWindowRgnBox not supported\n");
5863 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
5865 SetLastError(0xdeadbeef);
5866 ret = pGetWindowRgnBox(hwnd, NULL);
5867 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5868 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5870 hrgn = CreateRectRgn(2, 3, 10, 15);
5871 ok( hrgn != NULL, "Region creation failed\n");
5874 SetWindowRgn(hwnd, hrgn, FALSE);
5876 SetLastError(0xdeadbeef);
5877 ret = pGetWindowRgnBox(hwnd, NULL);
5878 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
5879 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
5881 r.left = r.top = r.right = r.bottom = 0;
5882 ret = pGetWindowRgnBox(hwnd, &r);
5883 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
5884 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
5885 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
5889 DestroyWindow(hwnd);
5894 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5895 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5896 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5897 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5898 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5899 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5900 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5901 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5902 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
5903 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
5905 if (!RegisterWindowClasses()) assert(0);
5907 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5908 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5910 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5911 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5912 WS_MAXIMIZEBOX | WS_POPUP,
5914 0, 0, GetModuleHandle(0), NULL);
5915 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5916 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5917 WS_MAXIMIZEBOX | WS_POPUP,
5919 0, 0, GetModuleHandle(0), NULL);
5921 assert( hwndMain2 );
5923 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5925 /* Add the tests below this line */
5926 test_thick_child_size(hwndMain);
5928 test_hwnd_message();
5929 test_nonclient_area(hwndMain);
5931 test_GetWindowModuleFileName();
5934 test_capture_3(hwndMain, hwndMain2);
5937 test_CreateWindow();
5938 test_parent_owner();
5940 test_enum_thread_windows();
5944 test_SetWindowPos(hwndMain);
5945 test_SetMenu(hwndMain);
5946 test_SetFocus(hwndMain);
5947 test_SetActiveWindow(hwndMain);
5950 test_children_zorder(hwndMain);
5951 test_popup_zorder(hwndMain2, hwndMain);
5952 test_keyboard_input(hwndMain);
5953 test_mouse_input(hwndMain);
5954 test_validatergn(hwndMain);
5955 test_nccalcscroll( hwndMain);
5956 test_scrollwindow( hwndMain);
5957 test_scrollvalidate( hwndMain);
5958 test_scrolldc( hwndMain);
5960 test_IsWindowUnicode();
5961 test_vis_rgn(hwndMain);
5963 test_AdjustWindowRect();
5964 test_window_styles();
5967 test_SetWindowLong();
5969 if (0) test_gettext(); /* crashes on NT4 */
5970 test_GetUpdateRect();
5972 test_layered_window();
5974 test_SetForegroundWindow(hwndMain);
5975 test_shell_window();
5976 test_handles( hwndMain );
5979 /* add the tests above this line */
5980 if (hhook) UnhookWindowsHookEx(hhook);
5982 DestroyWindow(hwndMain2);
5983 DestroyWindow(hwndMain);