[USER32_WINETEST]
[reactos.git] / rostests / winetests / user32 / win.c
1 /*
2 * Unit tests for window handling
3 *
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
7 *
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.
12 *
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.
17 *
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
21 */
22
23 /* To get ICON_SMALL2 with the MSVC headers */
24 //#define _WIN32_WINNT 0x0501
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 #include "wine/test.h"
37
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
41
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
44
45 void dump_region(HRGN hrgn);
46
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 *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
53 static BOOL (WINAPI *pUpdateLayeredWindowIndirect)(HWND,const UPDATELAYEREDWINDOWINFO*);
54 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
55 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
56 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
57 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
58 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
59 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
60 static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
61 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
62 static DWORD (WINAPI *pGetLayout)(HDC hdc);
63 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
64
65 static BOOL test_lbuttondown_flag;
66 static HWND hwndMessage;
67 static HWND hwndMain, hwndMain2;
68 static HHOOK hhook;
69
70 static const char* szAWRClass = "Winsize";
71 static HMENU hmenu;
72 static DWORD our_pid;
73
74 static BOOL is_win9x = FALSE;
75
76 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
77
78 static void dump_minmax_info( const MINMAXINFO *minmax )
79 {
80 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
81 minmax->ptReserved.x, minmax->ptReserved.y,
82 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
83 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
84 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
85 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
86 }
87
88 /* try to make sure pending X events have been processed before continuing */
89 static void flush_events( BOOL remove_messages )
90 {
91 MSG msg;
92 int diff = 200;
93 int min_timeout = 100;
94 DWORD time = GetTickCount() + diff;
95
96 while (diff > 0)
97 {
98 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
99 if (remove_messages)
100 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
101 diff = time - GetTickCount();
102 min_timeout = 50;
103 }
104 }
105
106 /* check the values returned by the various parent/owner functions on a given window */
107 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
108 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
109 {
110 HWND res;
111
112 if (pGetAncestor)
113 {
114 res = pGetAncestor( hwnd, GA_PARENT );
115 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
116 }
117 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
118 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
119 res = GetParent( hwnd );
120 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
121 res = GetWindow( hwnd, GW_OWNER );
122 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
123 if (pGetAncestor)
124 {
125 res = pGetAncestor( hwnd, GA_ROOT );
126 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
127 res = pGetAncestor( hwnd, GA_ROOTOWNER );
128 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
129 }
130 }
131
132 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
133 static void check_wnd_state_(const char *file, int line,
134 HWND active, HWND foreground, HWND focus, HWND capture)
135 {
136 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
137 /* only check foreground if it belongs to the current thread */
138 /* foreground can be moved to a different app pretty much at any time */
139 if (foreground && GetForegroundWindow() &&
140 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
141 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
142 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
143 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
144 }
145
146 /* same as above but without capture test */
147 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
148 static void check_active_state_(const char *file, int line,
149 HWND active, HWND foreground, HWND focus)
150 {
151 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
152 /* only check foreground if it belongs to the current thread */
153 /* foreground can be moved to a different app pretty much at any time */
154 if (foreground && GetForegroundWindow() &&
155 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
156 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
157 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
158 }
159
160 static BOOL ignore_message( UINT message )
161 {
162 /* these are always ignored */
163 return (message >= 0xc000 ||
164 message == WM_GETICON ||
165 message == WM_GETOBJECT ||
166 message == WM_TIMECHANGE ||
167 message == WM_DEVICECHANGE);
168 }
169
170 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
171 {
172 (*(LPINT)lParam)++;
173 trace("EnumChildProc on %p\n", hwndChild);
174 if (*(LPINT)lParam > 1) return FALSE;
175 return TRUE;
176 }
177
178 /* will search for the given window */
179 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
180 {
181 trace("EnumChildProc1 on %p\n", hwndChild);
182 if ((HWND)lParam == hwndChild) return FALSE;
183 return TRUE;
184 }
185
186 static HWND create_tool_window( LONG style, HWND parent )
187 {
188 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
189 0, 0, 100, 100, parent, 0, 0, NULL );
190 ok( ret != 0, "Creation failed\n" );
191 return ret;
192 }
193
194 /* test parent and owner values for various combinations */
195 static void test_parent_owner(void)
196 {
197 LONG style;
198 HWND test, owner, ret;
199 HWND desktop = GetDesktopWindow();
200 HWND child = create_tool_window( WS_CHILD, hwndMain );
201 INT numChildren;
202
203 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
204
205 /* child without parent, should fail */
206 SetLastError(0xdeadbeef);
207 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
208 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
209 ok( !test, "WS_CHILD without parent created\n" );
210 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
211 broken(GetLastError() == 0xdeadbeef), /* win9x */
212 "CreateWindowExA error %u\n", GetLastError() );
213
214 /* desktop window */
215 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
216 style = GetWindowLongA( desktop, GWL_STYLE );
217 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
218 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
219 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
220
221 /* normal child window */
222 test = create_tool_window( WS_CHILD, hwndMain );
223 trace( "created child %p\n", test );
224 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
225 SetWindowLongA( test, GWL_STYLE, 0 );
226 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
227 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
228 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
229 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
230 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
231 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
232 DestroyWindow( test );
233
234 /* normal child window with WS_MAXIMIZE */
235 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
236 DestroyWindow( test );
237
238 /* normal child window with WS_THICKFRAME */
239 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
240 DestroyWindow( test );
241
242 /* popup window with WS_THICKFRAME */
243 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
244 DestroyWindow( test );
245
246 /* child of desktop */
247 test = create_tool_window( WS_CHILD, desktop );
248 trace( "created child of desktop %p\n", test );
249 check_parents( test, desktop, 0, desktop, 0, test, desktop );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, 0, 0, 0, test, test );
252 SetWindowLongA( test, GWL_STYLE, 0 );
253 check_parents( test, desktop, 0, 0, 0, test, test );
254 DestroyWindow( test );
255
256 /* child of desktop with WS_MAXIMIZE */
257 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
258 DestroyWindow( test );
259
260 /* child of desktop with WS_MINIMIZE */
261 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
262 DestroyWindow( test );
263
264 /* child of child */
265 test = create_tool_window( WS_CHILD, child );
266 trace( "created child of child %p\n", test );
267 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
268 SetWindowLongA( test, GWL_STYLE, 0 );
269 check_parents( test, child, child, 0, 0, hwndMain, test );
270 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
271 check_parents( test, child, child, 0, 0, hwndMain, test );
272 DestroyWindow( test );
273
274 /* child of child with WS_MAXIMIZE */
275 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
276 DestroyWindow( test );
277
278 /* child of child with WS_MINIMIZE */
279 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
280 DestroyWindow( test );
281
282 /* not owned top-level window */
283 test = create_tool_window( 0, 0 );
284 trace( "created top-level %p\n", test );
285 check_parents( test, desktop, 0, 0, 0, test, test );
286 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
287 check_parents( test, desktop, 0, 0, 0, test, test );
288 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
289 check_parents( test, desktop, 0, desktop, 0, test, desktop );
290 DestroyWindow( test );
291
292 /* not owned top-level window with WS_MAXIMIZE */
293 test = create_tool_window( WS_MAXIMIZE, 0 );
294 DestroyWindow( test );
295
296 /* owned top-level window */
297 test = create_tool_window( 0, hwndMain );
298 trace( "created owned top-level %p\n", test );
299 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
300 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
301 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
302 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
303 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
304 DestroyWindow( test );
305
306 /* owned top-level window with WS_MAXIMIZE */
307 test = create_tool_window( WS_MAXIMIZE, hwndMain );
308 DestroyWindow( test );
309
310 /* not owned popup */
311 test = create_tool_window( WS_POPUP, 0 );
312 trace( "created popup %p\n", test );
313 check_parents( test, desktop, 0, 0, 0, test, test );
314 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
315 check_parents( test, desktop, 0, desktop, 0, test, desktop );
316 SetWindowLongA( test, GWL_STYLE, 0 );
317 check_parents( test, desktop, 0, 0, 0, test, test );
318 DestroyWindow( test );
319
320 /* not owned popup with WS_MAXIMIZE */
321 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
322 DestroyWindow( test );
323
324 /* owned popup */
325 test = create_tool_window( WS_POPUP, hwndMain );
326 trace( "created owned popup %p\n", test );
327 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
328 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
329 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
330 SetWindowLongA( test, GWL_STYLE, 0 );
331 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
332 DestroyWindow( test );
333
334 /* owned popup with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
337
338 /* top-level window owned by child (same as owned by top-level) */
339 test = create_tool_window( 0, child );
340 trace( "created top-level owned by child %p\n", test );
341 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
342 DestroyWindow( test );
343
344 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
345 test = create_tool_window( WS_MAXIMIZE, child );
346 DestroyWindow( test );
347
348 /* popup owned by desktop (same as not owned) */
349 test = create_tool_window( WS_POPUP, desktop );
350 trace( "created popup owned by desktop %p\n", test );
351 check_parents( test, desktop, 0, 0, 0, test, test );
352 DestroyWindow( test );
353
354 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
355 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
356 DestroyWindow( test );
357
358 /* popup owned by child (same as owned by top-level) */
359 test = create_tool_window( WS_POPUP, child );
360 trace( "created popup owned by child %p\n", test );
361 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
362 DestroyWindow( test );
363
364 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
365 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
366 DestroyWindow( test );
367
368 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
369 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
370 trace( "created WS_CHILD popup %p\n", test );
371 check_parents( test, desktop, 0, 0, 0, test, test );
372 DestroyWindow( test );
373
374 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
375 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
376 DestroyWindow( test );
377
378 /* owned popup with WS_CHILD (same as WS_POPUP only) */
379 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
380 trace( "created owned WS_CHILD popup %p\n", test );
381 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
382 DestroyWindow( test );
383
384 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
385 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
386 DestroyWindow( test );
387
388 /******************** parent changes *************************/
389 trace( "testing parent changes\n" );
390
391 /* desktop window */
392 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
393 if (0)
394 {
395 /* this test succeeds on NT but crashes on win9x systems */
396 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
397 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
398 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
399 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
400 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
401 }
402 /* normal child window */
403 test = create_tool_window( WS_CHILD, hwndMain );
404 trace( "created child %p\n", test );
405
406 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
407 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
408 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
409
410 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
411 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
412 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
413
414 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
415 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
416 check_parents( test, desktop, 0, desktop, 0, test, desktop );
417
418 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
419 if (!is_win9x)
420 {
421 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
422 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
423 check_parents( test, desktop, 0, desktop, 0, test, desktop );
424 }
425 else
426 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
427
428 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
429 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
430 check_parents( test, desktop, child, desktop, child, test, desktop );
431
432 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
433 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
434 check_parents( test, desktop, 0, desktop, 0, test, desktop );
435 DestroyWindow( test );
436
437 /* not owned top-level window */
438 test = create_tool_window( 0, 0 );
439 trace( "created top-level %p\n", test );
440
441 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
442 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
443 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
444
445 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
446 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
447 check_parents( test, desktop, child, 0, child, test, test );
448
449 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
450 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
451 check_parents( test, desktop, 0, 0, 0, test, test );
452 DestroyWindow( test );
453
454 /* not owned popup */
455 test = create_tool_window( WS_POPUP, 0 );
456 trace( "created popup %p\n", test );
457
458 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
459 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
460 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
461
462 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
463 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
464 check_parents( test, desktop, child, child, child, test, hwndMain );
465
466 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
467 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
468 check_parents( test, desktop, 0, 0, 0, test, test );
469 DestroyWindow( test );
470
471 /* normal child window */
472 test = create_tool_window( WS_CHILD, hwndMain );
473 trace( "created child %p\n", test );
474
475 ret = SetParent( test, desktop );
476 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
477 check_parents( test, desktop, 0, desktop, 0, test, desktop );
478
479 ret = SetParent( test, child );
480 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
481 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
482
483 ret = SetParent( test, hwndMain2 );
484 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
485 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
486 DestroyWindow( test );
487
488 /* not owned top-level window */
489 test = create_tool_window( 0, 0 );
490 trace( "created top-level %p\n", test );
491
492 ret = SetParent( test, child );
493 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
494 check_parents( test, child, child, 0, 0, hwndMain, test );
495
496 if (!is_win9x)
497 {
498 ShowWindow( test, SW_SHOW );
499 ret = SetParent( test, test );
500 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
501 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
502 check_parents( test, child, child, 0, 0, hwndMain, test );
503 }
504 else
505 win_skip( "Test crashes on Win9x/WinMe\n" );
506 DestroyWindow( test );
507
508 /* owned popup */
509 test = create_tool_window( WS_POPUP, hwndMain2 );
510 trace( "created owned popup %p\n", test );
511
512 ret = SetParent( test, child );
513 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
514 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
515
516 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
517 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
518 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
519 DestroyWindow( test );
520
521 /**************** test owner destruction *******************/
522
523 /* owned child popup */
524 owner = create_tool_window( 0, 0 );
525 test = create_tool_window( WS_POPUP, owner );
526 trace( "created owner %p and popup %p\n", owner, test );
527 ret = SetParent( test, child );
528 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
529 check_parents( test, child, child, owner, owner, hwndMain, owner );
530 /* window is now child of 'child' but owned by 'owner' */
531 DestroyWindow( owner );
532 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
533 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
534 * while Win95, Win2k, WinXP do.
535 */
536 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
537 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
538 DestroyWindow(test);
539
540 /* owned top-level popup */
541 owner = create_tool_window( 0, 0 );
542 test = create_tool_window( WS_POPUP, owner );
543 trace( "created owner %p and popup %p\n", owner, test );
544 check_parents( test, desktop, owner, owner, owner, test, owner );
545 DestroyWindow( owner );
546 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
547
548 /* top-level popup owned by child */
549 owner = create_tool_window( WS_CHILD, hwndMain2 );
550 test = create_tool_window( WS_POPUP, 0 );
551 trace( "created owner %p and popup %p\n", owner, test );
552 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
553 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
554 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
555 DestroyWindow( owner );
556 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
557 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
558 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
559 * while Win95, Win2k, WinXP do.
560 */
561 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
562 DestroyWindow(test);
563
564 /* final cleanup */
565 DestroyWindow(child);
566
567
568 owner = create_tool_window( WS_OVERLAPPED, 0 );
569 test = create_tool_window( WS_POPUP, desktop );
570
571 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
572 numChildren = 0;
573 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
574 "EnumChildWindows should have returned FALSE\n" );
575 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
576
577 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
578 ret = SetParent( test, owner );
579 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
580
581 numChildren = 0;
582 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
583 "EnumChildWindows should have returned TRUE\n" );
584 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
585
586 child = create_tool_window( WS_CHILD, owner );
587 numChildren = 0;
588 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
589 "EnumChildWindows should have returned FALSE\n" );
590 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
591 DestroyWindow( child );
592
593 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
594 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
595 numChildren = 0;
596 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
597 "EnumChildWindows should have returned TRUE\n" );
598 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
599
600 ret = SetParent( child, owner );
601 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
602 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
603 numChildren = 0;
604 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
605 "EnumChildWindows should have returned FALSE\n" );
606 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
607
608 ret = SetParent( child, NULL );
609 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
610 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
611 numChildren = 0;
612 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
613 "EnumChildWindows should have returned TRUE\n" );
614 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
615
616 /* even GW_OWNER == owner it's still a desktop's child */
617 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
618 "EnumChildWindows should have found %p and returned FALSE\n", child );
619
620 DestroyWindow( child );
621 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
622
623 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
624 "EnumChildWindows should have found %p and returned FALSE\n", child );
625
626 DestroyWindow( child );
627 DestroyWindow( test );
628 DestroyWindow( owner );
629 }
630
631 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
632 {
633 (*(LPINT)lParam)++;
634 if (*(LPINT)lParam > 2) return FALSE;
635 return TRUE;
636 }
637 static DWORD CALLBACK enum_thread( void *arg )
638 {
639 INT count;
640 HWND hwnd[3];
641 BOOL ret;
642 MSG msg;
643
644 if (pGetGUIThreadInfo)
645 {
646 GUITHREADINFO info;
647 info.cbSize = sizeof(info);
648 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
649 ok( ret || broken(!ret), /* win9x */
650 "GetGUIThreadInfo failed without message queue\n" );
651 SetLastError( 0xdeadbeef );
652 info.cbSize = sizeof(info) + 1;
653 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
654 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
655 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
656 broken(GetLastError() == 0xdeadbeef), /* win9x */
657 "wrong error %u\n", GetLastError() );
658 }
659
660 PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
661
662 count = 0;
663 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
664 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
665 ok( count == 0, "count should be 0 got %d\n", count );
666
667 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
668 0, 0, 100, 100, 0, 0, 0, NULL );
669 count = 0;
670 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
671 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
672 if (count != 2) /* Vista gives us two windows for the price of one */
673 {
674 ok( count == 1, "count should be 1 got %d\n", count );
675 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
676 0, 0, 100, 100, 0, 0, 0, NULL );
677 }
678 else hwnd[2] = 0;
679
680 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
681 0, 0, 100, 100, 0, 0, 0, NULL );
682 count = 0;
683 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
684 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
685 ok( count == 3, "count should be 3 got %d\n", count );
686
687 if (hwnd[2]) DestroyWindow(hwnd[2]);
688 DestroyWindow(hwnd[1]);
689 DestroyWindow(hwnd[0]);
690 return 0;
691 }
692
693 /* test EnumThreadWindows in a separate thread */
694 static void test_enum_thread_windows(void)
695 {
696 DWORD id;
697 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
698 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
699 CloseHandle( handle );
700 }
701
702 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
703 {
704 switch (msg)
705 {
706 case WM_GETMINMAXINFO:
707 {
708 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
709
710 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
711 dump_minmax_info( minmax );
712 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
713 break;
714 }
715 case WM_WINDOWPOSCHANGING:
716 {
717 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
718 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
719 winpos->hwnd, winpos->hwndInsertAfter,
720 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
721 if (!(winpos->flags & SWP_NOMOVE))
722 {
723 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
724 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
725 }
726 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
727 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
728 {
729 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
730 winpos->cx == 32768, /* win7 doesn't truncate */
731 "bad winpos->cx %d\n", winpos->cx);
732 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
733 winpos->cy == 40000, /* win7 doesn't truncate */
734 "bad winpos->cy %d\n", winpos->cy);
735 }
736 break;
737 }
738 case WM_WINDOWPOSCHANGED:
739 {
740 RECT rc1, rc2;
741 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
742 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
743 winpos->hwnd, winpos->hwndInsertAfter,
744 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
745 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
746 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
747
748 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
749 winpos->cx == 32768, /* win7 doesn't truncate */
750 "bad winpos->cx %d\n", winpos->cx);
751 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
752 winpos->cy == 40000, /* win7 doesn't truncate */
753 "bad winpos->cy %d\n", winpos->cy);
754
755 GetWindowRect(hwnd, &rc1);
756 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
757 /* note: winpos coordinates are relative to parent */
758 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
759 if (0)
760 {
761 /* Uncomment this once the test succeeds in all cases */
762 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
763 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
764
765 GetClientRect(hwnd, &rc2);
766 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
767 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
768 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
769 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
770 }
771 break;
772 }
773 case WM_NCCREATE:
774 {
775 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
776 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
777
778 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
779 if (got_getminmaxinfo)
780 trace("%p got WM_GETMINMAXINFO\n", hwnd);
781
782 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
783 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
784 else
785 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
786 break;
787 }
788 case WM_COMMAND:
789 if (test_lbuttondown_flag)
790 {
791 ShowWindow((HWND)wparam, SW_SHOW);
792 flush_events( FALSE );
793 }
794 break;
795 }
796
797 return DefWindowProcA(hwnd, msg, wparam, lparam);
798 }
799
800 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
801 {
802 switch (msg)
803 {
804 case WM_GETMINMAXINFO:
805 {
806 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
807
808 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
809 dump_minmax_info( minmax );
810 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
811 break;
812 }
813 case WM_NCCREATE:
814 {
815 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
816 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
817
818 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
819 if (got_getminmaxinfo)
820 trace("%p got WM_GETMINMAXINFO\n", hwnd);
821
822 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
823 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
824 else
825 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
826 break;
827 }
828 }
829
830 return DefWindowProcA(hwnd, msg, wparam, lparam);
831 }
832
833 static BOOL RegisterWindowClasses(void)
834 {
835 WNDCLASSA cls;
836
837 cls.style = CS_DBLCLKS;
838 cls.lpfnWndProc = main_window_procA;
839 cls.cbClsExtra = 0;
840 cls.cbWndExtra = 0;
841 cls.hInstance = GetModuleHandleA(0);
842 cls.hIcon = 0;
843 cls.hCursor = LoadCursorA(0, IDC_ARROW);
844 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
845 cls.lpszMenuName = NULL;
846 cls.lpszClassName = "MainWindowClass";
847
848 if(!RegisterClassA(&cls)) return FALSE;
849
850 cls.style = 0;
851 cls.lpfnWndProc = tool_window_procA;
852 cls.cbClsExtra = 0;
853 cls.cbWndExtra = 0;
854 cls.hInstance = GetModuleHandleA(0);
855 cls.hIcon = 0;
856 cls.hCursor = LoadCursorA(0, IDC_ARROW);
857 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
858 cls.lpszMenuName = NULL;
859 cls.lpszClassName = "ToolWindowClass";
860
861 if(!RegisterClassA(&cls)) return FALSE;
862
863 return TRUE;
864 }
865
866 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
867 {
868 RECT rcWindow, rcClient;
869 DWORD status;
870
871 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
872
873 GetWindowRect(hwnd, &rcWindow);
874 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
875
876 GetClientRect(hwnd, &rcClient);
877 /* translate to screen coordinates */
878 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
879 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
880
881 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
882 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
883 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
884 /* Windows reports some undocumented exstyles in WINDOWINFO, but
885 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
886 */
887 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
888 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
889 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
890 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
891 if (GetForegroundWindow())
892 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
893 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
894
895 /* win2k and XP return broken border info in GetWindowInfo most of
896 * the time, so there is no point in testing it.
897 */
898 #if 0
899 UINT border;
900 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
901 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
902 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
903 ok(info->cyWindowBorders == border,
904 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
905 #endif
906 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
907 hwnd, hook);
908 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
909 info->wCreatorVersion == 0x0500 /* Vista */,
910 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
911 }
912
913 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
914 {
915 AdjustWindowRectEx(rc, style, menu, exstyle);
916 /* AdjustWindowRectEx does not include scroll bars */
917 if (style & WS_VSCROLL)
918 {
919 if(exstyle & WS_EX_LEFTSCROLLBAR)
920 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
921 else
922 rc->right += GetSystemMetrics(SM_CXVSCROLL);
923 }
924 if (style & WS_HSCROLL)
925 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
926 }
927
928 static void test_nonclient_area(HWND hwnd)
929 {
930 DWORD style, exstyle;
931 RECT rc_window, rc_client, rc;
932 BOOL menu;
933 LRESULT ret;
934
935 style = GetWindowLongA(hwnd, GWL_STYLE);
936 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
937 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
938
939 GetWindowRect(hwnd, &rc_window);
940 GetClientRect(hwnd, &rc_client);
941
942 /* avoid some cases when things go wrong */
943 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
944 rc_window.right > 32768 || rc_window.bottom > 32768) return;
945
946 CopyRect(&rc, &rc_client);
947 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
948 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
949
950 ok(EqualRect(&rc, &rc_window),
951 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
952 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
953 rc.left, rc.top, rc.right, rc.bottom);
954
955
956 CopyRect(&rc, &rc_window);
957 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
958 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
959 ok(EqualRect(&rc, &rc_client),
960 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
961 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
962 rc.left, rc.top, rc.right, rc.bottom);
963
964 /* NULL rectangle shouldn't crash */
965 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
966 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
967
968 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
969 if (is_win9x)
970 return;
971
972 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
973 SetRect(&rc_client, 0, 0, 250, 150);
974 CopyRect(&rc_window, &rc_client);
975 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
976 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
977
978 CopyRect(&rc, &rc_window);
979 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
980 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
981 ok(EqualRect(&rc, &rc_client),
982 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
983 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
984 rc.left, rc.top, rc.right, rc.bottom);
985 }
986
987 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
988 {
989 static const char *CBT_code_name[10] = {
990 "HCBT_MOVESIZE",
991 "HCBT_MINMAX",
992 "HCBT_QS",
993 "HCBT_CREATEWND",
994 "HCBT_DESTROYWND",
995 "HCBT_ACTIVATE",
996 "HCBT_CLICKSKIPPED",
997 "HCBT_KEYSKIPPED",
998 "HCBT_SYSCOMMAND",
999 "HCBT_SETFOCUS" };
1000 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1001 HWND hwnd = (HWND)wParam;
1002
1003 switch (nCode)
1004 {
1005 case HCBT_CREATEWND:
1006 {
1007 static const RECT rc_null;
1008 RECT rc;
1009 LONG style;
1010 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1011 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1012
1013 if (pGetWindowInfo)
1014 {
1015 WINDOWINFO info;
1016 info.cbSize = sizeof(WINDOWINFO);
1017 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1018 verify_window_info(code_name, hwnd, &info);
1019 }
1020
1021 /* WS_VISIBLE should be turned off yet */
1022 style = createwnd->lpcs->style & ~WS_VISIBLE;
1023 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1024 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1025 GetWindowLongA(hwnd, GWL_STYLE), style);
1026
1027 if (0)
1028 {
1029 /* Uncomment this once the test succeeds in all cases */
1030 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1031 {
1032 ok(GetParent(hwnd) == hwndMessage,
1033 "wrong result from GetParent %p: message window %p\n",
1034 GetParent(hwnd), hwndMessage);
1035 }
1036 else
1037 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1038
1039 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1040 }
1041 if (0)
1042 {
1043 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1044 * Win9x still has them set to 0.
1045 */
1046 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1047 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1048 }
1049 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1050 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1051
1052 if (0)
1053 {
1054 /* Uncomment this once the test succeeds in all cases */
1055 if (pGetAncestor)
1056 {
1057 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1058 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1059 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1060
1061 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1062 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1063 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1064 else
1065 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1066 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1067 }
1068
1069 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1070 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1071 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1072 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1073 }
1074 break;
1075 }
1076 case HCBT_MOVESIZE:
1077 case HCBT_MINMAX:
1078 case HCBT_ACTIVATE:
1079 if (pGetWindowInfo && IsWindow(hwnd))
1080 {
1081 WINDOWINFO info;
1082
1083 /* Win98 actually does check the info.cbSize and doesn't allow
1084 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1085 * WinXP do not check it at all.
1086 */
1087 info.cbSize = sizeof(WINDOWINFO);
1088 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1089 verify_window_info(code_name, hwnd, &info);
1090 }
1091 break;
1092 /* window state is undefined */
1093 case HCBT_SETFOCUS:
1094 case HCBT_DESTROYWND:
1095 break;
1096 default:
1097 break;
1098 }
1099
1100 return CallNextHookEx(hhook, nCode, wParam, lParam);
1101 }
1102
1103 static void test_shell_window(void)
1104 {
1105 BOOL ret;
1106 DWORD error;
1107 HMODULE hinst, hUser32;
1108 BOOL (WINAPI*SetShellWindow)(HWND);
1109 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1110 HWND shellWindow, nextWnd;
1111
1112 if (is_win9x)
1113 {
1114 win_skip("Skipping shell window test on Win9x\n");
1115 return;
1116 }
1117
1118 shellWindow = GetShellWindow();
1119 hinst = GetModuleHandle(0);
1120 hUser32 = GetModuleHandleA("user32");
1121
1122 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1123
1124 trace("previous shell window: %p\n", shellWindow);
1125
1126 if (shellWindow) {
1127 DWORD pid;
1128 HANDLE hProcess;
1129
1130 GetWindowThreadProcessId(shellWindow, &pid);
1131 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1132 if (!hProcess)
1133 {
1134 skip( "cannot get access to shell process\n" );
1135 return;
1136 }
1137
1138 SetLastError(0xdeadbeef);
1139 ret = DestroyWindow(shellWindow);
1140 error = GetLastError();
1141
1142 ok(!ret, "DestroyWindow(shellWindow)\n");
1143 /* passes on Win XP, but not on Win98 */
1144 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1145 "got %u after DestroyWindow(shellWindow)\n", error);
1146
1147 /* close old shell instance */
1148 ret = TerminateProcess(hProcess, 0);
1149 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1150 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1151 CloseHandle(hProcess);
1152 }
1153
1154 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1155 trace("created window 1: %p\n", hwnd1);
1156
1157 ret = SetShellWindow(hwnd1);
1158 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1159 shellWindow = GetShellWindow();
1160 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1161
1162 ret = SetShellWindow(hwnd1);
1163 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1164
1165 ret = SetShellWindow(0);
1166 error = GetLastError();
1167 /* passes on Win XP, but not on Win98
1168 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1169 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1170
1171 ret = SetShellWindow(hwnd1);
1172 /* passes on Win XP, but not on Win98
1173 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1174
1175 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1176 ret = (GetWindowLong(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1177 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1178
1179 ret = DestroyWindow(hwnd1);
1180 ok(ret, "DestroyWindow(hwnd1)\n");
1181
1182 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1183 trace("created window 2: %p\n", hwnd2);
1184 ret = SetShellWindow(hwnd2);
1185 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1186
1187 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1188 trace("created window 3: %p\n", hwnd3);
1189
1190 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1191 trace("created window 4: %p\n", hwnd4);
1192
1193 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1194 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1195
1196 ret = SetShellWindow(hwnd4);
1197 ok(ret, "SetShellWindow(hwnd4)\n");
1198 shellWindow = GetShellWindow();
1199 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1200
1201 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1202 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1203
1204 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1205 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1206
1207 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1208 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1209
1210 ret = SetShellWindow(hwnd3);
1211 ok(!ret, "SetShellWindow(hwnd3)\n");
1212 shellWindow = GetShellWindow();
1213 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1214
1215 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1216 trace("created window 5: %p\n", hwnd5);
1217 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1218 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1219
1220 todo_wine
1221 {
1222 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1223 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1224 }
1225
1226 /* destroy test windows */
1227 DestroyWindow(hwnd2);
1228 DestroyWindow(hwnd3);
1229 DestroyWindow(hwnd4);
1230 DestroyWindow(hwnd5);
1231 }
1232
1233 /************** MDI test ****************/
1234
1235 static char mdi_lParam_test_message[] = "just a test string";
1236
1237 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1238 {
1239 MDICREATESTRUCTA mdi_cs;
1240 HWND mdi_child;
1241 INT_PTR id;
1242 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1243 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1244 BOOL isWin9x = FALSE;
1245
1246 mdi_cs.szClass = "MDI_child_Class_1";
1247 mdi_cs.szTitle = "MDI child";
1248 mdi_cs.hOwner = GetModuleHandle(0);
1249 mdi_cs.x = CW_USEDEFAULT;
1250 mdi_cs.y = CW_USEDEFAULT;
1251 mdi_cs.cx = CW_USEDEFAULT;
1252 mdi_cs.cy = CW_USEDEFAULT;
1253 mdi_cs.style = 0;
1254 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1255 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1256 ok(mdi_child != 0, "MDI child creation failed\n");
1257 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1258 ok(id == first_id, "wrong child id %ld\n", id);
1259 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1260 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1261
1262 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1263 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1264 ok(mdi_child != 0, "MDI child creation failed\n");
1265 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1266 ok(id == first_id, "wrong child id %ld\n", id);
1267 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1268 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1269
1270 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1271 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1272 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1273 {
1274 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1275 }
1276 else
1277 {
1278 ok(mdi_child != 0, "MDI child creation failed\n");
1279 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1280 ok(id == first_id, "wrong child id %ld\n", id);
1281 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1282 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1283 }
1284
1285 /* test MDICREATESTRUCT A<->W mapping */
1286 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1287 mdi_cs.style = 0;
1288 mdi_cs.szClass = (LPCSTR)classW;
1289 mdi_cs.szTitle = (LPCSTR)titleW;
1290 SetLastError(0xdeadbeef);
1291 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1292 if (!mdi_child)
1293 {
1294 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1295 isWin9x = TRUE;
1296 else
1297 ok(mdi_child != 0, "MDI child creation failed\n");
1298 }
1299 else
1300 {
1301 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1302 ok(id == first_id, "wrong child id %ld\n", id);
1303 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1304 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1305 }
1306
1307 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1308 0,
1309 CW_USEDEFAULT, CW_USEDEFAULT,
1310 CW_USEDEFAULT, CW_USEDEFAULT,
1311 mdi_client, GetModuleHandle(0),
1312 (LPARAM)mdi_lParam_test_message);
1313 ok(mdi_child != 0, "MDI child creation failed\n");
1314 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1315 ok(id == first_id, "wrong child id %ld\n", id);
1316 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1317 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1318
1319 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1320 0x7fffffff, /* without WS_POPUP */
1321 CW_USEDEFAULT, CW_USEDEFAULT,
1322 CW_USEDEFAULT, CW_USEDEFAULT,
1323 mdi_client, GetModuleHandle(0),
1324 (LPARAM)mdi_lParam_test_message);
1325 ok(mdi_child != 0, "MDI child creation failed\n");
1326 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1327 ok(id == first_id, "wrong child id %ld\n", id);
1328 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1329 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1330
1331 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1332 0xffffffff, /* with WS_POPUP */
1333 CW_USEDEFAULT, CW_USEDEFAULT,
1334 CW_USEDEFAULT, CW_USEDEFAULT,
1335 mdi_client, GetModuleHandle(0),
1336 (LPARAM)mdi_lParam_test_message);
1337 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1338 {
1339 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1340 }
1341 else
1342 {
1343 ok(mdi_child != 0, "MDI child creation failed\n");
1344 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1345 ok(id == first_id, "wrong child id %ld\n", id);
1346 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1347 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1348 }
1349
1350 /* test MDICREATESTRUCT A<->W mapping */
1351 SetLastError(0xdeadbeef);
1352 mdi_child = CreateMDIWindowW(classW, titleW,
1353 0,
1354 CW_USEDEFAULT, CW_USEDEFAULT,
1355 CW_USEDEFAULT, CW_USEDEFAULT,
1356 mdi_client, GetModuleHandle(0),
1357 (LPARAM)mdi_lParam_test_message);
1358 if (!mdi_child)
1359 {
1360 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1361 isWin9x = TRUE;
1362 else
1363 ok(mdi_child != 0, "MDI child creation failed\n");
1364 }
1365 else
1366 {
1367 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1368 ok(id == first_id, "wrong child id %ld\n", id);
1369 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1370 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1371 }
1372
1373 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1374 0,
1375 CW_USEDEFAULT, CW_USEDEFAULT,
1376 CW_USEDEFAULT, CW_USEDEFAULT,
1377 mdi_client, 0, GetModuleHandle(0),
1378 mdi_lParam_test_message);
1379 ok(mdi_child != 0, "MDI child creation failed\n");
1380 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1381 ok(id == first_id, "wrong child id %ld\n", id);
1382 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1383 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1384
1385 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1386 0x7fffffff, /* without WS_POPUP */
1387 CW_USEDEFAULT, CW_USEDEFAULT,
1388 CW_USEDEFAULT, CW_USEDEFAULT,
1389 mdi_client, 0, GetModuleHandle(0),
1390 mdi_lParam_test_message);
1391 ok(mdi_child != 0, "MDI child creation failed\n");
1392 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1393 ok(id == first_id, "wrong child id %ld\n", id);
1394 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1395 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1396
1397 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1398 0xffffffff, /* with WS_POPUP */
1399 CW_USEDEFAULT, CW_USEDEFAULT,
1400 CW_USEDEFAULT, CW_USEDEFAULT,
1401 mdi_client, 0, GetModuleHandle(0),
1402 mdi_lParam_test_message);
1403 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1404 {
1405 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1406 }
1407 else
1408 {
1409 ok(mdi_child != 0, "MDI child creation failed\n");
1410 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1411 ok(id == first_id, "wrong child id %ld\n", id);
1412 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1413 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1414 }
1415
1416 /* test MDICREATESTRUCT A<->W mapping */
1417 SetLastError(0xdeadbeef);
1418 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1419 0,
1420 CW_USEDEFAULT, CW_USEDEFAULT,
1421 CW_USEDEFAULT, CW_USEDEFAULT,
1422 mdi_client, 0, GetModuleHandle(0),
1423 mdi_lParam_test_message);
1424 if (!mdi_child)
1425 {
1426 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1427 isWin9x = TRUE;
1428 else
1429 ok(mdi_child != 0, "MDI child creation failed\n");
1430 }
1431 else
1432 {
1433 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1434 ok(id == first_id, "wrong child id %ld\n", id);
1435 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1436 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1437 }
1438
1439 /* This test fails on Win9x */
1440 if (!isWin9x)
1441 {
1442 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1443 WS_CHILD,
1444 CW_USEDEFAULT, CW_USEDEFAULT,
1445 CW_USEDEFAULT, CW_USEDEFAULT,
1446 parent, 0, GetModuleHandle(0),
1447 mdi_lParam_test_message);
1448 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1449 }
1450
1451 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1452 WS_CHILD, /* without WS_POPUP */
1453 CW_USEDEFAULT, CW_USEDEFAULT,
1454 CW_USEDEFAULT, CW_USEDEFAULT,
1455 mdi_client, 0, GetModuleHandle(0),
1456 mdi_lParam_test_message);
1457 ok(mdi_child != 0, "MDI child creation failed\n");
1458 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1459 ok(id == 0, "wrong child id %ld\n", id);
1460 DestroyWindow(mdi_child);
1461
1462 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1463 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1464 CW_USEDEFAULT, CW_USEDEFAULT,
1465 CW_USEDEFAULT, CW_USEDEFAULT,
1466 mdi_client, 0, GetModuleHandle(0),
1467 mdi_lParam_test_message);
1468 ok(mdi_child != 0, "MDI child creation failed\n");
1469 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1470 ok(id == 0, "wrong child id %ld\n", id);
1471 DestroyWindow(mdi_child);
1472
1473 /* maximized child */
1474 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1475 WS_CHILD | WS_MAXIMIZE,
1476 CW_USEDEFAULT, CW_USEDEFAULT,
1477 CW_USEDEFAULT, CW_USEDEFAULT,
1478 mdi_client, 0, GetModuleHandle(0),
1479 mdi_lParam_test_message);
1480 ok(mdi_child != 0, "MDI child creation failed\n");
1481 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1482 ok(id == 0, "wrong child id %ld\n", id);
1483 DestroyWindow(mdi_child);
1484
1485 trace("Creating maximized child with a caption\n");
1486 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1487 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1488 CW_USEDEFAULT, CW_USEDEFAULT,
1489 CW_USEDEFAULT, CW_USEDEFAULT,
1490 mdi_client, 0, GetModuleHandle(0),
1491 mdi_lParam_test_message);
1492 ok(mdi_child != 0, "MDI child creation failed\n");
1493 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1494 ok(id == 0, "wrong child id %ld\n", id);
1495 DestroyWindow(mdi_child);
1496
1497 trace("Creating maximized child with a caption and a thick frame\n");
1498 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1499 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1500 CW_USEDEFAULT, CW_USEDEFAULT,
1501 CW_USEDEFAULT, CW_USEDEFAULT,
1502 mdi_client, 0, GetModuleHandle(0),
1503 mdi_lParam_test_message);
1504 ok(mdi_child != 0, "MDI child creation failed\n");
1505 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1506 ok(id == 0, "wrong child id %ld\n", id);
1507 DestroyWindow(mdi_child);
1508 }
1509
1510 static void test_MDI_child_stack(HWND mdi_client)
1511 {
1512 HWND child_1, child_2, child_3, child_4;
1513 HWND stack[4];
1514 MDICREATESTRUCTA cs;
1515
1516 cs.szClass = "MDI_child_Class_1";
1517 cs.szTitle = "MDI child";
1518 cs.hOwner = GetModuleHandleA(0);
1519 cs.x = CW_USEDEFAULT;
1520 cs.y = CW_USEDEFAULT;
1521 cs.cx = CW_USEDEFAULT;
1522 cs.cy = CW_USEDEFAULT;
1523 cs.style = 0;
1524 cs.lParam = (LPARAM)mdi_lParam_test_message;
1525
1526 child_1 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1527 ok(child_1 != 0, "expected child_1 to be non NULL\n");
1528 child_2 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1529 ok(child_2 != 0, "expected child_2 to be non NULL\n");
1530 child_3 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1531 ok(child_3 != 0, "expected child_3 to be non NULL\n");
1532 child_4 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1533 ok(child_4 != 0, "expected child_4 to be non NULL\n");
1534
1535 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1536 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1537 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1538 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1539 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack[0], stack[1], stack[2], stack[3]);
1540 ok(stack[0] == child_4 && stack[1] == child_3 &&
1541 stack[2] == child_2 && stack[3] == child_1,
1542 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1543 child_4, child_3, child_2, child_1);
1544
1545 trace("Activate child next to %p\n", child_3);
1546 SendMessage(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
1547
1548 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1549 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1550 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1551 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1552 ok(stack[0] == child_2 && stack[1] == child_4 &&
1553 stack[2] == child_1 && stack[3] == child_3,
1554 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1555 child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1556
1557 trace("Activate child previous to %p\n", child_1);
1558 SendMessage(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
1559
1560 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1561 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1562 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1563 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1564 ok(stack[0] == child_4 && stack[1] == child_2 &&
1565 stack[2] == child_1 && stack[3] == child_3,
1566 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1567 child_4, child_2, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1568
1569 DestroyWindow(child_1);
1570 DestroyWindow(child_2);
1571 DestroyWindow(child_3);
1572 DestroyWindow(child_4);
1573 }
1574
1575 /**********************************************************************
1576 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1577 *
1578 * Note: The rule here is that client rect of the maximized MDI child
1579 * is equal to the client rect of the MDI client window.
1580 */
1581 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1582 {
1583 RECT rect;
1584
1585 GetClientRect( client, &rect );
1586 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1587 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1588
1589 rect.right -= rect.left;
1590 rect.bottom -= rect.top;
1591 lpMinMax->ptMaxSize.x = rect.right;
1592 lpMinMax->ptMaxSize.y = rect.bottom;
1593
1594 lpMinMax->ptMaxPosition.x = rect.left;
1595 lpMinMax->ptMaxPosition.y = rect.top;
1596
1597 trace("max rect (%d,%d - %d, %d)\n",
1598 rect.left, rect.top, rect.right, rect.bottom);
1599 }
1600
1601 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1602 {
1603 switch (msg)
1604 {
1605 case WM_NCCREATE:
1606 case WM_CREATE:
1607 {
1608 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1609 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1610
1611 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1612 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1613
1614 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1615 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1616 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1617 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1618 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1619
1620 /* MDICREATESTRUCT should have original values */
1621 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1622 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1623 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1624 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1625 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1626 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1627
1628 /* CREATESTRUCT should have fixed values */
1629 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1630 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1631
1632 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1633 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1634 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1635
1636 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1637
1638 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1639 {
1640 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1641 ok(cs->style == style,
1642 "cs->style does not match (%08x)\n", cs->style);
1643 }
1644 else
1645 {
1646 LONG style = mdi_cs->style;
1647 style &= ~WS_POPUP;
1648 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1649 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1650 ok(cs->style == style,
1651 "cs->style does not match (%08x)\n", cs->style);
1652 }
1653 break;
1654 }
1655
1656 case WM_GETMINMAXINFO:
1657 {
1658 HWND client = GetParent(hwnd);
1659 RECT rc;
1660 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1661 MINMAXINFO my_minmax;
1662 LONG style, exstyle;
1663
1664 style = GetWindowLongA(hwnd, GWL_STYLE);
1665 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1666
1667 GetWindowRect(client, &rc);
1668 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1669 GetClientRect(client, &rc);
1670 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1671 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1672 GetSystemMetrics(SM_CYSCREEN));
1673
1674 GetClientRect(client, &rc);
1675 if ((style & WS_CAPTION) == WS_CAPTION)
1676 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1677 AdjustWindowRectEx(&rc, style, 0, exstyle);
1678 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1679 dump_minmax_info( minmax );
1680
1681 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1682 minmax->ptMaxSize.x, rc.right - rc.left);
1683 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1684 minmax->ptMaxSize.y, rc.bottom - rc.top);
1685
1686 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1687
1688 trace("DefMDIChildProc returned:\n");
1689 dump_minmax_info( minmax );
1690
1691 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1692 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1693 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1694 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1695 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1696
1697 return 1;
1698 }
1699
1700 case WM_MDIACTIVATE:
1701 {
1702 HWND active, client = GetParent(hwnd);
1703 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1704 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1705 if (hwnd == (HWND)lparam) /* if we are being activated */
1706 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1707 else
1708 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1709 break;
1710 }
1711 }
1712 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1713 }
1714
1715 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1716 {
1717 switch (msg)
1718 {
1719 case WM_NCCREATE:
1720 case WM_CREATE:
1721 {
1722 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1723
1724 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1725 cs->x, cs->y, cs->cx, cs->cy);
1726
1727 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1728 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1729
1730 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1731 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1732
1733 /* CREATESTRUCT should have fixed values */
1734 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1735 while NT does. */
1736 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1737 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1738
1739 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1740 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1741 while Win95, Win2k, WinXP do. */
1742 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1743 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1744 break;
1745 }
1746
1747 case WM_GETMINMAXINFO:
1748 {
1749 HWND parent = GetParent(hwnd);
1750 RECT rc;
1751 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1752 LONG style, exstyle;
1753
1754 style = GetWindowLongA(hwnd, GWL_STYLE);
1755 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1756
1757 GetClientRect(parent, &rc);
1758 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1759
1760 GetClientRect(parent, &rc);
1761 if ((style & WS_CAPTION) == WS_CAPTION)
1762 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1763 AdjustWindowRectEx(&rc, style, 0, exstyle);
1764 dump_minmax_info( minmax );
1765
1766 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1767 minmax->ptMaxSize.x, rc.right - rc.left);
1768 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1769 minmax->ptMaxSize.y, rc.bottom - rc.top);
1770 break;
1771 }
1772
1773 case WM_WINDOWPOSCHANGED:
1774 {
1775 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1776 RECT rc1, rc2;
1777
1778 GetWindowRect(hwnd, &rc1);
1779 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1780 /* note: winpos coordinates are relative to parent */
1781 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1782 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1783 rc1.left, rc1.top, rc1.right, rc1.bottom,
1784 rc2.left, rc2.top, rc2.right, rc2.bottom);
1785 GetWindowRect(hwnd, &rc1);
1786 GetClientRect(hwnd, &rc2);
1787 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1788 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1789 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1790 rc1.left, rc1.top, rc1.right, rc1.bottom,
1791 rc2.left, rc2.top, rc2.right, rc2.bottom);
1792 }
1793 /* fall through */
1794 case WM_WINDOWPOSCHANGING:
1795 {
1796 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1797 WINDOWPOS my_winpos = *winpos;
1798
1799 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1800 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1801 winpos->hwnd, winpos->hwndInsertAfter,
1802 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1803
1804 DefWindowProcA(hwnd, msg, wparam, lparam);
1805
1806 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1807 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1808 winpos->hwnd, winpos->hwndInsertAfter,
1809 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1810
1811 return 1;
1812 }
1813 }
1814 return DefWindowProcA(hwnd, msg, wparam, lparam);
1815 }
1816
1817 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1818 {
1819 static HWND mdi_client;
1820
1821 switch (msg)
1822 {
1823 case WM_CREATE:
1824 {
1825 CLIENTCREATESTRUCT client_cs;
1826 RECT rc;
1827
1828 GetClientRect(hwnd, &rc);
1829
1830 client_cs.hWindowMenu = 0;
1831 client_cs.idFirstChild = 1;
1832
1833 /* MDIClient without MDIS_ALLCHILDSTYLES */
1834 mdi_client = CreateWindowExA(0, "mdiclient",
1835 NULL,
1836 WS_CHILD /*| WS_VISIBLE*/,
1837 /* tests depend on a not zero MDIClient size */
1838 0, 0, rc.right, rc.bottom,
1839 hwnd, 0, GetModuleHandle(0),
1840 &client_cs);
1841 assert(mdi_client);
1842 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1843 DestroyWindow(mdi_client);
1844
1845 /* MDIClient with MDIS_ALLCHILDSTYLES */
1846 mdi_client = CreateWindowExA(0, "mdiclient",
1847 NULL,
1848 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1849 /* tests depend on a not zero MDIClient size */
1850 0, 0, rc.right, rc.bottom,
1851 hwnd, 0, GetModuleHandle(0),
1852 &client_cs);
1853 assert(mdi_client);
1854 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1855 DestroyWindow(mdi_client);
1856
1857 /* Test child window stack management */
1858 mdi_client = CreateWindowExA(0, "mdiclient",
1859 NULL,
1860 WS_CHILD,
1861 0, 0, rc.right, rc.bottom,
1862 hwnd, 0, GetModuleHandle(0),
1863 &client_cs);
1864 assert(mdi_client);
1865 test_MDI_child_stack(mdi_client);
1866 DestroyWindow(mdi_client);
1867 break;
1868 }
1869
1870 case WM_WINDOWPOSCHANGED:
1871 {
1872 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1873 RECT rc1, rc2;
1874
1875 GetWindowRect(hwnd, &rc1);
1876 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1877 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1878 /* note: winpos coordinates are relative to parent */
1879 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1880 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1881 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1882
1883 GetWindowRect(hwnd, &rc1);
1884 GetClientRect(hwnd, &rc2);
1885 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1886 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1887 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1888 }
1889 /* fall through */
1890 case WM_WINDOWPOSCHANGING:
1891 {
1892 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1893 WINDOWPOS my_winpos = *winpos;
1894
1895 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1896 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1897 winpos->hwnd, winpos->hwndInsertAfter,
1898 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1899
1900 DefWindowProcA(hwnd, msg, wparam, lparam);
1901
1902 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1903 winpos->hwnd, winpos->hwndInsertAfter,
1904 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1905
1906 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1907 "DefWindowProc should not change WINDOWPOS values\n");
1908
1909 return 1;
1910 }
1911
1912 case WM_CLOSE:
1913 PostQuitMessage(0);
1914 break;
1915 }
1916 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1917 }
1918
1919 static BOOL mdi_RegisterWindowClasses(void)
1920 {
1921 WNDCLASSA cls;
1922
1923 cls.style = 0;
1924 cls.lpfnWndProc = mdi_main_wnd_procA;
1925 cls.cbClsExtra = 0;
1926 cls.cbWndExtra = 0;
1927 cls.hInstance = GetModuleHandleA(0);
1928 cls.hIcon = 0;
1929 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1930 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1931 cls.lpszMenuName = NULL;
1932 cls.lpszClassName = "MDI_parent_Class";
1933 if(!RegisterClassA(&cls)) return FALSE;
1934
1935 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1936 cls.lpszClassName = "MDI_child_Class_1";
1937 if(!RegisterClassA(&cls)) return FALSE;
1938
1939 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1940 cls.lpszClassName = "MDI_child_Class_2";
1941 if(!RegisterClassA(&cls)) return FALSE;
1942
1943 return TRUE;
1944 }
1945
1946 static void test_mdi(void)
1947 {
1948 HWND mdi_hwndMain;
1949 /*MSG msg;*/
1950
1951 if (!mdi_RegisterWindowClasses()) assert(0);
1952
1953 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1954 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1955 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1956 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1957 GetDesktopWindow(), 0,
1958 GetModuleHandle(0), NULL);
1959 assert(mdi_hwndMain);
1960 /*
1961 while(GetMessage(&msg, 0, 0, 0))
1962 {
1963 TranslateMessage(&msg);
1964 DispatchMessage(&msg);
1965 }
1966 */
1967 DestroyWindow(mdi_hwndMain);
1968 }
1969
1970 static void test_icons(void)
1971 {
1972 WNDCLASSEXA cls;
1973 HWND hwnd;
1974 HICON icon = LoadIconA(0, IDI_APPLICATION);
1975 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1976 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1977 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1978 HICON res;
1979
1980 cls.cbSize = sizeof(cls);
1981 cls.style = 0;
1982 cls.lpfnWndProc = DefWindowProcA;
1983 cls.cbClsExtra = 0;
1984 cls.cbWndExtra = 0;
1985 cls.hInstance = 0;
1986 cls.hIcon = LoadIconA(0, IDI_HAND);
1987 cls.hIconSm = small_icon;
1988 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1989 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1990 cls.lpszMenuName = NULL;
1991 cls.lpszClassName = "IconWindowClass";
1992
1993 RegisterClassExA(&cls);
1994
1995 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1996 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1997 assert( hwnd );
1998
1999 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2000 ok( res == 0, "wrong big icon %p/0\n", res );
2001 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
2002 ok( res == 0, "wrong previous big icon %p/0\n", res );
2003 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2004 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
2005 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
2006 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
2007 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2008 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2009
2010 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2011 ok( res == 0, "wrong small icon %p/0\n", res );
2012 /* this test is XP specific */
2013 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2014 ok( res != 0, "wrong small icon %p\n", res );*/
2015 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2016 ok( res == 0, "wrong previous small icon %p/0\n", res );
2017 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2018 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2019 /* this test is XP specific */
2020 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2021 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
2022 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2023 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2024 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2025 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2026 /* this test is XP specific */
2027 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2028 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
2029
2030 /* make sure the big icon hasn't changed */
2031 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2032 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2033
2034 DestroyWindow( hwnd );
2035 }
2036
2037 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2038 {
2039 if (msg == WM_NCCALCSIZE)
2040 {
2041 RECT *rect = (RECT *)lparam;
2042 /* first time around increase the rectangle, next time decrease it */
2043 if (rect->left == 100) InflateRect( rect, 10, 10 );
2044 else InflateRect( rect, -10, -10 );
2045 return 0;
2046 }
2047 return DefWindowProc( hwnd, msg, wparam, lparam );
2048 }
2049
2050 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2051 {
2052 RECT orig_win_rc, rect;
2053 LONG_PTR old_proc;
2054 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2055 HWND hwnd_desktop;
2056 RECT rc1, rc2;
2057 BOOL ret;
2058
2059 SetRect(&rect, 111, 222, 333, 444);
2060 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2061 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2062 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2063
2064 SetRect(&rect, 111, 222, 333, 444);
2065 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2066 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2067 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2068
2069 GetWindowRect(hwnd, &orig_win_rc);
2070
2071 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2072 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2073 ok(ret, "Got %d\n", ret);
2074 GetWindowRect( hwnd, &rect );
2075 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2076 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2077 GetClientRect( hwnd, &rect );
2078 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2079 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2080 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2081
2082 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2083 ok(ret, "Got %d\n", ret);
2084 GetWindowRect( hwnd, &rect );
2085 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2086 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2087 GetClientRect( hwnd, &rect );
2088 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2089 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2090 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2091
2092 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2093 orig_win_rc.right, orig_win_rc.bottom, 0);
2094 ok(ret, "Got %d\n", ret);
2095 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
2096
2097 /* Win9x truncates coordinates to 16-bit irrespectively */
2098 if (!is_win9x)
2099 {
2100 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2101 ok(ret, "Got %d\n", ret);
2102 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2103 ok(ret, "Got %d\n", ret);
2104
2105 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2106 ok(ret, "Got %d\n", ret);
2107 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2108 ok(ret, "Got %d\n", ret);
2109 }
2110
2111 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2112 orig_win_rc.right, orig_win_rc.bottom, 0);
2113 ok(ret, "Got %d\n", ret);
2114
2115 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2116 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2117 ok(ret, "Got %d\n", ret);
2118 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2119 ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2120 ok(ret, "Got %d\n", ret);
2121 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2122 ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2123 ok(ret, "Got %d\n", ret);
2124 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2125
2126 hwnd_desktop = GetDesktopWindow();
2127 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2128 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2129 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2130 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2131 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2132 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2133 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2134
2135 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2136 ok(ret, "Got %d\n", ret);
2137 check_active_state(hwnd, hwnd, hwnd);
2138
2139 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2140 ok(ret, "Got %d\n", ret);
2141 check_active_state(hwnd2, hwnd2, hwnd2);
2142
2143 /* Returns TRUE also for windows that are not siblings */
2144 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2145 ok(ret, "Got %d\n", ret);
2146 check_active_state(hwnd2, hwnd2, hwnd2);
2147
2148 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2149 ok(ret, "Got %d\n", ret);
2150 check_active_state(hwnd2, hwnd2, hwnd2);
2151
2152 /* Does not seem to do anything even without passing flags, still returns TRUE */
2153 GetWindowRect(hwnd_child, &rc1);
2154 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2155 ok(ret, "Got %d\n", ret);
2156 GetWindowRect(hwnd_child, &rc2);
2157 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2158 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2159 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2160 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2161 check_active_state(hwnd2, hwnd2, hwnd2);
2162
2163 /* Same thing the other way around. */
2164 GetWindowRect(hwnd2, &rc1);
2165 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2166 ok(ret, "Got %d\n", ret);
2167 GetWindowRect(hwnd2, &rc2);
2168 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2169 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2170 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2171 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2172 check_active_state(hwnd2, hwnd2, hwnd2);
2173
2174 /* .. and with these windows. */
2175 GetWindowRect(hwnd_grandchild, &rc1);
2176 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2177 ok(ret, "Got %d\n", ret);
2178 GetWindowRect(hwnd_grandchild, &rc2);
2179 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2180 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2181 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2182 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2183 check_active_state(hwnd2, hwnd2, hwnd2);
2184
2185 /* Add SWP_NOZORDER and it will be properly resized. */
2186 GetWindowRect(hwnd_grandchild, &rc1);
2187 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2188 ok(ret, "Got %d\n", ret);
2189 GetWindowRect(hwnd_grandchild, &rc2);
2190 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2191 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2192 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2193 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2194 check_active_state(hwnd2, hwnd2, hwnd2);
2195
2196 /* Given a sibling window, the window is properly resized. */
2197 GetWindowRect(hwnd_child, &rc1);
2198 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2199 ok(ret, "Got %d\n", ret);
2200 GetWindowRect(hwnd_child, &rc2);
2201 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2202 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2203 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2204 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2205 check_active_state(hwnd2, hwnd2, hwnd2);
2206
2207 /* Involving the desktop window changes things. */
2208 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2209 ok(!ret, "Got %d\n", ret);
2210 check_active_state(hwnd2, hwnd2, hwnd2);
2211
2212 GetWindowRect(hwnd_child, &rc1);
2213 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2214 ok(!ret, "Got %d\n", ret);
2215 GetWindowRect(hwnd_child, &rc2);
2216 ok(rc1.top == rc2.top && rc1.left == rc2.left &&
2217 rc1.bottom == rc2.bottom && rc1.right == rc2.right,
2218 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2219 rc1.top, rc1.left, rc1.bottom, rc1.right, rc2.top, rc2.left, rc2.bottom, rc2.right);
2220 check_active_state(hwnd2, hwnd2, hwnd2);
2221
2222 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2223 ok(!ret, "Got %d\n", ret);
2224 check_active_state(hwnd2, hwnd2, hwnd2);
2225
2226 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2227 ok(!ret, "Got %d\n", ret);
2228 check_active_state(hwnd2, hwnd2, hwnd2);
2229
2230 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2231 ok(!ret, "Got %d\n", ret);
2232 check_active_state(hwnd2, hwnd2, hwnd2);
2233
2234 DestroyWindow(hwnd_grandchild);
2235 DestroyWindow(hwnd_child);
2236 DestroyWindow(hwnd_child2);
2237
2238 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2239 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2240 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2241 ok(ret, "Got %d\n", ret);
2242 flush_events( TRUE );
2243 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2244 DestroyWindow(hwnd_child);
2245 }
2246
2247 static void test_SetMenu(HWND parent)
2248 {
2249 HWND child;
2250 HMENU hMenu, ret;
2251 BOOL retok;
2252 DWORD style;
2253
2254 hMenu = CreateMenu();
2255 assert(hMenu);
2256
2257 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2258 if (0)
2259 {
2260 /* fails on (at least) Wine, NT4, XP SP2 */
2261 test_nonclient_area(parent);
2262 }
2263 ret = GetMenu(parent);
2264 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2265 /* test whether we can destroy a menu assigned to a window */
2266 retok = DestroyMenu(hMenu);
2267 ok( retok, "DestroyMenu error %d\n", GetLastError());
2268 retok = IsMenu(hMenu);
2269 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2270 ret = GetMenu(parent);
2271 /* This test fails on Win9x */
2272 if (!is_win9x)
2273 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2274 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2275 test_nonclient_area(parent);
2276
2277 hMenu = CreateMenu();
2278 assert(hMenu);
2279
2280 /* parent */
2281 ret = GetMenu(parent);
2282 ok(ret == 0, "unexpected menu id %p\n", ret);
2283
2284 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2285 test_nonclient_area(parent);
2286 ret = GetMenu(parent);
2287 ok(ret == 0, "unexpected menu id %p\n", ret);
2288
2289 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2290 if (0)
2291 {
2292 /* fails on (at least) Wine, NT4, XP SP2 */
2293 test_nonclient_area(parent);
2294 }
2295 ret = GetMenu(parent);
2296 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2297
2298 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2299 test_nonclient_area(parent);
2300 ret = GetMenu(parent);
2301 ok(ret == 0, "unexpected menu id %p\n", ret);
2302
2303 /* child */
2304 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2305 assert(child);
2306
2307 ret = GetMenu(child);
2308 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2309
2310 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2311 test_nonclient_area(child);
2312 ret = GetMenu(child);
2313 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2314
2315 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2316 test_nonclient_area(child);
2317 ret = GetMenu(child);
2318 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2319
2320 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2321 test_nonclient_area(child);
2322 ret = GetMenu(child);
2323 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2324
2325 style = GetWindowLong(child, GWL_STYLE);
2326 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
2327 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2328 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2329 SetWindowLong(child, GWL_STYLE, style);
2330
2331 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
2332 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
2333 SetWindowLong(child, GWL_STYLE, style);
2334
2335 DestroyWindow(child);
2336 DestroyMenu(hMenu);
2337 }
2338
2339 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2340 {
2341 HWND child[5], hwnd;
2342 INT_PTR i;
2343
2344 assert(total <= 5);
2345
2346 hwnd = GetWindow(parent, GW_CHILD);
2347 ok(!hwnd, "have to start without children to perform the test\n");
2348
2349 for (i = 0; i < total; i++)
2350 {
2351 if (style[i] & DS_CONTROL)
2352 {
2353 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2354 0,0,0,0, parent, (HMENU)i, 0, NULL);
2355 if (style[i] & WS_VISIBLE)
2356 ShowWindow(child[i], SW_SHOW);
2357
2358 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2359 }
2360 else
2361 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2362 parent, (HMENU)i, 0, NULL);
2363 trace("child[%ld] = %p\n", i, child[i]);
2364 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2365 }
2366
2367 hwnd = GetWindow(parent, GW_CHILD);
2368 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2369 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2370 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2371
2372 for (i = 0; i < total; i++)
2373 {
2374 trace("hwnd[%ld] = %p\n", i, hwnd);
2375 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2376
2377 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2378 }
2379
2380 for (i = 0; i < total; i++)
2381 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2382 }
2383
2384 static void test_children_zorder(HWND parent)
2385 {
2386 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2387 WS_CHILD };
2388 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2389
2390 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2391 WS_CHILD | WS_VISIBLE, WS_CHILD,
2392 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2393 const int complex_order_1[1] = { 0 };
2394 const int complex_order_2[2] = { 1, 0 };
2395 const int complex_order_3[3] = { 1, 0, 2 };
2396 const int complex_order_4[4] = { 1, 0, 2, 3 };
2397 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2398 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2399 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2400 WS_CHILD | WS_VISIBLE };
2401 const int complex_order_6[3] = { 0, 1, 2 };
2402
2403 /* simple WS_CHILD */
2404 test_window_tree(parent, simple_style, simple_order, 5);
2405
2406 /* complex children styles */
2407 test_window_tree(parent, complex_style, complex_order_1, 1);
2408 test_window_tree(parent, complex_style, complex_order_2, 2);
2409 test_window_tree(parent, complex_style, complex_order_3, 3);
2410 test_window_tree(parent, complex_style, complex_order_4, 4);
2411 test_window_tree(parent, complex_style, complex_order_5, 5);
2412
2413 /* another set of complex children styles */
2414 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2415 }
2416
2417 #define check_z_order(hwnd, next, prev, owner, topmost) \
2418 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2419 __FILE__, __LINE__)
2420
2421 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2422 BOOL topmost, const char *file, int line)
2423 {
2424 HWND test;
2425 DWORD ex_style;
2426
2427 test = GetWindow(hwnd, GW_HWNDNEXT);
2428 /* skip foreign windows */
2429 while (test && test != next &&
2430 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2431 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2432 GetWindow(test, GW_OWNER) == next))
2433 {
2434 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2435 test = GetWindow(test, GW_HWNDNEXT);
2436 }
2437 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2438
2439 test = GetWindow(hwnd, GW_HWNDPREV);
2440 /* skip foreign windows */
2441 while (test && test != prev &&
2442 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2443 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2444 GetWindow(test, GW_OWNER) == hwnd))
2445 {
2446 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2447 test = GetWindow(test, GW_HWNDPREV);
2448 }
2449 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2450
2451 test = GetWindow(hwnd, GW_OWNER);
2452 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2453
2454 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2455 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2456 hwnd, topmost ? "" : "NOT ");
2457 }
2458
2459 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2460 {
2461 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2462
2463 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2464
2465 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2466
2467 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2468 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2469
2470 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2471 WS_OVERLAPPED | WS_CAPTION,
2472 100, 100, 100, 100,
2473 0, 0, GetModuleHandle(0), NULL);
2474 trace("hwnd_F %p\n", hwnd_F);
2475 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2476
2477 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2478 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2479 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2480 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2481
2482 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2483 style,
2484 100, 100, 100, 100,
2485 hwnd_F, 0, GetModuleHandle(0), NULL);
2486 trace("hwnd_C %p\n", hwnd_C);
2487 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2488 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2489 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2490 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2491
2492 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2493 style,
2494 100, 100, 100, 100,
2495 hwnd_F, 0, GetModuleHandle(0), NULL);
2496 trace("hwnd_B %p\n", hwnd_B);
2497 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2498 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2499 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2500 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2501 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2502
2503 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2504 style,
2505 100, 100, 100, 100,
2506 0, 0, GetModuleHandle(0), NULL);
2507 trace("hwnd_A %p\n", hwnd_A);
2508 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2509 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2510 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2511 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2512 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2513 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2514
2515 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);
2516
2517 /* move hwnd_F and its popups up */
2518 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2519 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2520 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2521 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2522 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2523 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2524 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2525
2526 /* move hwnd_F and its popups down */
2527 #if 0 /* enable once Wine is fixed to pass this test */
2528 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2529 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2530 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2531 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2532 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2533 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2534 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2535 #endif
2536
2537 /* make hwnd_C owned by a topmost window */
2538 DestroyWindow( hwnd_C );
2539 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2540 style,
2541 100, 100, 100, 100,
2542 hwnd_A, 0, GetModuleHandle(0), NULL);
2543 trace("hwnd_C %p\n", hwnd_C);
2544 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2545 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2546 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2547 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2548 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2549 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2550
2551 DestroyWindow(hwnd_A);
2552 DestroyWindow(hwnd_B);
2553 DestroyWindow(hwnd_C);
2554 DestroyWindow(hwnd_F);
2555 }
2556
2557 static void test_vis_rgn( HWND hwnd )
2558 {
2559 RECT win_rect, rgn_rect;
2560 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2561 HDC hdc;
2562
2563 ShowWindow(hwnd,SW_SHOW);
2564 hdc = GetDC( hwnd );
2565 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2566 GetWindowRect( hwnd, &win_rect );
2567 GetRgnBox( hrgn, &rgn_rect );
2568 if (is_win9x)
2569 {
2570 trace("win9x, mapping to screen coords\n");
2571 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2572 }
2573 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2574 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2575 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2576 rgn_rect.left, win_rect.left );
2577 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2578 rgn_rect.top, win_rect.top );
2579 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2580 rgn_rect.right, win_rect.right );
2581 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2582 rgn_rect.bottom, win_rect.bottom );
2583 ReleaseDC( hwnd, hdc );
2584 }
2585
2586 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2587 {
2588 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2589 {
2590 HWND child = GetWindow(hwnd, GW_CHILD);
2591 ok(child != 0, "couldn't find child window\n");
2592 SetFocus(child);
2593 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2594 return 0;
2595 }
2596 return DefWindowProc(hwnd, msg, wp, lp);
2597 }
2598
2599 static void test_SetFocus(HWND hwnd)
2600 {
2601 HWND child, child2, ret;
2602 WNDPROC old_wnd_proc;
2603
2604 /* check if we can set focus to non-visible windows */
2605
2606 ShowWindow(hwnd, SW_SHOW);
2607 SetFocus(0);
2608 SetFocus(hwnd);
2609 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2610 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2611 ShowWindow(hwnd, SW_HIDE);
2612 SetFocus(0);
2613 SetFocus(hwnd);
2614 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2615 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2616 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2617 assert(child);
2618 SetFocus(child);
2619 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2620 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2621 ShowWindow(child, SW_SHOW);
2622 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2623 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2624 ShowWindow(child, SW_HIDE);
2625 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2626 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2627 ShowWindow(child, SW_SHOW);
2628 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2629 assert(child2);
2630 ShowWindow(child2, SW_SHOW);
2631 SetFocus(child2);
2632 ShowWindow(child, SW_HIDE);
2633 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2634 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2635 ShowWindow(child, SW_SHOW);
2636 SetFocus(child);
2637 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2638 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2639 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2640
2641 ShowWindow(child, SW_HIDE);
2642 SetFocus(hwnd);
2643 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2644 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2645 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2646 ShowWindow(child, SW_HIDE);
2647 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2648
2649 ShowWindow(hwnd, SW_SHOW);
2650 ShowWindow(child, SW_SHOW);
2651 SetFocus(child);
2652 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2653 EnableWindow(hwnd, FALSE);
2654 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2655 EnableWindow(hwnd, TRUE);
2656
2657 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2658 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2659 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2660 todo_wine
2661 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2662 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2663 ShowWindow(hwnd, SW_RESTORE);
2664 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2665 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2666 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2667 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2668 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2669 todo_wine
2670 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2671 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2672 ShowWindow(hwnd, SW_RESTORE);
2673 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2674 todo_wine
2675 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2676 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2677
2678 SetFocus( hwnd );
2679 SetParent( child, GetDesktopWindow());
2680 SetParent( child2, child );
2681 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2682 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2683 ret = SetFocus( child2 );
2684 ok( ret == 0, "SetFocus %p should fail\n", child2);
2685 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2686 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2687 ret = SetFocus( child );
2688 ok( ret == 0, "SetFocus %p should fail\n", child);
2689 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2690 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2691 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
2692 SetFocus( child2 );
2693 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2694 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
2695 SetFocus( hwnd );
2696 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2697 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2698 SetFocus( child );
2699 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2700 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2701
2702 DestroyWindow( child2 );
2703 DestroyWindow( child );
2704 }
2705
2706 static void test_SetActiveWindow(HWND hwnd)
2707 {
2708 HWND hwnd2;
2709
2710 flush_events( TRUE );
2711 ShowWindow(hwnd, SW_HIDE);
2712 SetFocus(0);
2713 SetActiveWindow(0);
2714 check_wnd_state(0, 0, 0, 0);
2715
2716 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2717
2718 ShowWindow(hwnd, SW_SHOW);
2719 check_wnd_state(hwnd, hwnd, hwnd, 0);
2720
2721 hwnd2 = SetActiveWindow(0);
2722 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2723 if (!GetActiveWindow()) /* doesn't always work on vista */
2724 {
2725 check_wnd_state(0, 0, 0, 0);
2726 hwnd2 = SetActiveWindow(hwnd);
2727 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2728 }
2729 check_wnd_state(hwnd, hwnd, hwnd, 0);
2730
2731 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2732 check_wnd_state(hwnd, hwnd, hwnd, 0);
2733
2734 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2735 check_wnd_state(hwnd, hwnd, hwnd, 0);
2736
2737 ShowWindow(hwnd, SW_HIDE);
2738 check_wnd_state(0, 0, 0, 0);
2739
2740 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2741 SetActiveWindow(hwnd);
2742 check_wnd_state(hwnd, hwnd, hwnd, 0);
2743
2744 ShowWindow(hwnd, SW_SHOW);
2745 check_wnd_state(hwnd, hwnd, hwnd, 0);
2746
2747 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2748 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2749
2750 DestroyWindow(hwnd2);
2751 check_wnd_state(hwnd, hwnd, hwnd, 0);
2752
2753 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2754 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2755
2756 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2757 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2758
2759 DestroyWindow(hwnd2);
2760 check_wnd_state(hwnd, hwnd, hwnd, 0);
2761 }
2762
2763 struct create_window_thread_params
2764 {
2765 HWND window;
2766 HANDLE window_created;
2767 HANDLE test_finished;
2768 };
2769
2770 static DWORD WINAPI create_window_thread(void *param)
2771 {
2772 struct create_window_thread_params *p = param;
2773 DWORD res;
2774 BOOL ret;
2775
2776 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2777
2778 ret = SetEvent(p->window_created);
2779 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2780
2781 res = WaitForSingleObject(p->test_finished, INFINITE);
2782 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2783
2784 DestroyWindow(p->window);
2785 return 0;
2786 }
2787
2788 static void test_SetForegroundWindow(HWND hwnd)
2789 {
2790 struct create_window_thread_params thread_params;
2791 HANDLE thread;
2792 DWORD res, tid;
2793 BOOL ret;
2794 HWND hwnd2;
2795 MSG msg;
2796
2797 flush_events( TRUE );
2798 ShowWindow(hwnd, SW_HIDE);
2799 SetFocus(0);
2800 SetActiveWindow(0);
2801 check_wnd_state(0, 0, 0, 0);
2802
2803 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2804
2805 ShowWindow(hwnd, SW_SHOW);
2806 check_wnd_state(hwnd, hwnd, hwnd, 0);
2807
2808 hwnd2 = SetActiveWindow(0);
2809 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2810 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2811 check_wnd_state(hwnd, hwnd, hwnd, 0);
2812 else
2813 check_wnd_state(0, 0, 0, 0);
2814
2815 ret = SetForegroundWindow(hwnd);
2816 if (!ret)
2817 {
2818 skip( "SetForegroundWindow not working\n" );
2819 return;
2820 }
2821 check_wnd_state(hwnd, hwnd, hwnd, 0);
2822
2823 SetLastError(0xdeadbeef);
2824 ret = SetForegroundWindow(0);
2825 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2826 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2827 broken(GetLastError() == 0xdeadbeef), /* win9x */
2828 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2829 check_wnd_state(hwnd, hwnd, hwnd, 0);
2830
2831 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2832 check_wnd_state(hwnd, hwnd, hwnd, 0);
2833
2834 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2835 check_wnd_state(hwnd, hwnd, hwnd, 0);
2836
2837 hwnd2 = GetForegroundWindow();
2838 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2839 ret = SetForegroundWindow( GetDesktopWindow() );
2840 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2841 hwnd2 = GetForegroundWindow();
2842 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2843
2844 ShowWindow(hwnd, SW_HIDE);
2845 check_wnd_state(0, 0, 0, 0);
2846
2847 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2848 ret = SetForegroundWindow(hwnd);
2849 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2850 check_wnd_state(hwnd, hwnd, hwnd, 0);
2851
2852 ShowWindow(hwnd, SW_SHOW);
2853 check_wnd_state(hwnd, hwnd, hwnd, 0);
2854
2855 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2856 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2857
2858 DestroyWindow(hwnd2);
2859 check_wnd_state(hwnd, hwnd, hwnd, 0);
2860
2861 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2862 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2863
2864 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2865 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2866
2867 DestroyWindow(hwnd2);
2868 check_wnd_state(hwnd, hwnd, hwnd, 0);
2869
2870 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2871 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2872
2873 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2874 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2875 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2876 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2877 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2878 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2879 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2880 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2881 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2882
2883 SetForegroundWindow(hwnd2);
2884 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2885
2886 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2887 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2888 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2889 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2890
2891 SetEvent(thread_params.test_finished);
2892 WaitForSingleObject(thread, INFINITE);
2893 CloseHandle(thread_params.test_finished);
2894 CloseHandle(thread_params.window_created);
2895 CloseHandle(thread);
2896 DestroyWindow(hwnd2);
2897 }
2898
2899 static WNDPROC old_button_proc;
2900
2901 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2902 {
2903 LRESULT ret;
2904 USHORT key_state;
2905
2906 key_state = GetKeyState(VK_LBUTTON);
2907 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2908
2909 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2910
2911 if (msg == WM_LBUTTONDOWN)
2912 {
2913 HWND hwnd, capture;
2914
2915 check_wnd_state(button, button, button, button);
2916
2917 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2918 assert(hwnd);
2919 trace("hwnd %p\n", hwnd);
2920
2921 check_wnd_state(button, button, button, button);
2922
2923 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2924
2925 check_wnd_state(button, button, button, button);
2926
2927 DestroyWindow(hwnd);
2928
2929 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2930 assert(hwnd);
2931 trace("hwnd %p\n", hwnd);
2932
2933 check_wnd_state(button, button, button, button);
2934
2935 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2936 * match internal button state.
2937 */
2938 SendMessage(button, WM_KILLFOCUS, 0, 0);
2939 check_wnd_state(button, button, button, 0);
2940
2941 ShowWindow(hwnd, SW_SHOW);
2942 check_wnd_state(hwnd, hwnd, hwnd, 0);
2943
2944 capture = SetCapture(hwnd);
2945 ok(capture == 0, "SetCapture() = %p\n", capture);
2946
2947 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2948
2949 DestroyWindow(hwnd);
2950
2951 check_wnd_state(button, 0, button, 0);
2952 }
2953
2954 return ret;
2955 }
2956
2957 static void test_capture_1(void)
2958 {
2959 HWND button, capture;
2960
2961 capture = GetCapture();
2962 ok(capture == 0, "GetCapture() = %p\n", capture);
2963
2964 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2965 assert(button);
2966 trace("button %p\n", button);
2967
2968 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2969
2970 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2971
2972 capture = SetCapture(button);
2973 ok(capture == 0, "SetCapture() = %p\n", capture);
2974 check_wnd_state(button, 0, button, button);
2975
2976 DestroyWindow(button);
2977 /* old active window test depends on previously executed window
2978 * activation tests, and fails under NT4.
2979 check_wnd_state(oldActive, 0, oldFocus, 0);*/
2980 }
2981
2982 static void test_capture_2(void)
2983 {
2984 HWND button, hwnd, capture, oldFocus, oldActive;
2985
2986 oldFocus = GetFocus();
2987 oldActive = GetActiveWindow();
2988 check_wnd_state(oldActive, 0, oldFocus, 0);
2989
2990 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2991 assert(button);
2992 trace("button %p\n", button);
2993
2994 check_wnd_state(button, button, button, 0);
2995
2996 capture = SetCapture(button);
2997 ok(capture == 0, "SetCapture() = %p\n", capture);
2998
2999 check_wnd_state(button, button, button, button);
3000
3001 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3002 * internal button state.
3003 */
3004 SendMessage(button, WM_KILLFOCUS, 0, 0);
3005 check_wnd_state(button, button, button, button);
3006
3007 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3008 assert(hwnd);
3009 trace("hwnd %p\n", hwnd);
3010
3011 check_wnd_state(button, button, button, button);
3012
3013 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3014
3015 check_wnd_state(button, button, button, button);
3016
3017 DestroyWindow(hwnd);
3018
3019 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3020 assert(hwnd);
3021 trace("hwnd %p\n", hwnd);
3022
3023 check_wnd_state(button, button, button, button);
3024
3025 ShowWindow(hwnd, SW_SHOW);
3026
3027 check_wnd_state(hwnd, hwnd, hwnd, button);
3028
3029 capture = SetCapture(hwnd);
3030 ok(capture == button, "SetCapture() = %p\n", capture);
3031
3032 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3033
3034 DestroyWindow(hwnd);
3035 check_wnd_state(button, button, button, 0);
3036
3037 DestroyWindow(button);
3038 check_wnd_state(oldActive, 0, oldFocus, 0);
3039 }
3040
3041 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3042 {
3043 BOOL ret;
3044
3045 ShowWindow(hwnd1, SW_HIDE);
3046 ShowWindow(hwnd2, SW_HIDE);
3047
3048 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3049 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3050
3051 SetCapture(hwnd1);
3052 check_wnd_state(0, 0, 0, hwnd1);
3053
3054 SetCapture(hwnd2);
3055 check_wnd_state(0, 0, 0, hwnd2);
3056
3057 ShowWindow(hwnd1, SW_SHOW);
3058 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3059
3060 ret = ReleaseCapture();
3061 ok (ret, "releasecapture did not return TRUE.\n");
3062 ret = ReleaseCapture();
3063 ok (ret, "releasecapture did not return TRUE after second try.\n");
3064 }
3065
3066 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3067 {
3068 GUITHREADINFO gti;
3069 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3070 BOOL status;
3071 switch (msg)
3072 {
3073 case WM_CAPTURECHANGED:
3074
3075 /* now try to release capture from menu. this should fail */
3076 if (pGetGUIThreadInfo)
3077 {
3078 memset(&gti, 0, sizeof(GUITHREADINFO));
3079 gti.cbSize = sizeof(GUITHREADINFO);
3080 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3081 ok(status, "GetGUIThreadInfo() failed!\n");
3082 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3083 }
3084 cap_wnd = GetCapture();
3085
3086 /* check that re-setting the capture for the menu fails */
3087 set_cap_wnd = SetCapture(cap_wnd);
3088 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3089 "SetCapture should have failed!\n");
3090 if (set_cap_wnd)
3091 {
3092 DestroyWindow(hWnd);
3093 break;
3094 }
3095
3096 /* check that SetCapture fails for another window and that it does not touch the error code */
3097 set_cap_wnd = SetCapture(hWnd);
3098 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3099
3100 /* check that ReleaseCapture fails and does not touch the error code */
3101 status = ReleaseCapture();
3102 ok(!status, "ReleaseCapture should have failed!\n");
3103
3104 /* check that thread info did not change */
3105 if (pGetGUIThreadInfo)
3106 {
3107 memset(&gti, 0, sizeof(GUITHREADINFO));
3108 gti.cbSize = sizeof(GUITHREADINFO);
3109 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3110 ok(status, "GetGUIThreadInfo() failed!\n");
3111 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3112 }
3113
3114 /* verify that no capture change took place */
3115 cap_wnd2 = GetCapture();
3116 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3117
3118 /* we are done. kill the window */
3119 DestroyWindow(hWnd);
3120 break;
3121
3122 default:
3123 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3124 }
3125 return 0;
3126 }
3127
3128 /* Test that no-one can mess around with the current capture while a menu is open */
3129 static void test_capture_4(void)
3130 {
3131 BOOL ret;
3132 HMENU hmenu;
3133 HWND hwnd;
3134 WNDCLASSA wclass;
3135 HINSTANCE hInstance = GetModuleHandleA( NULL );
3136 ATOM aclass;
3137
3138 if (!pGetGUIThreadInfo)
3139 {
3140 win_skip("GetGUIThreadInfo is not available\n");
3141 return;
3142 }
3143 wclass.lpszClassName = "TestCapture4Class";
3144 wclass.style = CS_HREDRAW | CS_VREDRAW;
3145 wclass.lpfnWndProc = test_capture_4_proc;
3146 wclass.hInstance = hInstance;
3147 wclass.hIcon = LoadIconA( 0, IDI_APPLICATION );
3148 wclass.hCursor = LoadCursorA( NULL, IDC_ARROW );
3149 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3150 wclass.lpszMenuName = 0;
3151 wclass.cbClsExtra = 0;
3152 wclass.cbWndExtra = 0;
3153 aclass = RegisterClassA( &wclass );
3154 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3155 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3156 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3157 400, 200, NULL, NULL, hInstance, NULL);
3158 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3159 if (!hwnd) return;
3160 hmenu = CreatePopupMenu();
3161
3162 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3163 ok( ret, "AppendMenuA has failed!\n");
3164
3165 /* set main window to have initial capture */
3166 SetCapture(hwnd);
3167
3168 if (is_win9x)
3169 {
3170 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3171 }
3172 else
3173 {
3174 /* create popup (it will self-destruct) */
3175 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3176 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3177 }
3178
3179 /* clean up */
3180 DestroyMenu(hmenu);
3181 DestroyWindow(hwnd);
3182 }
3183
3184 /* PeekMessage wrapper that ignores the messages we don't care about */
3185 static BOOL peek_message( MSG *msg )
3186 {
3187 BOOL ret;
3188 do
3189 {
3190 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3191 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
3192 return ret;
3193 }
3194
3195 static void test_keyboard_input(HWND hwnd)
3196 {
3197 MSG msg;
3198 BOOL ret;
3199
3200 flush_events( TRUE );
3201 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3202 UpdateWindow(hwnd);
3203 flush_events( TRUE );
3204
3205 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3206
3207 SetFocus(hwnd);
3208 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3209
3210 flush_events( TRUE );
3211
3212 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3213 ret = peek_message(&msg);
3214 ok( ret, "no message available\n");
3215 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3216 ret = peek_message(&msg);
3217 ok( !ret, "message %04x available\n", msg.message);
3218
3219 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3220
3221 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3222 ret = peek_message(&msg);
3223 ok(ret, "no message available\n");
3224 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3225 ret = peek_message(&msg);
3226 ok( !ret, "message %04x available\n", msg.message);
3227
3228 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3229
3230 keybd_event(VK_SPACE, 0, 0, 0);
3231 if (!peek_message(&msg))
3232 {
3233 skip( "keybd_event didn't work, skipping keyboard test\n" );
3234 return;
3235 }
3236 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3237 ret = peek_message(&msg);
3238 ok( !ret, "message %04x available\n", msg.message);
3239
3240 SetFocus(0);
3241 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3242
3243 flush_events( TRUE );
3244
3245 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3246 ret = peek_message(&msg);
3247 ok(ret, "no message available\n");
3248 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3249 ret = peek_message(&msg);
3250 ok( !ret, "message %04x available\n", msg.message);
3251
3252 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3253
3254 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3255 ret = peek_message(&msg);
3256 ok(ret, "no message available\n");
3257 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3258 ret = peek_message(&msg);
3259 ok( !ret, "message %04x available\n", msg.message);
3260
3261 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3262
3263 keybd_event(VK_SPACE, 0, 0, 0);
3264 ret = peek_message(&msg);
3265 ok(ret, "no message available\n");
3266 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3267 ret = peek_message(&msg);
3268 ok( !ret, "message %04x available\n", msg.message);
3269 }
3270
3271 static BOOL wait_for_message( MSG *msg )
3272 {
3273 BOOL ret;
3274
3275 for (;;)
3276 {
3277 ret = peek_message(msg);
3278 if (ret)
3279 {
3280 if (msg->message == WM_PAINT) DispatchMessage(msg);
3281 else break;
3282 }
3283 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3284 }
3285 if (!ret) msg->message = 0;
3286 return ret;
3287 }
3288
3289 static void test_mouse_input(HWND hwnd)
3290 {
3291 RECT rc;
3292 POINT pt;
3293 int x, y;
3294 HWND popup;
3295 MSG msg;
3296 BOOL ret;
3297 LRESULT res;
3298
3299 ShowWindow(hwnd, SW_SHOWNORMAL);
3300 UpdateWindow(hwnd);
3301 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3302
3303 GetWindowRect(hwnd, &rc);
3304 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3305
3306 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3307 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3308 hwnd, 0, 0, NULL);
3309 assert(popup != 0);
3310 ShowWindow(popup, SW_SHOW);
3311 UpdateWindow(popup);
3312 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3313
3314 GetWindowRect(popup, &rc);
3315 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3316
3317 x = rc.left + (rc.right - rc.left) / 2;
3318 y = rc.top + (rc.bottom - rc.top) / 2;
3319 trace("setting cursor to (%d,%d)\n", x, y);
3320
3321 SetCursorPos(x, y);
3322 GetCursorPos(&pt);
3323 if (x != pt.x || y != pt.y)
3324 {
3325 skip( "failed to set mouse position, skipping mouse input tests\n" );
3326 goto done;
3327 }
3328
3329 flush_events( TRUE );
3330
3331 /* Check that setting the same position may generate WM_MOUSEMOVE */
3332 SetCursorPos(x, y);
3333 msg.message = 0;
3334 ret = peek_message(&msg);
3335 if (ret)
3336 {
3337 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3338 msg.hwnd, msg.message);
3339 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3340 x, y, msg.pt.x, msg.pt.y);
3341 }
3342
3343 /* force the system to update its internal queue mouse position,
3344 * otherwise it won't generate relative mouse movements below.
3345 */
3346 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3347 flush_events( TRUE );
3348
3349 msg.message = 0;
3350 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3351 flush_events( FALSE );
3352 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3353 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3354 {
3355 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3356 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3357 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3358 DispatchMessage(&msg);
3359 }
3360 ret = peek_message(&msg);
3361 ok( !ret, "message %04x available\n", msg.message);
3362
3363 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3364 ShowWindow(popup, SW_HIDE);
3365 ret = wait_for_message( &msg );
3366 if (ret)
3367 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3368 flush_events( TRUE );
3369
3370 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3371 ShowWindow(hwnd, SW_HIDE);
3372 ret = wait_for_message( &msg );
3373 ok( !ret, "message %04x available\n", msg.message);
3374 flush_events( TRUE );
3375
3376 /* test mouse clicks */
3377
3378 ShowWindow(hwnd, SW_SHOW);
3379 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3380 flush_events( TRUE );
3381 ShowWindow(popup, SW_SHOW);
3382 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3383 flush_events( TRUE );
3384
3385 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3386 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3387 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3388 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3389
3390 ret = wait_for_message( &msg );
3391 if (!ret)
3392 {
3393 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3394 goto done;
3395 }
3396 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3397 {
3398 ret = wait_for_message( &msg );
3399 ok(ret, "no message available\n");
3400 }
3401
3402 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3403 msg.hwnd, popup, msg.message);
3404
3405 ret = wait_for_message( &msg );
3406 ok(ret, "no message available\n");
3407 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3408 msg.hwnd, popup, msg.message);
3409
3410 ret = wait_for_message( &msg );
3411 ok(ret, "no message available\n");
3412 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3413 msg.hwnd, popup, msg.message);
3414
3415 ret = wait_for_message( &msg );
3416 ok(ret, "no message available\n");
3417 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3418 msg.hwnd, popup, msg.message);
3419
3420 ret = peek_message(&msg);
3421 ok(!ret, "message %04x available\n", msg.message);
3422
3423 ShowWindow(popup, SW_HIDE);
3424 flush_events( TRUE );
3425
3426 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3427 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3428 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3429 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3430
3431 ret = wait_for_message( &msg );
3432 ok(ret, "no message available\n");
3433 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3434 msg.hwnd, hwnd, msg.message);
3435 ret = wait_for_message( &msg );
3436 ok(ret, "no message available\n");
3437 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3438 msg.hwnd, hwnd, msg.message);
3439
3440 test_lbuttondown_flag = TRUE;
3441 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3442 test_lbuttondown_flag = FALSE;
3443
3444 ret = wait_for_message( &msg );
3445 ok(ret, "no message available\n");
3446 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3447 msg.hwnd, popup, msg.message);
3448 ok(peek_message(&msg), "no message available\n");
3449 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3450 msg.hwnd, popup, msg.message);
3451 ok(peek_message(&msg), "no message available\n");
3452
3453 /* Test WM_MOUSEACTIVATE */
3454 #define TEST_MOUSEACTIVATE(A,B) \
3455 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3456 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3457
3458 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3459 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3460 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3461 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3462 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3463 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3464 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3465 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3466 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3467 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3468 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3469 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3470 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3471 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3472 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3473 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3474 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3475 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3476 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3477 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3478 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3479 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3480 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3481 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3482
3483 done:
3484 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3485 flush_events( TRUE );
3486
3487 DestroyWindow(popup);
3488 }
3489
3490 static void test_validatergn(HWND hwnd)
3491 {
3492 HWND child;
3493 RECT rc, rc2;
3494 HRGN rgn;
3495 int ret;
3496 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3497 ShowWindow(hwnd, SW_SHOW);
3498 UpdateWindow( hwnd);
3499 /* test that ValidateRect validates children*/
3500 InvalidateRect( child, NULL, 1);
3501 GetWindowRect( child, &rc);
3502 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3503 ret = GetUpdateRect( child, &rc2, 0);
3504 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3505 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3506 "Update rectangle is empty!\n");
3507 ValidateRect( hwnd, &rc);
3508 ret = GetUpdateRect( child, &rc2, 0);
3509 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3510 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3511 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3512 rc2.right, rc2.bottom);
3513
3514 /* now test ValidateRgn */
3515 InvalidateRect( child, NULL, 1);
3516 GetWindowRect( child, &rc);
3517 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3518 rgn = CreateRectRgnIndirect( &rc);
3519 ValidateRgn( hwnd, rgn);
3520 ret = GetUpdateRect( child, &rc2, 0);
3521 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3522 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3523 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3524 rc2.right, rc2.bottom);
3525
3526 DeleteObject( rgn);
3527 DestroyWindow( child );
3528 }
3529
3530 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3531 {
3532 RECT rc;
3533 MoveWindow( hwnd, 0, 0, x, y, 0);
3534 GetWindowRect( hwnd, prc);
3535 rc = *prc;
3536 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3537 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3538 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3539 }
3540
3541 static void test_nccalcscroll(HWND parent)
3542 {
3543 RECT rc1;
3544 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3545 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3546 HWND hwnd = CreateWindowExA(0, "static", NULL,
3547 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3548 10, 10, 200, 200, parent, 0, 0, NULL);
3549 ShowWindow( parent, SW_SHOW);
3550 UpdateWindow( parent);
3551
3552 /* test window too low for a horizontal scroll bar */
3553 nccalchelper( hwnd, 100, sbheight, &rc1);
3554 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3555 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3556
3557 /* test window just high enough for a horizontal scroll bar */
3558 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3559 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3560 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3561
3562 /* test window too narrow for a vertical scroll bar */
3563 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3564 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3565 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3566
3567 /* test window just wide enough for a vertical scroll bar */
3568 nccalchelper( hwnd, sbwidth, 100, &rc1);
3569 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3570 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3571
3572 /* same test, but with client edge: not enough width */
3573 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3574 nccalchelper( hwnd, sbwidth, 100, &rc1);
3575 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3576 "Width should be %d size is %d,%d - %d,%d\n",
3577 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3578
3579 DestroyWindow( hwnd);
3580 }
3581
3582 static void test_SetParent(void)
3583 {
3584 HWND desktop = GetDesktopWindow();
3585 HMENU hMenu;
3586 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3587 BOOL bret;
3588
3589 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3590 100, 100, 200, 200, 0, 0, 0, NULL);
3591 assert(parent != 0);
3592 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3593 0, 0, 50, 50, parent, 0, 0, NULL);
3594 assert(child1 != 0);
3595 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3596 0, 0, 50, 50, child1, 0, 0, NULL);
3597 assert(child2 != 0);
3598 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3599 0, 0, 50, 50, child2, 0, 0, NULL);
3600 assert(child3 != 0);
3601 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3602 0, 0, 50, 50, child3, 0, 0, NULL);
3603 assert(child4 != 0);
3604
3605 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3606 parent, child1, child2, child3, child4);
3607
3608 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3609 check_parents(child1, parent, parent, parent, 0, parent, parent);
3610 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3611 check_parents(child3, child2, child2, child2, 0, child2, parent);
3612 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3613
3614 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3615 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3616 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3617 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3618 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3619
3620 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3621 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3622 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3623 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3624 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3625 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3626 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3627 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3628 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3629
3630 if (!is_win9x) /* Win9x doesn't survive this test */
3631 {
3632 ok(!SetParent(parent, child1), "SetParent should fail\n");
3633 ok(!SetParent(child2, child3), "SetParent should fail\n");
3634 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3635 ret = SetParent(parent, child2);
3636 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3637 if (ret) /* nt4, win2k */
3638 {
3639 ret = SetParent(parent, child3);
3640 ok(ret != 0, "SetParent should not fail\n");
3641 ret = SetParent(child2, parent);
3642 ok(!ret, "SetParent should fail\n");
3643 ret = SetParent(parent, child4);
3644 ok(ret != 0, "SetParent should not fail\n");
3645 check_parents(parent, child4, child4, 0, 0, child4, parent);
3646 check_parents(child1, parent, parent, parent, 0, child4, parent);
3647 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3648 check_parents(child3, child2, child2, child2, 0, child2, parent);
3649 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3650 }
3651 else
3652 {
3653 ret = SetParent(parent, child3);
3654 ok(ret != 0, "SetParent should not fail\n");
3655 ret = SetParent(child2, parent);
3656 ok(!ret, "SetParent should fail\n");
3657 ret = SetParent(parent, child4);
3658 ok(!ret, "SetParent should fail\n");
3659 check_parents(parent, child3, child3, 0, 0, child2, parent);
3660 check_parents(child1, parent, parent, parent, 0, child2, parent);
3661 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3662 check_parents(child3, child2, child2, child2, 0, child2, parent);
3663 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3664 }
3665 }
3666 else
3667 skip("Win9x/WinMe crash\n");
3668
3669 hMenu = CreateMenu();
3670 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3671 100, 100, 200, 200, 0, hMenu, 0, NULL);
3672 assert(sibling != 0);
3673
3674 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3675 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3676
3677 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3678
3679 ok(!IsWindow(parent), "parent still exists\n");
3680 ok(!IsWindow(sibling), "sibling still exists\n");
3681 ok(!IsWindow(child1), "child1 still exists\n");
3682 ok(!IsWindow(child2), "child2 still exists\n");
3683 ok(!IsWindow(child3), "child3 still exists\n");
3684 ok(!IsWindow(child4), "child4 still exists\n");
3685
3686 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3687 100, 100, 200, 200, 0, 0, 0, NULL);
3688 assert(parent != 0);
3689 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3690 0, 0, 50, 50, parent, 0, 0, NULL);
3691 assert(child1 != 0);
3692 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
3693 0, 0, 50, 50, 0, 0, 0, NULL);
3694 assert(popup != 0);
3695
3696 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
3697
3698 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3699 check_parents(child1, parent, parent, parent, 0, parent, parent);
3700 check_parents(popup, desktop, 0, 0, 0, popup, popup);
3701
3702 SetActiveWindow(parent);
3703 SetFocus(parent);
3704 check_active_state(parent, 0, parent);
3705
3706 ret = SetParent(popup, child1);
3707 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
3708 check_parents(popup, child1, child1, 0, 0, parent, popup);
3709 todo_wine
3710 check_active_state(popup, 0, popup);
3711
3712 SetActiveWindow(parent);
3713 SetFocus(parent);
3714 check_active_state(parent, 0, parent);
3715
3716 bret = SetForegroundWindow(popup);
3717 todo_wine {
3718 ok(bret || broken(!bret), "SetForegroundWindow() failed\n");
3719 if (!bret)
3720 check_active_state(popup, 0, popup);
3721 else
3722 check_active_state(popup, popup, popup);
3723 }
3724
3725 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3726
3727 ok(!IsWindow(parent), "parent still exists\n");
3728 ok(!IsWindow(child1), "child1 still exists\n");
3729 ok(!IsWindow(popup), "popup still exists\n");
3730 }
3731
3732 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3733 {
3734 LPCREATESTRUCT lpcs;
3735 LPSTYLESTRUCT lpss;
3736
3737 switch (msg)
3738 {
3739 case WM_NCCREATE:
3740 case WM_CREATE:
3741 lpcs = (LPCREATESTRUCT)lparam;
3742 lpss = lpcs->lpCreateParams;
3743 if (lpss)
3744 {
3745 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3746 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3747 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3748 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3749 else
3750 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3751
3752 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3753 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3754 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3755
3756 ok(lpss->styleNew == lpcs->style,
3757 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3758 lpss->styleNew, lpcs->style);
3759 }
3760 break;
3761 }
3762 return DefWindowProc(hwnd, msg, wparam, lparam);
3763 }
3764
3765 static ATOM atomStyleCheckClass;
3766
3767 static void register_style_check_class(void)
3768 {
3769 WNDCLASS wc =
3770 {
3771 0,
3772 StyleCheckProc,
3773 0,
3774 0,
3775 GetModuleHandle(NULL),
3776 NULL,
3777 LoadCursor(NULL, IDC_ARROW),
3778 (HBRUSH)(COLOR_BTNFACE+1),
3779 NULL,
3780 TEXT("WineStyleCheck"),
3781 };
3782
3783 atomStyleCheckClass = RegisterClass(&wc);
3784 assert(atomStyleCheckClass);
3785 }
3786
3787 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3788 {
3789 DWORD dwActualStyle;
3790 DWORD dwActualExStyle;
3791 STYLESTRUCT ss;
3792 HWND hwnd;
3793 HWND hwndParent = NULL;
3794
3795 ss.styleNew = dwStyleIn;
3796 ss.styleOld = dwExStyleIn;
3797
3798 if (dwStyleIn & WS_CHILD)
3799 {
3800 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3801 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3802 }
3803
3804 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3805 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3806 assert(hwnd);
3807
3808 flush_events( TRUE );
3809
3810 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3811 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3812 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3813 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3814
3815 /* try setting the styles explicitly */
3816 SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
3817 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3818 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3819 /* WS_EX_WINDOWEDGE can't always be changed */
3820 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3821 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3822 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3823 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3824 else
3825 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3826 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3827 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3828
3829 SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
3830 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3831 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3832 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3833 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
3834 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3835 /* WS_EX_WINDOWEDGE can't always be changed */
3836 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3837 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3838 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3839 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3840 else
3841 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3842 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3843 /* FIXME: Remove the condition below once Wine is fixed */
3844 if (dwActualExStyle != dwExStyleOut)
3845 todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3846 else
3847 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3848
3849 DestroyWindow(hwnd);
3850 if (hwndParent) DestroyWindow(hwndParent);
3851 }
3852
3853 /* tests what window styles the window manager automatically adds */
3854 static void test_window_styles(void)
3855 {
3856 register_style_check_class();
3857
3858 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3859 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3860 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3861 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3862 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3863 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3864 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3865 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3866 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3867 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3868 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3869 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3870 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3871 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3872 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3873 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3874 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3875 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3876 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3877 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3878 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3879 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3880 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3881 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3882 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3883 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3884 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3885 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3886 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3887 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3888 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3889 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3890 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3891
3892 if (pGetLayeredWindowAttributes)
3893 {
3894 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3895 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3896 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3897 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3898 }
3899 }
3900
3901 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3902 {
3903 return 0;
3904 }
3905
3906 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
3907 {
3908 struct
3909 {
3910 DLGTEMPLATE dt;
3911 WORD menu_name;
3912 WORD class_id;
3913 WORD class_atom;
3914 WCHAR caption[1];
3915 } dlg_data;
3916 DWORD style, ex_style;
3917 HWND hwnd, parent = 0;
3918
3919 if (style_in & WS_CHILD)
3920 parent = CreateWindowEx(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3921 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3922
3923 dlg_data.dt.style = style_in;
3924 dlg_data.dt.dwExtendedStyle = ex_style_in;
3925 dlg_data.dt.cdit = 0;
3926 dlg_data.dt.x = 0;
3927 dlg_data.dt.y = 0;
3928 dlg_data.dt.cx = 100;
3929 dlg_data.dt.cy = 100;
3930 dlg_data.menu_name = 0;
3931 dlg_data.class_id = 0;
3932 dlg_data.class_atom = 0;
3933 dlg_data.caption[0] = 0;
3934
3935 hwnd = CreateDialogIndirectParam(GetModuleHandle(0), &dlg_data.dt, parent, empty_dlg_proc, 0);
3936 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
3937
3938 flush_events( TRUE );
3939
3940 style = GetWindowLong(hwnd, GWL_STYLE);
3941 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3942 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out | DS_3DLOOK, style);
3943 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3944
3945 /* try setting the styles explicitly */
3946 SetWindowLong(hwnd, GWL_EXSTYLE, ex_style_in);
3947 style = GetWindowLong(hwnd, GWL_STYLE);
3948 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3949 ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out|DS_3DLOOK, style);
3950 /* WS_EX_WINDOWEDGE can't always be changed */
3951 if (ex_style_in & WS_EX_DLGMODALFRAME)
3952 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3953 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3954 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3955 else
3956 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3957 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3958
3959 SetWindowLong(hwnd, GWL_STYLE, style_in);
3960 style = GetWindowLong(hwnd, GWL_STYLE);
3961 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
3962 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3963 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
3964 else style_out = style_in | WS_CLIPSIBLINGS;
3965 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
3966 /* WS_EX_WINDOWEDGE can't always be changed */
3967 if (ex_style_in & WS_EX_DLGMODALFRAME)
3968 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3969 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3970 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3971 else
3972 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
3973 /* FIXME: Remove the condition below once Wine is fixed */
3974 if (ex_style != ex_style_out)
3975 todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3976 else
3977 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3978
3979 DestroyWindow(hwnd);
3980 DestroyWindow(parent);
3981 }
3982
3983 static void test_dialog_styles(void)
3984 {
3985 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3986 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3987 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3988 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3989 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
3990 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3991 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3992 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3993 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3994 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3995 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3996 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3997 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3998 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
3999 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4000 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4001 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4002 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4003 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4004 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4005 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4006 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4007 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4008 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4009 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4010 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4011 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4012 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4013 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4014 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4015 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4016 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4017 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4018 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4019 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4020 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4021 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4022 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4023 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4024 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4025 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4026 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4027 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4028 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4029 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4030 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4031 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4032 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4033 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4034 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4035 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4036 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4037 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4038 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4039 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4040 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4041 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4042 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4043 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4044 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4045 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4046 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4047 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4048 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4049 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4050 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4051 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4052 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4053 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4054 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4055 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4056 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4057 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4058 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4059 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4060
4061 if (pGetLayeredWindowAttributes)
4062 {
4063 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4064 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4065 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4066 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4067 }
4068 }
4069
4070 static void test_scrollwindow( HWND hwnd)
4071 {
4072 HDC hdc;
4073 RECT rc, rc2, rc3;
4074 COLORREF colr;
4075
4076 ShowWindow( hwnd, SW_SHOW);
4077 UpdateWindow( hwnd);
4078 flush_events( TRUE );
4079 GetClientRect( hwnd, &rc);
4080 hdc = GetDC( hwnd);
4081 /* test ScrollWindow(Ex) with no clip rectangle */
4082 /* paint the lower half of the window black */
4083 rc2 = rc;
4084 rc2.top = ( rc2.top + rc2.bottom) / 2;
4085 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4086 /* paint the upper half of the window white */
4087 rc2.bottom = rc2.top;
4088 rc2.top =0;
4089 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4090 /* scroll lower half up */
4091 rc2 = rc;
4092 rc2.top = ( rc2.top + rc2.bottom) / 2;
4093 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4094 flush_events(FALSE);
4095 /* expected: black should have scrolled to the upper half */
4096 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4097 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4098 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4099 /* paint the lower half of the window black */
4100 rc2 = rc;
4101 rc2.top = ( rc2.top + rc2.bottom) / 2;
4102 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4103 /* paint the upper half of the window white */
4104 rc2.bottom = rc2.top;
4105 rc2.top =0;
4106 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4107 /* scroll lower half up */
4108 rc2 = rc;
4109 rc2.top = ( rc2.top + rc2.bottom) / 2;
4110 rc3 = rc;
4111 rc3.left = rc3.right / 4;
4112 rc3.right -= rc3.right / 4;
4113 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4114 flush_events(FALSE);
4115 /* expected: black should have scrolled to the upper half */
4116 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4117 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4118
4119 /* clean up */
4120 ReleaseDC( hwnd, hdc);
4121 }
4122
4123 static void test_scrollvalidate( HWND parent)
4124 {
4125 HDC hdc;
4126 HRGN hrgn=CreateRectRgn(0,0,0,0);
4127 HRGN exprgn, tmprgn, clipping;
4128 RECT rc, rcu, cliprc;
4129 /* create two overlapping child windows. The visual region
4130 * of hwnd1 is clipped by the overlapping part of
4131 * hwnd2 because of the WS_CLIPSIBLING style */
4132 HWND hwnd1, hwnd2;
4133
4134 clipping = CreateRectRgn(0,0,0,0);
4135 tmprgn = CreateRectRgn(0,0,0,0);
4136 exprgn = CreateRectRgn(0,0,0,0);
4137 hwnd2 = CreateWindowExA(0, "static", NULL,
4138 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4139 75, 30, 100, 100, parent, 0, 0, NULL);
4140 hwnd1 = CreateWindowExA(0, "static", NULL,
4141 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4142 25, 50, 100, 100, parent, 0, 0, NULL);
4143 ShowWindow( parent, SW_SHOW);
4144 UpdateWindow( parent);
4145 GetClientRect( hwnd1, &rc);
4146 cliprc=rc;
4147 SetRectRgn( clipping, 10, 10, 90, 90);
4148 hdc = GetDC( hwnd1);
4149 /* for a visual touch */
4150 TextOut( hdc, 0,10, "0123456789", 10);
4151 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4152 if (winetest_debug > 0) dump_region(hrgn);
4153 /* create a region with what is expected */
4154 SetRectRgn( exprgn, 39,0,49,74);
4155 SetRectRgn( tmprgn, 88,79,98,93);
4156 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4157 SetRectRgn( tmprgn, 0,93,98,98);
4158 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4159 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4160 trace("update rect is %d,%d - %d,%d\n",
4161 rcu.left,rcu.top,rcu.right,rcu.bottom);
4162 /* now with clipping region */
4163 SelectClipRgn( hdc, clipping);
4164 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4165 if (winetest_debug > 0) dump_region(hrgn);
4166 /* create a region with what is expected */
4167 SetRectRgn( exprgn, 39,10,49,74);
4168 SetRectRgn( tmprgn, 80,79,90,85);
4169 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4170 SetRectRgn( tmprgn, 10,85,90,90);
4171 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4172 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4173 trace("update rect is %d,%d - %d,%d\n",
4174 rcu.left,rcu.top,rcu.right,rcu.bottom);
4175 ReleaseDC( hwnd1, hdc);
4176
4177 /* test scrolling a window with an update region */
4178 DestroyWindow( hwnd2);
4179 ValidateRect( hwnd1, NULL);
4180 SetRect( &rc, 40,40, 50,50);
4181 InvalidateRect( hwnd1, &rc, 1);
4182 GetClientRect( hwnd1, &rc);
4183 cliprc=rc;
4184 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
4185 SW_SCROLLCHILDREN | SW_INVALIDATE);
4186 if (winetest_debug > 0) dump_region(hrgn);
4187 SetRectRgn( exprgn, 88,0,98,98);
4188 SetRectRgn( tmprgn, 30, 40, 50, 50);
4189 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4190 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4191
4192 /* clear an update region */
4193 UpdateWindow( hwnd1 );
4194
4195 SetRect( &rc, 0,40, 100,60);
4196 SetRect( &cliprc, 0,0, 100,100);
4197 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4198 if (winetest_debug > 0) dump_region( hrgn );
4199 SetRectRgn( exprgn, 0, 40, 98, 60 );
4200 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
4201
4202 /* now test ScrollWindowEx with a combination of
4203 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4204 /* make hwnd2 the child of hwnd1 */
4205 hwnd2 = CreateWindowExA(0, "static", NULL,
4206 WS_CHILD| WS_VISIBLE | WS_BORDER ,
4207 50, 50, 100, 100, hwnd1, 0, 0, NULL);
4208 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
4209 GetClientRect( hwnd1, &rc);
4210 cliprc=rc;
4211
4212 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4213 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4214 ValidateRect( hwnd1, NULL);
4215 ValidateRect( hwnd2, NULL);
4216 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
4217 SW_SCROLLCHILDREN | SW_INVALIDATE);
4218 if (winetest_debug > 0) dump_region(hrgn);
4219 SetRectRgn( exprgn, 88,0,98,88);
4220 SetRectRgn( tmprgn, 0,88,98,98);
4221 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4222 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4223
4224 /* SW_SCROLLCHILDREN */
4225 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4226 ValidateRect( hwnd1, NULL);
4227 ValidateRect( hwnd2, NULL);
4228 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
4229 if (winetest_debug > 0) dump_region(hrgn);
4230 /* expected region is the same as in previous test */
4231 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4232
4233 /* no SW_SCROLLCHILDREN */
4234 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4235 ValidateRect( hwnd1, NULL);
4236 ValidateRect( hwnd2, NULL);
4237 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4238 if (winetest_debug > 0) dump_region(hrgn);
4239 /* expected region is the same as in previous test */
4240 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4241
4242 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4243 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4244 ValidateRect( hwnd1, NULL);
4245 ValidateRect( hwnd2, NULL);
4246 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4247 if (winetest_debug > 0) dump_region(hrgn);
4248 SetRectRgn( exprgn, 88,0,98,20);
4249 SetRectRgn( tmprgn, 20,20,98,30);
4250 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4251 SetRectRgn( tmprgn, 20,30,30,88);
4252 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4253 SetRectRgn( tmprgn, 0,88,30,98);
4254 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4255 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4256
4257 /* clean up */
4258 DeleteObject( hrgn);
4259 DeleteObject( exprgn);
4260 DeleteObject( tmprgn);
4261 DestroyWindow( hwnd1);
4262 DestroyWindow( hwnd2);
4263 }
4264
4265 /* couple of tests of return values of scrollbar functions
4266 * called on a scrollbarless window */
4267 static void test_scroll(void)
4268 {
4269 BOOL ret;
4270 INT min, max;
4271 SCROLLINFO si;
4272 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
4273 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
4274 100, 100, 200, 200, 0, 0, 0, NULL);
4275 /* horizontal */
4276 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
4277 if (!ret) /* win9x */
4278 {
4279 win_skip( "GetScrollRange doesn't work\n" );
4280 DestroyWindow( hwnd);
4281 return;
4282 }
4283 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4284 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4285 si.cbSize = sizeof( si);
4286 si.fMask = SIF_PAGE;
4287 si.nPage = 0xdeadbeef;
4288 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
4289 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4290 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4291 /* vertical */
4292 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
4293 ok( ret, "GetScrollRange returns FALSE\n");
4294 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4295 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4296 si.cbSize = sizeof( si);
4297 si.fMask = SIF_PAGE;
4298 si.nPage = 0xdeadbeef;
4299 ret = GetScrollInfo( hwnd, SB_VERT, &si);
4300 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4301 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4302 /* clean up */
4303 DestroyWindow( hwnd);
4304 }
4305
4306 static void test_scrolldc( HWND parent)
4307 {
4308 HDC hdc;
4309 HRGN exprgn, tmprgn, hrgn;
4310 RECT rc, rc2, rcu, cliprc;
4311 HWND hwnd1;
4312 COLORREF colr;
4313
4314 hrgn = CreateRectRgn(0,0,0,0);
4315 tmprgn = CreateRectRgn(0,0,0,0);
4316 exprgn = CreateRectRgn(0,0,0,0);
4317
4318 hwnd1 = CreateWindowExA(0, "static", NULL,
4319 WS_CHILD| WS_VISIBLE,
4320 25, 50, 100, 100, parent, 0, 0, NULL);
4321 ShowWindow( parent, SW_SHOW);
4322 UpdateWindow( parent);
4323 flush_events( TRUE );
4324 GetClientRect( hwnd1, &rc);
4325 hdc = GetDC( hwnd1);
4326 /* paint the upper half of the window black */
4327 rc2 = rc;
4328 rc2.bottom = ( rc.top + rc.bottom) /2;
4329 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4330 /* clip region is the lower half */
4331 cliprc=rc;
4332 cliprc.top = (rc.top + rc.bottom) /2;
4333 /* test whether scrolled pixels are properly clipped */
4334 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4335 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4336 /* this scroll should not cause any visible changes */
4337 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
4338 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4339 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4340 /* test with NULL clip rect */
4341 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
4342 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4343 trace("update rect: %d,%d - %d,%d\n",
4344 rcu.left, rcu.top, rcu.right, rcu.bottom);
4345 if (winetest_debug > 0) dump_region(hrgn);
4346 SetRect(&rc2, 0, 0, 100, 100);
4347 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4348 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
4349
4350 SetRectRgn( exprgn, 0, 0, 20, 80);
4351 SetRectRgn( tmprgn, 0, 80, 100, 100);
4352 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4353 if (winetest_debug > 0) dump_region(exprgn);
4354 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4355 /* test clip rect > scroll rect */
4356 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
4357 rc2=rc;
4358 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
4359 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4360 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
4361 SetRectRgn( exprgn, 25, 25, 75, 35);
4362 SetRectRgn( tmprgn, 25, 35, 35, 75);
4363 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4364 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4365 trace("update rect: %d,%d - %d,%d\n",
4366 rcu.left, rcu.top, rcu.right, rcu.bottom);
4367 if (winetest_debug > 0) dump_region(hrgn);
4368
4369 /* clean up */
4370 DeleteObject(hrgn);
4371 DeleteObject(exprgn);
4372 DeleteObject(tmprgn);
4373 DestroyWindow(hwnd1);
4374 }
4375
4376 static void test_params(void)
4377 {
4378 HWND hwnd;
4379 INT rc;
4380
4381 ok(!IsWindow(0), "IsWindow(0)\n");
4382 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
4383 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
4384
4385 /* Just a param check */
4386 if (pGetMonitorInfoA)
4387 {
4388 SetLastError(0xdeadbeef);
4389 rc = GetWindowText(hwndMain2, NULL, 1024);
4390 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
4391 }
4392 else
4393 {
4394 /* Skips actually on Win95 and NT4 */
4395 win_skip("Test would crash on Win95\n");
4396 }
4397
4398 SetLastError(0xdeadbeef);
4399 hwnd=CreateWindow("LISTBOX", "TestList",
4400 (LBS_STANDARD & ~LBS_SORT),
4401 0, 0, 100, 100,
4402 NULL, (HMENU)1, NULL, 0);
4403
4404 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
4405 "CreateWindow with invalid menu handle should fail\n");
4406 if (!hwnd)
4407 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
4408 GetLastError() == 0xdeadbeef, /* Win9x */
4409 "wrong last error value %d\n", GetLastError());
4410 }
4411
4412 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
4413 {
4414 HWND hwnd = 0;
4415
4416 hwnd = CreateWindowEx(exStyle, class, class, style,
4417 110, 100,
4418 225, 200,
4419 0,
4420 menu ? hmenu : 0,
4421 0, 0);
4422 if (!hwnd) {
4423 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
4424 return;
4425 }
4426 ShowWindow(hwnd, SW_SHOW);
4427
4428 test_nonclient_area(hwnd);
4429
4430 SetMenu(hwnd, 0);
4431 DestroyWindow(hwnd);
4432 }
4433
4434 static BOOL AWR_init(void)
4435 {
4436 WNDCLASS class;
4437
4438 class.style = CS_HREDRAW | CS_VREDRAW;
4439 class.lpfnWndProc = DefWindowProcA;
4440 class.cbClsExtra = 0;
4441 class.cbWndExtra = 0;
4442 class.hInstance = 0;
4443 class.hIcon = LoadIcon (0, IDI_APPLICATION);
4444 class.hCursor = LoadCursor (0, IDC_ARROW);
4445 class.hbrBackground = 0;
4446 class.lpszMenuName = 0;
4447 class.lpszClassName = szAWRClass;
4448
4449 if (!RegisterClass (&class)) {
4450 ok(FALSE, "RegisterClass failed\n");
4451 return FALSE;
4452 }
4453
4454 hmenu = CreateMenu();
4455 if (!hmenu)
4456 return FALSE;
4457 ok(hmenu != 0, "Failed to create menu\n");
4458 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
4459
4460 return TRUE;
4461 }
4462
4463
4464 static void test_AWR_window_size(BOOL menu)
4465 {
4466 LONG styles[] = {
4467 WS_POPUP,
4468 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
4469 WS_SYSMENU,
4470 WS_THICKFRAME,
4471 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
4472 WS_HSCROLL, WS_VSCROLL
4473 };
4474 LONG exStyles[] = {
4475 WS_EX_CLIENTEDGE,
4476 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
4477 WS_EX_APPWINDOW,
4478 #if 0
4479 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4480 WS_EX_DLGMODALFRAME,
4481 WS_EX_STATICEDGE,
4482 #endif
4483 };
4484
4485 int i;
4486
4487 /* A exhaustive check of all the styles takes too long
4488 * so just do a (hopefully representative) sample
4489 */
4490 for (i = 0; i < COUNTOF(styles); ++i)
4491 test_AWRwindow(szAWRClass, styles[i], 0, menu);
4492 for (i = 0; i < COUNTOF(exStyles); ++i) {
4493 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
4494 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
4495 }
4496 }
4497 #undef COUNTOF
4498
4499 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4500
4501 static void test_AdjustWindowRect(void)
4502 {
4503 if (!AWR_init())
4504 return;
4505
4506 SHOWSYSMETRIC(SM_CYCAPTION);
4507 SHOWSYSMETRIC(SM_CYSMCAPTION);
4508 SHOWSYSMETRIC(SM_CYMENU);
4509 SHOWSYSMETRIC(SM_CXEDGE);
4510 SHOWSYSMETRIC(SM_CYEDGE);
4511 SHOWSYSMETRIC(SM_CXVSCROLL);
4512 SHOWSYSMETRIC(SM_CYHSCROLL);
4513 SHOWSYSMETRIC(SM_CXFRAME);
4514 SHOWSYSMETRIC(SM_CYFRAME);
4515 SHOWSYSMETRIC(SM_CXDLGFRAME);
4516 SHOWSYSMETRIC(SM_CYDLGFRAME);
4517 SHOWSYSMETRIC(SM_CXBORDER);
4518 SHOWSYSMETRIC(SM_CYBORDER);
4519
4520 test_AWR_window_size(FALSE);
4521 test_AWR_window_size(TRUE);
4522
4523 DestroyMenu(hmenu);
4524 }
4525 #undef SHOWSYSMETRIC
4526
4527
4528 /* Global variables to trigger exit from loop */
4529 static int redrawComplete, WMPAINT_count;
4530
4531 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4532 {
4533 switch (msg)
4534 {
4535 case WM_PAINT:
4536 trace("doing WM_PAINT %d\n", WMPAINT_count);
4537 WMPAINT_count++;
4538 if (WMPAINT_count > 10 && redrawComplete == 0) {
4539 PAINTSTRUCT ps;
4540 BeginPaint(hwnd, &ps);
4541 EndPaint(hwnd, &ps);
4542 return 1;
4543 }
4544 return 0;
4545 }
4546 return DefWindowProc(hwnd, msg, wparam, lparam);
4547 }
4548
4549 /* Ensure we exit from RedrawNow regardless of invalidated area */
4550 static void test_redrawnow(void)
4551 {
4552 WNDCLASSA cls;
4553 HWND hwndMain;
4554
4555 cls.style = CS_DBLCLKS;
4556 cls.lpfnWndProc = redraw_window_procA;
4557 cls.cbClsExtra = 0;
4558 cls.cbWndExtra = 0;
4559 cls.hInstance = GetModuleHandleA(0);
4560 cls.hIcon = 0;
4561 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4562 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4563 cls.lpszMenuName = NULL;
4564 cls.lpszClassName = "RedrawWindowClass";
4565
4566 if(!RegisterClassA(&cls)) {
4567 trace("Register failed %d\n", GetLastError());
4568 return;
4569 }
4570
4571 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4572 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4573
4574 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4575 ShowWindow(hwndMain, SW_SHOW);
4576 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4577 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4578 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4579 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4580 redrawComplete = TRUE;
4581 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4582
4583 /* clean up */
4584 DestroyWindow( hwndMain);
4585 }
4586
4587 struct parentdc_stat {
4588 RECT client;
4589 RECT clip;
4590 RECT paint;
4591 };
4592
4593 struct parentdc_test {
4594 struct parentdc_stat main, main_todo;
4595 struct parentdc_stat child1, child1_todo;
4596 struct parentdc_stat child2, child2_todo;
4597 };
4598
4599 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4600 {
4601 RECT rc;
4602 PAINTSTRUCT ps;
4603
4604 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4605
4606 switch (msg)
4607 {
4608 case WM_PAINT:
4609 GetClientRect(hwnd, &rc);
4610 CopyRect(&t->client, &rc);
4611 GetWindowRect(hwnd, &rc);
4612 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4613 t->client.left, t->client.top, t->client.right, t->client.bottom,
4614 rc.left, rc.top, rc.right, rc.bottom);
4615 BeginPaint(hwnd, &ps);
4616 CopyRect(&t->paint, &ps.rcPaint);
4617 GetClipBox(ps.hdc, &rc);
4618 CopyRect(&t->clip, &rc);
4619 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4620 rc.left, rc.top, rc.right, rc.bottom,
4621 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4622 EndPaint(hwnd, &ps);
4623 return 0;
4624 }
4625 return DefWindowProc(hwnd, msg, wparam, lparam);
4626 }
4627
4628 static void zero_parentdc_stat(struct parentdc_stat *t)
4629 {
4630 SetRectEmpty(&t->client);
4631 SetRectEmpty(&t->clip);
4632 SetRectEmpty(&t->paint);
4633 }
4634
4635 static void zero_parentdc_test(struct parentdc_test *t)
4636 {
4637 zero_parentdc_stat(&t->main);
4638 zero_parentdc_stat(&t->child1);
4639 zero_parentdc_stat(&t->child2);
4640 }
4641
4642 #define parentdc_field_ok(t, w, r, f, got) \
4643 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4644 ": expected %d, got %d\n", \
4645 t.w.r.f, got.w.r.f)
4646
4647 #define parentdc_todo_field_ok(t, w, r, f, got) \
4648 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4649 else parentdc_field_ok(t, w, r, f, got)
4650
4651 #define parentdc_rect_ok(t, w, r, got) \
4652 parentdc_todo_field_ok(t, w, r, left, got); \
4653 parentdc_todo_field_ok(t, w, r, top, got); \
4654 parentdc_todo_field_ok(t, w, r, right, got); \
4655 parentdc_todo_field_ok(t, w, r, bottom, got);
4656
4657 #define parentdc_win_ok(t, w, got) \
4658 parentdc_rect_ok(t, w, client, got); \
4659 parentdc_rect_ok(t, w, clip, got); \
4660 parentdc_rect_ok(t, w, paint, got);
4661
4662 #define parentdc_ok(t, got) \
4663 parentdc_win_ok(t, main, got); \
4664 parentdc_win_ok(t, child1, got); \
4665 parentdc_win_ok(t, child2, got);
4666
4667 static void test_csparentdc(void)
4668 {
4669 WNDCLASSA clsMain, cls;
4670 HWND hwndMain, hwnd1, hwnd2;
4671 RECT rc;
4672
4673 struct parentdc_test test_answer;
4674
4675 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4676 const struct parentdc_test test1 =
4677 {
4678 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4679 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4680 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4681 };
4682
4683 const struct parentdc_test test2 =
4684 {
4685 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4686 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4687 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4688 };
4689
4690 const struct parentdc_test test3 =
4691 {
4692 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4693 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4694 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4695 };
4696
4697 const struct parentdc_test test4 =
4698 {
4699 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4700 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4701 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4702 };
4703
4704 const struct parentdc_test test5 =
4705 {
4706 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4707 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4708 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4709 };
4710
4711 const struct parentdc_test test6 =
4712 {
4713 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4714 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4715 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4716 };
4717
4718 const struct parentdc_test test7 =
4719 {
4720 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4721 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4722 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4723 };
4724 #undef nothing_todo
4725
4726 clsMain.style = CS_DBLCLKS;
4727 clsMain.lpfnWndProc = parentdc_window_procA;
4728 clsMain.cbClsExtra = 0;
4729 clsMain.cbWndExtra = 0;
4730 clsMain.hInstance = GetModuleHandleA(0);
4731 clsMain.hIcon = 0;
4732 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
4733 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4734 clsMain.lpszMenuName = NULL;
4735 clsMain.lpszClassName = "ParentDcMainWindowClass";
4736
4737 if(!RegisterClassA(&clsMain)) {
4738 trace("Register failed %d\n", GetLastError());
4739 return;
4740 }
4741
4742 cls.style = CS_DBLCLKS | CS_PARENTDC;
4743 cls.lpfnWndProc = parentdc_window_procA;
4744 cls.cbClsExtra = 0;
4745 cls.cbWndExtra = 0;
4746 cls.hInstance = GetModuleHandleA(0);
4747 cls.hIcon = 0;
4748 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4749 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4750 cls.lpszMenuName = NULL;
4751 cls.lpszClassName = "ParentDcWindowClass";
4752
4753 if(!RegisterClassA(&cls)) {
4754 trace("Register failed %d\n", GetLastError());
4755 return;
4756 }
4757
4758 SetRect(&rc, 0, 0, 150, 150);
4759 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4760 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4761 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4762 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4763 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4764 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4765 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4766 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4767 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4768 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4769 ShowWindow(hwndMain, SW_SHOW);
4770 ShowWindow(hwnd1, SW_SHOW);
4771 ShowWindow(hwnd2, SW_SHOW);
4772 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4773 flush_events( TRUE );
4774
4775 zero_parentdc_test(&test_answer);
4776 InvalidateRect(hwndMain, NULL, TRUE);
4777 flush_events( TRUE );
4778 parentdc_ok(test1, test_answer);
4779
4780 zero_parentdc_test(&test_answer);
4781 SetRect(&rc, 0, 0, 50, 50);
4782 InvalidateRect(hwndMain, &rc, TRUE);
4783 flush_events( TRUE );
4784 parentdc_ok(test2, test_answer);
4785
4786 zero_parentdc_test(&test_answer);
4787 SetRect(&rc, 0, 0, 10, 10);
4788 InvalidateRect(hwndMain, &rc, TRUE);
4789 flush_events( TRUE );
4790 parentdc_ok(test3, test_answer);
4791
4792 zero_parentdc_test(&test_answer);
4793 SetRect(&rc, 40, 40, 50, 50);
4794 InvalidateRect(hwndMain, &rc, TRUE);
4795 flush_events( TRUE );
4796 parentdc_ok(test4, test_answer);
4797
4798 zero_parentdc_test(&test_answer);
4799 SetRect(&rc, 20, 20, 60, 60);
4800 InvalidateRect(hwndMain, &rc, TRUE);
4801 flush_events( TRUE );
4802 parentdc_ok(test5, test_answer);
4803
4804 zero_parentdc_test(&test_answer);
4805 SetRect(&rc, 0, 0, 10, 10);
4806 InvalidateRect(hwnd1, &rc, TRUE);
4807 flush_events( TRUE );
4808 parentdc_ok(test6, test_answer);
4809
4810 zero_parentdc_test(&test_answer);
4811 SetRect(&rc, -5, -5, 65, 65);
4812 InvalidateRect(hwnd1, &rc, TRUE);
4813 flush_events( TRUE );
4814 parentdc_ok(test7, test_answer);
4815
4816 DestroyWindow(hwndMain);
4817 DestroyWindow(hwnd1);
4818 DestroyWindow(hwnd2);
4819 }
4820
4821 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4822 {
4823 return DefWindowProcA(hwnd, msg, wparam, lparam);
4824 }
4825
4826 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4827 {
4828 return DefWindowProcW(hwnd, msg, wparam, lparam);
4829 }
4830
4831 static void test_IsWindowUnicode(void)
4832 {
4833 static const char ansi_class_nameA[] = "ansi class name";
4834 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4835 static const char unicode_class_nameA[] = "unicode class name";
4836 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4837 WNDCLASSA classA;
4838 WNDCLASSW classW;
4839 HWND hwnd;
4840
4841 memset(&classW, 0, sizeof(classW));
4842 classW.hInstance = GetModuleHandleA(0);
4843 classW.lpfnWndProc = def_window_procW;
4844 classW.lpszClassName = unicode_class_nameW;
4845 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4846
4847 memset(&classA, 0, sizeof(classA));
4848 classA.hInstance = GetModuleHandleA(0);
4849 classA.lpfnWndProc = def_window_procA;
4850 classA.lpszClassName = ansi_class_nameA;
4851 assert(RegisterClassA(&classA));
4852
4853 /* unicode class: window proc */
4854 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4855 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4856 assert(hwnd);
4857
4858 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4859 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4860 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4861 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4862 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4863
4864 DestroyWindow(hwnd);
4865
4866 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4867 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4868 assert(hwnd);
4869
4870 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4871 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4872 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4873 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4874 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4875
4876 DestroyWindow(hwnd);
4877
4878 /* ansi class: window proc */
4879 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4880 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4881 assert(hwnd);
4882
4883 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4884 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4885 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4886 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4887 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4888
4889 DestroyWindow(hwnd);
4890
4891 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4892 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4893 assert(hwnd);
4894
4895 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4896 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4897 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4898 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4899 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4900
4901 DestroyWindow(hwnd);
4902
4903 /* unicode class: class proc */
4904 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4905 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4906 assert(hwnd);
4907
4908 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4909 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4910 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4911 /* do not restore class window proc back to unicode */
4912
4913 DestroyWindow(hwnd);
4914
4915 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4916 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4917 assert(hwnd);
4918
4919 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4920 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4921 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4922
4923 DestroyWindow(hwnd);
4924
4925 /* ansi class: class proc */
4926 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4927 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4928 assert(hwnd);
4929
4930 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4931 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4932 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4933 /* do not restore class window proc back to ansi */
4934
4935 DestroyWindow(hwnd);
4936
4937 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4938 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4939 assert(hwnd);
4940
4941 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4942 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4943 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4944
4945 DestroyWindow(hwnd);
4946 }
4947
4948 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4949 {
4950 MINMAXINFO *minmax;
4951
4952 if (msg != WM_GETMINMAXINFO)
4953 return DefWindowProc(hwnd, msg, wp, lp);
4954
4955 minmax = (MINMAXINFO *)lp;
4956
4957 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4958 {
4959 minmax->ptReserved.x = 0;
4960 minmax->ptReserved.y = 0;
4961 minmax->ptMaxSize.x = 400;
4962 minmax->ptMaxSize.y = 400;
4963 minmax->ptMaxPosition.x = 300;
4964 minmax->ptMaxPosition.y = 300;
4965 minmax->ptMaxTrackSize.x = 200;
4966 minmax->ptMaxTrackSize.y = 200;
4967 minmax->ptMinTrackSize.x = 100;
4968 minmax->ptMinTrackSize.y = 100;
4969 }
4970 else
4971 DefWindowProc(hwnd, msg, wp, lp);
4972 return 1;
4973 }
4974
4975 static int expected_cx, expected_cy;
4976 static RECT expected_rect, broken_rect;
4977
4978 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4979 {
4980 switch(msg)
4981 {
4982 case WM_GETMINMAXINFO:
4983 {
4984 RECT rect;
4985 GetWindowRect( hwnd, &rect );
4986 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4987 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4988 return DefWindowProc(hwnd, msg, wp, lp);
4989 }
4990 case WM_NCCREATE:
4991 case WM_CREATE:
4992 {
4993 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4994 RECT rect;
4995 GetWindowRect( hwnd, &rect );
4996 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4997 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4998 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4999 "wrong x size %d/%d\n", cs->cx, expected_cx );
5000 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5001 "wrong y size %d/%d\n", cs->cy, expected_cy );
5002 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5003 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5004 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5005 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5006 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5007 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5008 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5009 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5010 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
5011 rect.left, rect.top, rect.right, rect.bottom,
5012 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
5013 return DefWindowProc(hwnd, msg, wp, lp);
5014 }
5015 case WM_NCCALCSIZE:
5016 {
5017 RECT rect, *r = (RECT *)lp;
5018 GetWindowRect( hwnd, &rect );
5019 ok( !memcmp( &rect, r, sizeof(rect) ),
5020 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
5021 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
5022 return DefWindowProc(hwnd, msg, wp, lp);
5023 }
5024 default:
5025 return DefWindowProc(hwnd, msg, wp, lp);
5026 }
5027 }
5028
5029 static void test_CreateWindow(void)
5030 {
5031 WNDCLASS cls;
5032 HWND hwnd, parent;
5033 HMENU hmenu;
5034 RECT rc, rc_minmax;
5035 MINMAXINFO minmax;
5036 BOOL res;
5037
5038 #define expect_menu(window, menu) \
5039 SetLastError(0xdeadbeef); \
5040 res = (GetMenu(window) == (HMENU)menu); \
5041 ok(res, "GetMenu error %d\n", GetLastError())
5042
5043 #define expect_style(window, style)\
5044 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
5045
5046 #define expect_ex_style(window, ex_style)\
5047 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
5048
5049 #define expect_gle_broken_9x(gle)\
5050 ok(GetLastError() == gle ||\
5051 broken(GetLastError() == 0xdeadbeef),\
5052 "IsMenu set error %d\n", GetLastError())
5053
5054 hmenu = CreateMenu();
5055 assert(hmenu != 0);
5056 parent = GetDesktopWindow();
5057 assert(parent != 0);
5058
5059 SetLastError(0xdeadbeef);
5060 res = IsMenu(hmenu);
5061 ok(res, "IsMenu error %d\n", GetLastError());
5062
5063 /* WS_CHILD */
5064 SetLastError(0xdeadbeef);
5065 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5066 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5067 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5068 expect_menu(hwnd, 1);
5069 expect_style(hwnd, WS_CHILD);
5070 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5071 DestroyWindow(hwnd);
5072
5073 SetLastError(0xdeadbeef);
5074 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5075 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5076 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5077 expect_menu(hwnd, 1);
5078 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5079 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5080 DestroyWindow(hwnd);
5081
5082 SetLastError(0xdeadbeef);
5083 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
5084 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5085 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5086 expect_menu(hwnd, 1);
5087 expect_style(hwnd, WS_CHILD);
5088 expect_ex_style(hwnd, 0);
5089 DestroyWindow(hwnd);
5090
5091 SetLastError(0xdeadbeef);
5092 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
5093 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5094 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5095 expect_menu(hwnd, 1);
5096 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5097 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5098 DestroyWindow(hwnd);
5099
5100 /* WS_POPUP */
5101 SetLastError(0xdeadbeef);
5102 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5103 0, 0, 100, 100, parent, hmenu, 0, NULL);
5104 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5105 expect_menu(hwnd, hmenu);
5106 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5107 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5108 DestroyWindow(hwnd);
5109 SetLastError(0xdeadbeef);
5110 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5111 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5112
5113 hmenu = CreateMenu();
5114 assert(hmenu != 0);
5115 SetLastError(0xdeadbeef);
5116 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5117 0, 0, 100, 100, parent, hmenu, 0, NULL);
5118 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5119 expect_menu(hwnd, hmenu);
5120 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5121 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5122 DestroyWindow(hwnd);
5123 SetLastError(0xdeadbeef);
5124 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5125 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5126
5127 hmenu = CreateMenu();
5128 assert(hmenu != 0);
5129 SetLastError(0xdeadbeef);
5130 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
5131 0, 0, 100, 100, parent, hmenu, 0, NULL);
5132 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5133 expect_menu(hwnd, hmenu);
5134 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5135 expect_ex_style(hwnd, 0);
5136 DestroyWindow(hwnd);
5137 SetLastError(0xdeadbeef);
5138 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5139 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5140
5141 hmenu = CreateMenu();
5142 assert(hmenu != 0);
5143 SetLastError(0xdeadbeef);
5144 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
5145 0, 0, 100, 100, parent, hmenu, 0, NULL);
5146 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5147 expect_menu(hwnd, hmenu);
5148 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5149 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5150 DestroyWindow(hwnd);
5151 SetLastError(0xdeadbeef);
5152 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5153 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5154
5155 /* WS_CHILD | WS_POPUP */
5156 SetLastError(0xdeadbeef);
5157 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5158 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5159 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5160 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5161 if (hwnd)
5162 DestroyWindow(hwnd);
5163
5164 hmenu = CreateMenu();
5165 assert(hmenu != 0);
5166 SetLastError(0xdeadbeef);
5167 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5168 0, 0, 100, 100, parent, hmenu, 0, NULL);
5169 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5170 expect_menu(hwnd, hmenu);
5171 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5172 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5173 DestroyWindow(hwnd);
5174 SetLastError(0xdeadbeef);
5175 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5176 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5177
5178 SetLastError(0xdeadbeef);
5179 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5180 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5181 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5182 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5183 if (hwnd)
5184 DestroyWindow(hwnd);
5185
5186 hmenu = CreateMenu();
5187 assert(hmenu != 0);
5188 SetLastError(0xdeadbeef);
5189 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5190 0, 0, 100, 100, parent, hmenu, 0, NULL);
5191 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5192 expect_menu(hwnd, hmenu);
5193 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5194 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5195 DestroyWindow(hwnd);
5196 SetLastError(0xdeadbeef);
5197 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5198 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5199
5200 SetLastError(0xdeadbeef);
5201 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
5202 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5203 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5204 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5205 if (hwnd)
5206 DestroyWindow(hwnd);
5207
5208 hmenu = CreateMenu();
5209 assert(hmenu != 0);
5210 SetLastError(0xdeadbeef);
5211 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
5212 0, 0, 100, 100, parent, hmenu, 0, NULL);
5213 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5214 expect_menu(hwnd, hmenu);
5215 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5216 expect_ex_style(hwnd, 0);
5217 DestroyWindow(hwnd);
5218 SetLastError(0xdeadbeef);
5219 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5220 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5221
5222 SetLastError(0xdeadbeef);
5223 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5224 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5225 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5226 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5227 if (hwnd)
5228 DestroyWindow(hwnd);
5229
5230 hmenu = CreateMenu();
5231 assert(hmenu != 0);
5232 SetLastError(0xdeadbeef);
5233 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5234 0, 0, 100, 100, parent, hmenu, 0, NULL);
5235 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5236 expect_menu(hwnd, hmenu);
5237 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5238 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5239 DestroyWindow(hwnd);
5240 SetLastError(0xdeadbeef);
5241 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5242 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5243
5244 /* test child window sizing */
5245 cls.style = 0;
5246 cls.lpfnWndProc = minmax_wnd_proc;
5247 cls.cbClsExtra = 0;
5248 cls.cbWndExtra = 0;
5249 cls.hInstance = GetModuleHandle(0);
5250 cls.hIcon = 0;
5251 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5252 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5253 cls.lpszMenuName = NULL;
5254 cls.lpszClassName = "MinMax_WndClass";
5255 RegisterClass(&cls);
5256
5257 SetLastError(0xdeadbeef);
5258 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5259 0, 0, 100, 100, 0, 0, 0, NULL);
5260 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5261 expect_menu(parent, 0);
5262 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
5263 expect_ex_style(parent, WS_EX_WINDOWEDGE);
5264
5265 memset(&minmax, 0, sizeof(minmax));
5266 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5267 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
5268 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
5269 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5270 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
5271
5272 GetWindowRect(parent, &rc);
5273 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
5274 GetClientRect(parent, &rc);
5275 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
5276
5277 InflateRect(&rc, 200, 200);
5278 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5279
5280 SetLastError(0xdeadbeef);
5281 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5282 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
5283 parent, (HMENU)1, 0, NULL);
5284 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5285 expect_menu(hwnd, 1);
5286 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
5287 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5288
5289 memset(&minmax, 0, sizeof(minmax));
5290 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5291 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5292
5293 GetWindowRect(hwnd, &rc);
5294 OffsetRect(&rc, -rc.left, -rc.top);
5295 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5296 rc.left, rc.top, rc.right, rc.bottom,
5297 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
5298 DestroyWindow(hwnd);
5299
5300 cls.lpfnWndProc = winsizes_wnd_proc;
5301 cls.lpszClassName = "Sizes_WndClass";
5302 RegisterClass(&cls);
5303
5304 expected_cx = expected_cy = 200000;
5305 SetRect( &expected_rect, 0, 0, 200000, 200000 );
5306 broken_rect = expected_rect;
5307 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
5308 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5309 GetClientRect( hwnd, &rc );
5310 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
5311 "invalid rect right %u\n", rc.right );
5312 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
5313 "invalid rect bottom %u\n", rc.bottom );
5314 DestroyWindow(hwnd);
5315
5316 expected_cx = expected_cy = -10;
5317 SetRect( &expected_rect, 0, 0, 0, 0 );
5318 SetRect( &broken_rect, 0, 0, -10, -10 );
5319 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
5320 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5321 GetClientRect( hwnd, &rc );
5322 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5323 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5324 DestroyWindow(hwnd);
5325
5326 expected_cx = expected_cy = -200000;
5327 SetRect( &expected_rect, 0, 0, 0, 0 );
5328 SetRect( &broken_rect, 0, 0, -200000, -200000 );
5329 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
5330 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5331 GetClientRect( hwnd, &rc );
5332 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5333 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5334 DestroyWindow(hwnd);
5335
5336 /* we need a parent at 0,0 so that child coordinates match */
5337 DestroyWindow(parent);
5338 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
5339 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5340
5341 expected_cx = 100;
5342 expected_cy = 0x7fffffff;
5343 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
5344 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
5345 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
5346 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5347 GetClientRect( hwnd, &rc );
5348 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
5349 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
5350 "invalid rect bottom %u\n", rc.bottom );
5351 DestroyWindow(hwnd);
5352
5353 expected_cx = 0x7fffffff;
5354 expected_cy = 0x7fffffff;
5355 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
5356 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
5357 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
5358 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5359 GetClientRect( hwnd, &rc );
5360 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
5361 "invalid rect right %u\n", rc.right );
5362 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
5363 "invalid rect bottom %u\n", rc.bottom );
5364 DestroyWindow(hwnd);
5365
5366 /* top level window */
5367 expected_cx = expected_cy = 200000;
5368 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
5369 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
5370 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5371 GetClientRect( hwnd, &rc );
5372 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
5373 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
5374 DestroyWindow(hwnd);
5375
5376 if (pGetLayout && pSetLayout)
5377 {
5378 HDC hdc = GetDC( parent );
5379 pSetLayout( hdc, LAYOUT_RTL );
5380 if (pGetLayout( hdc ))
5381 {
5382 ReleaseDC( parent, hdc );
5383 DestroyWindow( parent );
5384 SetLastError( 0xdeadbeef );
5385 parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
5386 0, 0, 100, 100, 0, 0, 0, NULL);
5387 ok( parent != 0, "creation failed err %u\n", GetLastError());
5388 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5389 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5390 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5391 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
5392 DestroyWindow( hwnd );
5393 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
5394 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5395 expect_ex_style( hwnd, 0 );
5396 DestroyWindow( hwnd );
5397 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
5398 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5399 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5400 expect_ex_style( hwnd, 0 );
5401 DestroyWindow( hwnd );
5402
5403 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
5404 {
5405 DWORD layout;
5406
5407 SetLastError( 0xdeadbeef );
5408 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
5409 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
5410 SetLastError( 0xdeadbeef );
5411 res = pGetProcessDefaultLayout( &layout );
5412 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5413 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
5414 SetLastError( 0xdeadbeef );
5415 res = pSetProcessDefaultLayout( 7 );
5416 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5417 res = pGetProcessDefaultLayout( &layout );
5418 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5419 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
5420 SetLastError( 0xdeadbeef );
5421 res = pSetProcessDefaultLayout( LAYOUT_RTL );
5422 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5423 res = pGetProcessDefaultLayout( &layout );
5424 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5425 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
5426 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5427 0, 0, 100, 100, 0, 0, 0, NULL);
5428 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5429 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5430 DestroyWindow( hwnd );
5431 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5432 0, 0, 100, 100, parent, 0, 0, NULL);
5433 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5434 expect_ex_style( hwnd, WS_EX_APPWINDOW );
5435 DestroyWindow( hwnd );
5436 pSetProcessDefaultLayout( 0 );
5437 }
5438 else win_skip( "SetProcessDefaultLayout not supported\n" );
5439 }
5440 else win_skip( "SetLayout not supported\n" );
5441 }
5442 else win_skip( "SetLayout not available\n" );
5443
5444 DestroyWindow(parent);
5445
5446 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
5447 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
5448
5449 #undef expect_gle_broken_9x
5450 #undef expect_menu
5451 #undef expect_style
5452 #undef expect_ex_style
5453 }
5454
5455 /* function that remembers whether the system the test is running on sets the
5456 * last error for user32 functions to make the tests stricter */
5457 static int check_error(DWORD actual, DWORD expected)
5458 {
5459 static int sets_last_error = -1;
5460 if (sets_last_error == -1)
5461 sets_last_error = (actual != 0xdeadbeef);
5462 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
5463 }
5464
5465 static void test_SetWindowLong(void)
5466 {
5467 LONG_PTR retval;
5468 WNDPROC old_window_procW;
5469
5470 SetLastError(0xdeadbeef);
5471 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
5472 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
5473 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
5474 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5475
5476 SetLastError(0xdeadbeef);
5477 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
5478 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
5479 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
5480 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5481
5482 SetLastError(0xdeadbeef);
5483 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
5484 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
5485 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
5486 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5487 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
5488 ok((WNDPROC)retval == main_window_procA,
5489 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5490 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
5491
5492 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
5493 SetLastError(0xdeadbeef);
5494 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
5495 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
5496 {
5497 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5498 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
5499 ok((WNDPROC)retval == old_window_procW,
5500 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5501 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5502
5503 /* set it back to ANSI */
5504 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
5505 }
5506 }
5507
5508 static void test_ShowWindow(void)
5509 {
5510 HWND hwnd;
5511 DWORD style;
5512 RECT rcMain, rc, rcMinimized;
5513 LPARAM ret;
5514
5515 SetRect(&rcMain, 120, 120, 210, 210);
5516
5517 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
5518 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5519 WS_MAXIMIZEBOX | WS_POPUP,
5520 rcMain.left, rcMain.top,
5521 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5522 0, 0, 0, NULL);
5523 assert(hwnd);
5524
5525 style = GetWindowLong(hwnd, GWL_STYLE);
5526 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5527 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5528 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5529 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5530 GetWindowRect(hwnd, &rc);
5531 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5532 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5533 rc.left, rc.top, rc.right, rc.bottom);
5534
5535 ret = ShowWindow(hwnd, SW_SHOW);
5536 ok(!ret, "not expected ret: %lu\n", ret);
5537 style = GetWindowLong(hwnd, GWL_STYLE);
5538 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5539 ok(style & WS_VISIBLE, "window should be visible\n");
5540 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5541 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5542 GetWindowRect(hwnd, &rc);
5543 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5544 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5545 rc.left, rc.top, rc.right, rc.bottom);
5546
5547 ret = ShowWindow(hwnd, SW_MINIMIZE);
5548 ok(ret, "not expected ret: %lu\n", ret);
5549 style = GetWindowLong(hwnd, GWL_STYLE);
5550 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5551 ok(style & WS_VISIBLE, "window should be visible\n");
5552 ok(style & WS_MINIMIZE, "window should be minimized\n");
5553 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5554 GetWindowRect(hwnd, &rcMinimized);
5555 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5556 /* shouldn't be able to resize minimized windows */
5557 ret = SetWindowPos(hwnd, 0, 0, 0,
5558 (rcMinimized.right - rcMinimized.left) * 2,
5559 (rcMinimized.bottom - rcMinimized.top) * 2,
5560 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5561 ok(ret, "not expected ret: %lu\n", ret);
5562 GetWindowRect(hwnd, &rc);
5563 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5564
5565 ShowWindow(hwnd, SW_RESTORE);
5566 ok(ret, "not expected ret: %lu\n", ret);
5567 style = GetWindowLong(hwnd, GWL_STYLE);
5568 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5569 ok(style & WS_VISIBLE, "window should be visible\n");
5570 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5571 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5572 GetWindowRect(hwnd, &rc);
5573 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5574 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5575 rc.left, rc.top, rc.right, rc.bottom);
5576
5577 ret = EnableWindow(hwnd, FALSE);
5578 ok(!ret, "not expected ret: %lu\n", ret);
5579 style = GetWindowLong(hwnd, GWL_STYLE);
5580 ok(style & WS_DISABLED, "window should be disabled\n");
5581
5582 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5583 ok(!ret, "not expected ret: %lu\n", ret);
5584 style = GetWindowLong(hwnd, GWL_STYLE);
5585 ok(style & WS_DISABLED, "window should be disabled\n");
5586 ok(style & WS_VISIBLE, "window should be visible\n");
5587 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5588 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5589 GetWindowRect(hwnd, &rc);
5590 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5591 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5592 rc.left, rc.top, rc.right, rc.bottom);
5593
5594 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5595 ok(!ret, "not expected ret: %lu\n", ret);
5596 style = GetWindowLong(hwnd, GWL_STYLE);
5597 ok(style & WS_DISABLED, "window should be disabled\n");
5598 ok(style & WS_VISIBLE, "window should be visible\n");
5599 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5600 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5601 GetWindowRect(hwnd, &rc);
5602 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5603 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5604 rc.left, rc.top, rc.right, rc.bottom);
5605
5606 ret = ShowWindow(hwnd, SW_MINIMIZE);
5607 ok(ret, "not expected ret: %lu\n", ret);
5608 style = GetWindowLong(hwnd, GWL_STYLE);
5609 ok(style & WS_DISABLED, "window should be disabled\n");
5610 ok(style & WS_VISIBLE, "window should be visible\n");
5611 ok(style & WS_MINIMIZE, "window should be minimized\n");
5612 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5613 GetWindowRect(hwnd, &rc);
5614 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5615
5616 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5617 ok(!ret, "not expected ret: %lu\n", ret);
5618 style = GetWindowLong(hwnd, GWL_STYLE);
5619 ok(style & WS_DISABLED, "window should be disabled\n");
5620 ok(style & WS_VISIBLE, "window should be visible\n");
5621 ok(style & WS_MINIMIZE, "window should be minimized\n");
5622 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5623 GetWindowRect(hwnd, &rc);
5624 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5625
5626 ret = ShowWindow(hwnd, SW_RESTORE);
5627 ok(ret, "not expected ret: %lu\n", ret);
5628 style = GetWindowLong(hwnd, GWL_STYLE);
5629 ok(style & WS_DISABLED, "window should be disabled\n");
5630 ok(style & WS_VISIBLE, "window should be visible\n");
5631 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5632 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5633 GetWindowRect(hwnd, &rc);
5634 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5635 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5636 rc.left, rc.top, rc.right, rc.bottom);
5637
5638 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5639 ok(!ret, "not expected ret: %lu\n", ret);
5640 ok(IsWindow(hwnd), "window should exist\n");
5641
5642 ret = EnableWindow(hwnd, TRUE);
5643 ok(ret, "not expected ret: %lu\n", ret);
5644
5645 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5646 ok(!ret, "not expected ret: %lu\n", ret);
5647 ok(!IsWindow(hwnd), "window should not exist\n");
5648 }
5649
5650 static void test_gettext(void)
5651 {
5652 WNDCLASS cls;
5653 LPCSTR clsname = "gettexttest";
5654 HWND hwnd;
5655 LRESULT r;
5656
5657 memset( &cls, 0, sizeof cls );
5658 cls.lpfnWndProc = DefWindowProc;
5659 cls.lpszClassName = clsname;
5660 cls.hInstance = GetModuleHandle(NULL);
5661
5662 if (!RegisterClass( &cls )) return;
5663
5664 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
5665 ok( hwnd != NULL, "window was null\n");
5666
5667 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
5668 ok( r == 0, "settext should return zero\n");
5669
5670 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
5671 ok( r == 0, "settext should return zero (%ld)\n", r);
5672
5673 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5674 ok( r == 0, "settext should return zero (%ld)\n", r);
5675
5676 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5677 ok( r == 0, "settext should return zero (%ld)\n", r);
5678
5679 DestroyWindow(hwnd);
5680 UnregisterClass( clsname, NULL );
5681 }
5682
5683
5684 static void test_GetUpdateRect(void)
5685 {
5686 MSG msg;
5687 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5688 RECT rc1, rc2;
5689 HWND hgrandparent, hparent, hchild;
5690 WNDCLASSA cls;
5691 static const char classNameA[] = "GetUpdateRectClass";
5692
5693 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5694 0, 0, 100, 100, NULL, NULL, 0, NULL);
5695
5696 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5697 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5698
5699 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5700 10, 10, 30, 30, hparent, NULL, 0, NULL);
5701
5702 ShowWindow(hgrandparent, SW_SHOW);
5703 UpdateWindow(hgrandparent);
5704 flush_events( TRUE );
5705
5706 ShowWindow(hchild, SW_HIDE);
5707 SetRect(&rc2, 0, 0, 0, 0);
5708 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5709 ok(!ret, "GetUpdateRect returned not empty region\n");
5710 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5711 rc1.left, rc1.top, rc1.right, rc1.bottom,
5712 rc2.left, rc2.top, rc2.right, rc2.bottom);
5713
5714 SetRect(&rc2, 10, 10, 40, 40);
5715 ret = GetUpdateRect(hparent, &rc1, FALSE);
5716 ok(ret, "GetUpdateRect returned empty region\n");
5717 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5718 rc1.left, rc1.top, rc1.right, rc1.bottom,
5719 rc2.left, rc2.top, rc2.right, rc2.bottom);
5720
5721 parent_wm_paint = FALSE;
5722 grandparent_wm_paint = FALSE;
5723 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5724 {
5725 if (msg.message == WM_PAINT)
5726 {
5727 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5728 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5729 }
5730 DispatchMessage(&msg);
5731 }
5732 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5733 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5734
5735 DestroyWindow(hgrandparent);
5736
5737 cls.style = 0;
5738 cls.lpfnWndProc = DefWindowProcA;
5739 cls.cbClsExtra = 0;
5740 cls.cbWndExtra = 0;
5741 cls.hInstance = GetModuleHandleA(0);
5742 cls.hIcon = 0;
5743 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5744 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5745 cls.lpszMenuName = NULL;
5746 cls.lpszClassName = classNameA;
5747
5748 if(!RegisterClassA(&cls)) {
5749 trace("Register failed %d\n", GetLastError());
5750 return;
5751 }
5752
5753 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5754 0, 0, 100, 100, NULL, NULL, 0, NULL);
5755
5756 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5757 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5758
5759 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5760 10, 10, 30, 30, hparent, NULL, 0, NULL);
5761
5762 ShowWindow(hgrandparent, SW_SHOW);
5763 UpdateWindow(hgrandparent);
5764 flush_events( TRUE );
5765
5766 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5767 ok(!ret, "GetUpdateRect returned not empty region\n");
5768
5769 ShowWindow(hchild, SW_HIDE);
5770
5771 SetRect(&rc2, 0, 0, 0, 0);
5772 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5773 ok(!ret, "GetUpdateRect returned not empty region\n");
5774 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5775 rc1.left, rc1.top, rc1.right, rc1.bottom,
5776 rc2.left, rc2.top, rc2.right, rc2.bottom);
5777
5778 SetRect(&rc2, 10, 10, 40, 40);
5779 ret = GetUpdateRect(hparent, &rc1, FALSE);
5780 ok(ret, "GetUpdateRect returned empty region\n");
5781 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5782 rc1.left, rc1.top, rc1.right, rc1.bottom,
5783 rc2.left, rc2.top, rc2.right, rc2.bottom);
5784
5785 parent_wm_paint = FALSE;
5786 grandparent_wm_paint = FALSE;
5787 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
5788 {
5789 if (msg.message == WM_PAINT)
5790 {
5791 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5792 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5793 }
5794 DispatchMessage(&msg);
5795 }
5796 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5797 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5798
5799 DestroyWindow(hgrandparent);
5800 }
5801
5802
5803 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5804 {
5805 if(msg == WM_PAINT)
5806 {
5807 PAINTSTRUCT ps;
5808 RECT updateRect;
5809 DWORD waitResult;
5810 HWND win;
5811 const int waitTime = 2000;
5812
5813 BeginPaint(hwnd, &ps);
5814
5815 /* create and destroy window to create an exposed region on this window */
5816 win = CreateWindowA("static", "win", WS_VISIBLE,
5817 10,10,50,50, NULL, NULL, 0, NULL);
5818 DestroyWindow(win);
5819
5820 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5821
5822 ValidateRect(hwnd, NULL);
5823 EndPaint(hwnd, &ps);
5824
5825 if(waitResult != WAIT_TIMEOUT)
5826 {
5827 GetUpdateRect(hwnd, &updateRect, FALSE);
5828 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5829 }
5830
5831 return 1;
5832 }
5833 return DefWindowProc(hwnd, msg, wParam, lParam);
5834 }
5835
5836 static void test_Expose(void)
5837 {
5838 WNDCLASSA cls;
5839 HWND mw;
5840
5841 memset(&cls, 0, sizeof(WNDCLASSA));
5842 cls.lpfnWndProc = TestExposedRegion_WndProc;
5843 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5844 cls.lpszClassName = "TestExposeClass";
5845 RegisterClassA(&cls);
5846
5847 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
5848 0, 0, 200, 100, NULL, NULL, 0, NULL);
5849
5850 UpdateWindow(mw);
5851 DestroyWindow(mw);
5852 }
5853
5854 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5855 {
5856 static UINT ncredrawflags;
5857 PAINTSTRUCT ps;
5858
5859 switch(msg)
5860 {
5861 case WM_CREATE:
5862 ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
5863 return 0;
5864 case WM_NCPAINT:
5865 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
5866 break;
5867 case WM_PAINT:
5868 BeginPaint(hwnd, &ps);
5869 EndPaint(hwnd, &ps);
5870 return 0;
5871 }
5872 return DefWindowProc(hwnd, msg, wParam, lParam);
5873 }
5874
5875 static void run_NCRedrawLoop(UINT flags)
5876 {
5877 HWND hwnd;
5878 MSG msg;
5879
5880 UINT loopcount = 0;
5881
5882 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
5883 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
5884 NULL, NULL, 0, &flags);
5885 ShowWindow(hwnd, SW_SHOW);
5886 UpdateWindow(hwnd);
5887 flush_events( FALSE );
5888 while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
5889 {
5890 if (msg.message == WM_PAINT) loopcount++;
5891 if (loopcount >= 100) break;
5892 TranslateMessage(&msg);
5893 DispatchMessage(&msg);
5894 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
5895 }
5896 if (flags == (RDW_INVALIDATE | RDW_FRAME))
5897 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5898 else
5899 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
5900 DestroyWindow(hwnd);
5901 }
5902
5903 static void test_NCRedraw(void)
5904 {
5905 WNDCLASSA wndclass;
5906
5907 wndclass.lpszClassName = "TestNCRedrawClass";
5908 wndclass.style = CS_HREDRAW | CS_VREDRAW;
5909 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
5910 wndclass.cbClsExtra = 0;
5911 wndclass.cbWndExtra = 0;
5912 wndclass.hInstance = 0;
5913 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
5914 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
5915 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
5916 wndclass.lpszMenuName = NULL;
5917
5918 RegisterClassA(&wndclass);
5919
5920 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
5921 run_NCRedrawLoop(RDW_INVALIDATE);
5922 }
5923
5924 static void test_GetWindowModuleFileName(void)
5925 {
5926 HWND hwnd;
5927 HINSTANCE hinst;
5928 UINT ret1, ret2;
5929 char buf1[MAX_PATH], buf2[MAX_PATH];
5930
5931 if (!pGetWindowModuleFileNameA)
5932 {
5933 win_skip("GetWindowModuleFileNameA is not available\n");
5934 return;
5935 }
5936
5937 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
5938 assert(hwnd);
5939
5940 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
5941 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
5942
5943 buf1[0] = 0;
5944 SetLastError(0xdeadbeef);
5945 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
5946 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
5947
5948 buf2[0] = 0;
5949 SetLastError(0xdeadbeef);
5950 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
5951 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
5952 "GetWindowModuleFileNameA error %u\n", GetLastError());
5953
5954 if (ret2)
5955 {
5956 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
5957 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
5958 }
5959 hinst = GetModuleHandle(0);
5960
5961 SetLastError(0xdeadbeef);
5962 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
5963 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
5964 "expected %u, got %u\n", ret1 - 2, ret2);
5965 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5966 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5967 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5968
5969 SetLastError(0xdeadbeef);
5970 ret2 = GetModuleFileName(hinst, buf2, 0);
5971 ok(!ret2, "GetModuleFileName should return 0\n");
5972 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5973 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5974 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5975
5976 SetLastError(0xdeadbeef);
5977 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
5978 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
5979 "expected %u, got %u\n", ret1 - 2, ret2);
5980 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5981 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5982 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5983
5984 SetLastError(0xdeadbeef);
5985 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
5986 ok(!ret2, "expected 0, got %u\n", ret2);
5987 ok(GetLastError() == 0xdeadbeef /* XP */ ||
5988 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
5989 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
5990
5991 DestroyWindow(hwnd);
5992
5993 buf2[0] = 0;
5994 hwnd = (HWND)0xdeadbeef;
5995 SetLastError(0xdeadbeef);
5996 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
5997 ok(!ret1, "expected 0, got %u\n", ret1);
5998 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
5999 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
6000
6001 hwnd = FindWindow("Shell_TrayWnd", NULL);
6002 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
6003 SetLastError(0xdeadbeef);
6004 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6005 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
6006
6007 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
6008 {
6009 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
6010 hwnd = GetDesktopWindow();
6011 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
6012 SetLastError(0xdeadbeef);
6013 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6014 ok(!ret2 ||
6015 ret1 == ret2 || /* vista */
6016 broken(ret2), /* some win98 return user.exe as file name */
6017 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
6018 }
6019 }
6020
6021 static void test_hwnd_message(void)
6022 {
6023 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
6024 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
6025
6026 HWND parent = 0, hwnd, found;
6027 RECT rect;
6028
6029 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
6030 on CreateWindowExA and crash later in the test.
6031 Use UNICODE here to fail on win9x */
6032 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
6033 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
6034 if (!hwnd)
6035 {
6036 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
6037 return;
6038 }
6039
6040 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
6041 if (pGetAncestor)
6042 {
6043 char buffer[100];
6044 HWND root, desktop = GetDesktopWindow();
6045
6046 parent = pGetAncestor(hwnd, GA_PARENT);
6047 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
6048 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
6049 root = pGetAncestor(hwnd, GA_ROOT);
6050 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
6051 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
6052 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
6053 trace("parent %p root %p desktop %p\n", parent, root, desktop);
6054 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
6055 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
6056 GetWindowRect( parent, &rect );
6057 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
6058 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6059 }
6060 GetWindowRect( hwnd, &rect );
6061 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
6062 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6063
6064 /* test FindWindow behavior */
6065
6066 found = FindWindowExA( 0, 0, 0, "message window" );
6067 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6068 SetLastError(0xdeadbeef);
6069 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
6070 ok( found == 0, "found message window %p/%p\n", found, hwnd );
6071 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
6072 if (parent)
6073 {
6074 found = FindWindowExA( parent, 0, 0, "message window" );
6075 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6076 }
6077
6078 /* test IsChild behavior */
6079
6080 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
6081
6082 /* test IsWindowVisible behavior */
6083
6084 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
6085 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
6086
6087 DestroyWindow(hwnd);
6088 }
6089
6090 static void test_layered_window(void)
6091 {
6092 HWND hwnd;
6093 COLORREF key = 0;
6094 BYTE alpha = 0;
6095 DWORD flags = 0;
6096 POINT pt = { 0, 0 };
6097 SIZE sz = { 200, 200 };
6098 HDC hdc;
6099 HBITMAP hbm;
6100 BOOL ret;
6101
6102 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
6103 {
6104 win_skip( "layered windows not supported\n" );
6105 return;
6106 }
6107
6108 hdc = CreateCompatibleDC( 0 );
6109 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
6110 SelectObject( hdc, hbm );
6111
6112 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
6113 100, 100, 200, 200, 0, 0, 0, NULL);
6114 assert( hwnd );
6115 SetLastError( 0xdeadbeef );
6116 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6117 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6118 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6119 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6120 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6121 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
6122 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6123 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6124 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6125 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6126 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6127 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6128 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6129 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6130 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
6131 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6132 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6133 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6134 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
6135 ok( alpha == 44, "wrong alpha %u\n", alpha );
6136 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
6137 SetLastError( 0xdeadbeef );
6138 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6139 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6140 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6141
6142 /* clearing WS_EX_LAYERED resets attributes */
6143 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6144 SetLastError( 0xdeadbeef );
6145 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6146 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6147 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6148 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6149 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6150 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6151 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6152 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6153 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6154 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
6155 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
6156 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6157 if (pUpdateLayeredWindowIndirect)
6158 {
6159 UPDATELAYEREDWINDOWINFO info;
6160 info.cbSize = sizeof(info);
6161 info.hdcDst = 0;
6162 info.pptDst = NULL;
6163 info.psize = &sz;
6164 info.hdcSrc = hdc;
6165 info.pptSrc = &pt;
6166 info.crKey = 0;
6167 info.pblend = NULL;
6168 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
6169 info.prcDirty = NULL;
6170 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6171 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6172 sz.cx--;
6173 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6174 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6175 ok( GetLastError() == ERROR_INCORRECT_SIZE || broken(GetLastError() == ERROR_MR_MID_NOT_FOUND),
6176 "wrong error %u\n", GetLastError() );
6177 info.dwFlags = ULW_OPAQUE;
6178 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6179 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6180 sz.cx++;
6181 info.dwFlags = ULW_OPAQUE | 0xf00;
6182 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6183 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6184 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6185 info.cbSize--;
6186 info.dwFlags = ULW_OPAQUE;
6187 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6188 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6189 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6190 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
6191 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6192 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6193 }
6194
6195 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
6196 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6197 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6198 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6199 ok( key == 0x654321, "wrong color key %x\n", key );
6200 ok( alpha == 22, "wrong alpha %u\n", alpha );
6201 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
6202 SetLastError( 0xdeadbeef );
6203 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6204 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6205 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6206
6207 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
6208 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6209 alpha = 0;
6210 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6211 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6212 ok( key == 0x888888, "wrong color key %x\n", key );
6213 /* alpha not changed on vista if LWA_ALPHA is not set */
6214 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
6215 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
6216
6217 /* color key may or may not be changed without LWA_COLORKEY */
6218 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
6219 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6220 alpha = 0;
6221 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6222 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6223 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
6224 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
6225 ok( flags == 0, "wrong flags %x\n", flags );
6226
6227 /* default alpha and color key is 0 */
6228 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6229 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6230 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
6231 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6232 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6233 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6234 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
6235 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
6236 ok( flags == 0, "wrong flags %x\n", flags );
6237
6238 DestroyWindow( hwnd );
6239 DeleteDC( hdc );
6240 DeleteObject( hbm );
6241 }
6242
6243 static MONITORINFO mi;
6244
6245 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6246 {
6247 switch (msg)
6248 {
6249 case WM_NCCREATE:
6250 {
6251 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
6252 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
6253 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
6254 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
6255 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6256 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6257 cs->x, cs->y, cs->cx, cs->cy);
6258 break;
6259 }
6260 case WM_GETMINMAXINFO:
6261 {
6262 MINMAXINFO *minmax = (MINMAXINFO *)lp;
6263 dump_minmax_info(minmax);
6264 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
6265 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
6266 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
6267 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
6268 break;
6269 }
6270 }
6271 return DefWindowProc(hwnd, msg, wp, lp);
6272 }
6273
6274 static void test_fullscreen(void)
6275 {
6276 static const DWORD t_style[] = {
6277 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
6278 };
6279 static const DWORD t_ex_style[] = {
6280 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
6281 };
6282 WNDCLASS cls;
6283 HWND hwnd;
6284 int i, j;
6285 POINT pt;
6286 RECT rc;
6287 HMONITOR hmon;
6288 LRESULT ret;
6289
6290 if (!pGetMonitorInfoA || !pMonitorFromPoint)
6291 {
6292 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6293 return;
6294 }
6295
6296 pt.x = pt.y = 0;
6297 SetLastError(0xdeadbeef);
6298 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
6299 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
6300
6301 mi.cbSize = sizeof(mi);
6302 SetLastError(0xdeadbeef);
6303 ret = pGetMonitorInfoA(hmon, &mi);
6304 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
6305 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6306 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6307 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6308
6309 cls.style = 0;
6310 cls.lpfnWndProc = fullscreen_wnd_proc;
6311 cls.cbClsExtra = 0;
6312 cls.cbWndExtra = 0;
6313 cls.hInstance = GetModuleHandle(0);
6314 cls.hIcon = 0;
6315 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6316 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6317 cls.lpszMenuName = NULL;
6318 cls.lpszClassName = "fullscreen_class";
6319 RegisterClass(&cls);
6320
6321 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
6322 {
6323 DWORD style, ex_style;
6324
6325 /* avoid a WM interaction */
6326 assert(!(t_style[i] & WS_VISIBLE));
6327
6328 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
6329 {
6330 int fixup;
6331
6332 style = t_style[i];
6333 ex_style = t_ex_style[j];
6334
6335 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6336 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6337 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6338 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6339 GetWindowRect(hwnd, &rc);
6340 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6341 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6342 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6343 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6344 DestroyWindow(hwnd);
6345
6346 style = t_style[i] | WS_MAXIMIZE;
6347 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6348 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6349 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6350 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6351 GetWindowRect(hwnd, &rc);
6352 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6353 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6354 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6355 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6356 DestroyWindow(hwnd);
6357
6358 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
6359 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6360 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6361 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6362 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6363 GetWindowRect(hwnd, &rc);
6364 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6365 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6366 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6367 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6368 DestroyWindow(hwnd);
6369
6370 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
6371 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6372 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6373 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6374 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6375 GetWindowRect(hwnd, &rc);
6376 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6377 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6378 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6379 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6380 DestroyWindow(hwnd);
6381
6382 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
6383 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6384 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6385 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6386 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6387 GetWindowRect(hwnd, &rc);
6388 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6389 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6390 fixup = min(abs(rc.left), abs(rc.top));
6391 InflateRect(&rc, -fixup, -fixup);
6392 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6393 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6394 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6395 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
6396 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6397 DestroyWindow(hwnd);
6398
6399 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
6400 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6401 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6402 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
6403 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6404 GetWindowRect(hwnd, &rc);
6405 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6406 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6407 fixup = min(abs(rc.left), abs(rc.top));
6408 InflateRect(&rc, -fixup, -fixup);
6409 if (style & (WS_CHILD | WS_POPUP))
6410 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6411 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6412 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6413 else
6414 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6415 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6416 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6417 DestroyWindow(hwnd);
6418 }
6419 }
6420
6421 UnregisterClass("fullscreen_class", GetModuleHandle(0));
6422 }
6423
6424 static BOOL test_thick_child_got_minmax;
6425 static const char * test_thick_child_name;
6426 static LONG test_thick_child_style;
6427 static LONG test_thick_child_exStyle;
6428
6429 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
6430 {
6431 MINMAXINFO* minmax;
6432 int expectedMinTrackX;
6433 int expectedMinTrackY;
6434 int actualMinTrackX;
6435 int actualMinTrackY;
6436 int expectedMaxTrackX;
6437 int expectedMaxTrackY;
6438 int actualMaxTrackX;
6439 int actualMaxTrackY;
6440 int expectedMaxSizeX;
6441 int expectedMaxSizeY;
6442 int actualMaxSizeX;
6443 int actualMaxSizeY;
6444 int expectedPosX;
6445 int expectedPosY;
6446 int actualPosX;
6447 int actualPosY;
6448 LONG adjustedStyle;
6449 RECT rect;
6450 switch (msg)
6451 {
6452 case WM_GETMINMAXINFO:
6453 {
6454 minmax = (MINMAXINFO *)lparam;
6455 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
6456 dump_minmax_info( minmax );
6457
6458 test_thick_child_got_minmax = TRUE;
6459
6460
6461 adjustedStyle = test_thick_child_style;
6462 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6463 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6464 GetClientRect(GetParent(hwnd), &rect);
6465 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
6466
6467 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6468 {
6469 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
6470 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
6471 }
6472 else
6473 {
6474 expectedMinTrackX = -2 * rect.left;
6475 expectedMinTrackY = -2 * rect.top;
6476 }
6477 actualMinTrackX = minmax->ptMinTrackSize.x;
6478 actualMinTrackY = minmax->ptMinTrackSize.y;
6479
6480 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
6481 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6482 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
6483 test_thick_child_name);
6484
6485 actualMaxTrackX = minmax->ptMaxTrackSize.x;
6486 actualMaxTrackY = minmax->ptMaxTrackSize.y;
6487 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
6488 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
6489 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
6490 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6491 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
6492 test_thick_child_name);
6493
6494 expectedMaxSizeX = rect.right - rect.left;
6495 expectedMaxSizeY = rect.bottom - rect.top;
6496 actualMaxSizeX = minmax->ptMaxSize.x;
6497 actualMaxSizeY = minmax->ptMaxSize.y;
6498
6499 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
6500 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6501 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
6502 test_thick_child_name);
6503
6504
6505 expectedPosX = rect.left;
6506 expectedPosY = rect.top;
6507 actualPosX = minmax->ptMaxPosition.x;
6508 actualPosY = minmax->ptMaxPosition.y;
6509 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
6510 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6511 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
6512
6513 break;
6514 }
6515 }
6516
6517 return DefWindowProcA(hwnd, msg, wparam, lparam);
6518 }
6519
6520 #define NUMBER_OF_THICK_CHILD_TESTS 16
6521 static void test_thick_child_size(HWND parentWindow)
6522 {
6523 BOOL success;
6524 RECT childRect;
6525 RECT adjustedParentRect;
6526 HWND childWindow;
6527 LONG childWidth;
6528 LONG childHeight;
6529 LONG expectedWidth;
6530 LONG expectedHeight;
6531 WNDCLASSA cls;
6532 LPCTSTR className = "THICK_CHILD_CLASS";
6533 int i;
6534 LONG adjustedStyle;
6535 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
6536 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6537 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6538 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6539 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6540 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6541 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6542 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6543 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6544 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6545 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6546 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6547 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6548 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6549 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6550 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6551 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6552 };
6553
6554 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6555 0,
6556 0,
6557 0,
6558 0,
6559 WS_EX_DLGMODALFRAME,
6560 WS_EX_DLGMODALFRAME,
6561 WS_EX_DLGMODALFRAME,
6562 WS_EX_DLGMODALFRAME,
6563 WS_EX_STATICEDGE,
6564 WS_EX_STATICEDGE,
6565 WS_EX_STATICEDGE,
6566 WS_EX_STATICEDGE,
6567 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6568 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6569 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6570 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6571 };
6572 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6573 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6574 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6575 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6576 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6577 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6578 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6579 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6580 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6581 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6582 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6583 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6584 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6585 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6586 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6587 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6588 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6589 };
6590
6591 cls.style = 0;
6592 cls.lpfnWndProc = test_thick_child_size_winproc;
6593 cls.cbClsExtra = 0;
6594 cls.cbWndExtra = 0;
6595 cls.hInstance = GetModuleHandleA(0);
6596 cls.hIcon = 0;
6597 cls.hCursor = LoadCursorA(0, IDC_ARROW);
6598 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6599 cls.lpszMenuName = NULL;
6600 cls.lpszClassName = className;
6601 SetLastError(0xdeadbeef);
6602 success = RegisterClassA(&cls);
6603 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6604
6605 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6606 {
6607 test_thick_child_name = styleName[i];
6608 test_thick_child_style = styles[i];
6609 test_thick_child_exStyle = exStyles[i];
6610 test_thick_child_got_minmax = FALSE;
6611
6612 SetLastError(0xdeadbeef);
6613 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6614 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6615
6616 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6617
6618 SetLastError(0xdeadbeef);
6619 success = GetWindowRect(childWindow, &childRect);
6620 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6621 childWidth = childRect.right - childRect.left;
6622 childHeight = childRect.bottom - childRect.top;
6623
6624 adjustedStyle = styles[i];
6625 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6626 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6627 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6628 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6629
6630
6631 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6632 {
6633 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6634 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6635 }
6636 else
6637 {
6638 expectedWidth = -2 * adjustedParentRect.left;
6639 expectedHeight = -2 * adjustedParentRect.top;
6640 }
6641
6642 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6643 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6644 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6645
6646 SetLastError(0xdeadbeef);
6647 success = DestroyWindow(childWindow);
6648 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6649 }
6650 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
6651 }
6652
6653 static void test_handles( HWND full_hwnd )
6654 {
6655 HWND hwnd = full_hwnd;
6656 BOOL ret;
6657 RECT rect;
6658
6659 SetLastError( 0xdeadbeef );
6660 ret = GetWindowRect( hwnd, &rect );
6661 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6662
6663 #ifdef _WIN64
6664 if ((ULONG_PTR)full_hwnd >> 32)
6665 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6666 else
6667 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6668 SetLastError( 0xdeadbeef );
6669 ret = GetWindowRect( hwnd, &rect );
6670 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6671
6672 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6673 SetLastError( 0xdeadbeef );
6674 ret = GetWindowRect( hwnd, &rect );
6675 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6676
6677 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6678 SetLastError( 0xdeadbeef );
6679 ret = GetWindowRect( hwnd, &rect );
6680 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6681 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6682
6683 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6684 SetLastError( 0xdeadbeef );
6685 ret = GetWindowRect( hwnd, &rect );
6686 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6687 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6688 #endif
6689 }
6690
6691 static void test_winregion(void)
6692 {
6693 HWND hwnd;
6694 RECT r;
6695 int ret, width;
6696 HRGN hrgn;
6697
6698 if (!pGetWindowRgnBox)
6699 {
6700 win_skip("GetWindowRgnBox not supported\n");
6701 return;
6702 }
6703
6704 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6705 /* NULL prect */
6706 SetLastError(0xdeadbeef);
6707 ret = pGetWindowRgnBox(hwnd, NULL);
6708 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6709 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6710
6711 hrgn = CreateRectRgn(2, 3, 10, 15);
6712 ok( hrgn != NULL, "Region creation failed\n");
6713 if (hrgn)
6714 {
6715 SetWindowRgn(hwnd, hrgn, FALSE);
6716
6717 SetLastError(0xdeadbeef);
6718 ret = pGetWindowRgnBox(hwnd, NULL);
6719 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6720 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6721
6722 r.left = r.top = r.right = r.bottom = 0;
6723 ret = pGetWindowRgnBox(hwnd, &r);
6724 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6725 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6726 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6727 r.right, r.bottom);
6728 if (pMirrorRgn)
6729 {
6730 hrgn = CreateRectRgn(2, 3, 10, 15);
6731 ret = pMirrorRgn( hwnd, hrgn );
6732 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6733 r.left = r.top = r.right = r.bottom = 0;
6734 GetWindowRect( hwnd, &r );
6735 width = r.right - r.left;
6736 r.left = r.top = r.right = r.bottom = 0;
6737 ret = GetRgnBox( hrgn, &r );
6738 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
6739 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
6740 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
6741 }
6742 else win_skip( "MirrorRgn not supported\n" );
6743 }
6744 DestroyWindow(hwnd);
6745 }
6746
6747 static void test_rtl_layout(void)
6748 {
6749 HWND parent, child;
6750 RECT r;
6751 POINT pt;
6752
6753 if (!pSetProcessDefaultLayout)
6754 {
6755 win_skip( "SetProcessDefaultLayout not supported\n" );
6756 return;
6757 }
6758
6759 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
6760 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
6761
6762 GetWindowRect( parent, &r );
6763 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6764 GetClientRect( parent, &r );
6765 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6766 GetClientRect( child, &r );
6767 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6768 MapWindowPoints( child, parent, (POINT *)&r, 2 );
6769 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6770 GetWindowRect( child, &r );
6771 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6772 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6773 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6774 GetWindowRect( child, &r );
6775 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
6776 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
6777 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6778 pt.x = pt.y = 12;
6779 MapWindowPoints( child, parent, &pt, 1 );
6780 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
6781 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6782 GetWindowRect( parent, &r );
6783 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6784 GetWindowRect( child, &r );
6785 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6786 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
6787 GetWindowRect( child, &r );
6788 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6789 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6790 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6791 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
6792 GetWindowRect( child, &r );
6793 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6794 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6795 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6796 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6797 GetWindowRect( child, &r );
6798 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6799 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6800 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6801 DestroyWindow( child );
6802 DestroyWindow( parent );
6803 }
6804
6805 static void test_FlashWindowEx(void)
6806 {
6807 HWND hwnd;
6808 FLASHWINFO finfo;
6809 BOOL prev, ret;
6810
6811 if (!pFlashWindowEx)
6812 {
6813 win_skip( "FlashWindowEx not supported\n" );
6814 return;
6815 }
6816
6817 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
6818 0, 0, 0, 0, 0, 0, 0, NULL );
6819 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6820
6821 finfo.cbSize = sizeof(FLASHWINFO);
6822 finfo.dwFlags = FLASHW_TIMER;
6823 finfo.uCount = 3;
6824 finfo.dwTimeout = 200;
6825 finfo.hwnd = NULL;
6826 SetLastError(0xdeadbeef);
6827 ret = pFlashWindowEx(&finfo);
6828 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6829 "FlashWindowEx returned with %d\n", GetLastError());
6830
6831 finfo.hwnd = hwnd;
6832 SetLastError(0xdeadbeef);
6833 ret = pFlashWindowEx(NULL);
6834 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6835 "FlashWindowEx returned with %d\n", GetLastError());
6836
6837 SetLastError(0xdeadbeef);
6838 ret = pFlashWindowEx(&finfo);
6839 todo_wine ok(!ret, "previous window state should not be active\n");
6840
6841 finfo.cbSize = sizeof(FLASHWINFO) - 1;
6842 SetLastError(0xdeadbeef);
6843 ret = pFlashWindowEx(&finfo);
6844 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6845 "FlashWindowEx succeeded\n");
6846
6847 finfo.cbSize = sizeof(FLASHWINFO) + 1;
6848 SetLastError(0xdeadbeef);
6849 ret = pFlashWindowEx(&finfo);
6850 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6851 "FlashWindowEx succeeded\n");
6852 finfo.cbSize = sizeof(FLASHWINFO);
6853
6854 DestroyWindow( hwnd );
6855
6856 SetLastError(0xdeadbeef);
6857 ret = pFlashWindowEx(&finfo);
6858 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6859 "FlashWindowEx returned with %d\n", GetLastError());
6860
6861 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6862 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6863 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6864 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6865 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6866
6867 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
6868 0, 0, 0, 0, 0, 0, 0, NULL );
6869 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6870 finfo.hwnd = hwnd;
6871
6872 SetLastError(0xdeadbeef);
6873 ret = pFlashWindowEx(NULL);
6874 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6875 "FlashWindowEx returned with %d\n", GetLastError());
6876
6877 SetLastError(0xdeadbeef);
6878 prev = pFlashWindowEx(&finfo);
6879
6880 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
6881 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
6882 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
6883 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
6884 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
6885
6886 finfo.dwFlags = FLASHW_STOP;
6887 SetLastError(0xdeadbeef);
6888 ret = pFlashWindowEx(&finfo);
6889 todo_wine
6890 ok(prev != ret, "previous window state should be different\n");
6891
6892 DestroyWindow( hwnd );
6893 }
6894
6895 static void test_FindWindowEx(void)
6896 {
6897 HWND hwnd, found;
6898 CHAR title[1];
6899
6900 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6901 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6902
6903 title[0] = 0;
6904
6905 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6906 ok( found == NULL, "expected a NULL hwnd\n" );
6907 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6908 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6909
6910 DestroyWindow( hwnd );
6911
6912 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
6913 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6914
6915 found = FindWindowExA( 0, 0, "MainWindowClass", title );
6916 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6917 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
6918 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
6919
6920 DestroyWindow( hwnd );
6921
6922 /* test behaviour with a window title that is an empty character */
6923 found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
6924 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6925 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
6926 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
6927 }
6928
6929 static void test_GetLastActivePopup(void)
6930 {
6931 HWND hwndOwner, hwndPopup1, hwndPopup2;
6932
6933 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
6934 WS_VISIBLE | WS_POPUPWINDOW,
6935 100, 100, 200, 200,
6936 NULL, 0, GetModuleHandle(0), NULL);
6937 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
6938 WS_VISIBLE | WS_POPUPWINDOW,
6939 100, 100, 200, 200,
6940 hwndOwner, 0, GetModuleHandle(0), NULL);
6941 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
6942 WS_VISIBLE | WS_POPUPWINDOW,
6943 100, 100, 200, 200,
6944 hwndPopup1, 0, GetModuleHandle(0), NULL);
6945 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
6946 DestroyWindow( hwndPopup2 );
6947 DestroyWindow( hwndPopup1 );
6948 DestroyWindow( hwndOwner );
6949 }
6950
6951 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6952 {
6953 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
6954 return DefWindowProc(hwnd, msg, wp, lp);
6955 }
6956
6957 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6958 {
6959 return DefWindowProc(hwnd, msg, wp, lp);
6960 }
6961
6962 static void create_window_tree(HWND parent, HWND *window, int size)
6963 {
6964 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
6965 int i, pos;
6966
6967 memset(window, 0, size * sizeof(window[0]));
6968
6969 pos = 0;
6970 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
6971 {
6972 assert(pos < size);
6973 window[pos] = CreateWindowEx(0, "my_window", NULL, style[i] | WS_CHILD,
6974 0, 0, 100, 100, parent, 0, 0, NULL);
6975 ok(window[pos] != 0, "CreateWindowEx failed\n");
6976 pos++;
6977 assert(pos < size);
6978 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
6979 0, 0, 100, 100, parent, 0, 0, NULL);
6980 ok(window[pos] != 0, "CreateWindowEx failed\n");
6981 pos++;
6982
6983 assert(pos < size);
6984 window[pos] = CreateWindowEx(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
6985 0, 0, 100, 100, parent, 0, 0, NULL);
6986 ok(window[pos] != 0, "CreateWindowEx failed\n");
6987 pos++;
6988 assert(pos < size);
6989 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
6990 0, 0, 100, 100, parent, 0, 0, NULL);
6991 ok(window[pos] != 0, "CreateWindowEx failed\n");
6992 pos++;
6993
6994 assert(pos < size);
6995 window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
6996 0, 0, 100, 100, parent, 0, 0, NULL);
6997 ok(window[pos] != 0, "CreateWindowEx failed\n");
6998 pos++;
6999 assert(pos < size);
7000 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7001 0, 0, 100, 100, parent, 0, 0, NULL);
7002 ok(window[pos] != 0, "CreateWindowEx failed\n");
7003 pos++;
7004 assert(pos < size);
7005 window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7006 0, 0, 100, 100, parent, 0, 0, NULL);
7007 ok(window[pos] != 0, "CreateWindowEx failed\n");
7008 pos++;
7009 assert(pos < size);
7010 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7011 0, 0, 100, 100, parent, 0, 0, NULL);
7012 ok(window[pos] != 0, "CreateWindowEx failed\n");
7013 pos++;
7014
7015 assert(pos < size);
7016 window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7017 0, 0, 100, 100, parent, 0, 0, NULL);
7018 ok(window[pos] != 0, "CreateWindowEx failed\n");
7019 pos++;
7020 assert(pos < size);
7021 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7022 0, 0, 100, 100, parent, 0, 0, NULL);
7023 ok(window[pos] != 0, "CreateWindowEx failed\n");
7024 pos++;
7025 assert(pos < size);
7026 window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7027 0, 0, 100, 100, parent, 0, 0, NULL);
7028 ok(window[pos] != 0, "CreateWindowEx failed\n");
7029 pos++;
7030 assert(pos < size);
7031 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7032 0, 0, 100, 100, parent, 0, 0, NULL);
7033 ok(window[pos] != 0, "CreateWindowEx failed\n");
7034 pos++;
7035
7036 assert(pos < size);
7037 window[pos] = CreateWindowEx(0, "Static", NULL, style[i] | WS_CHILD,
7038 0, 0, 100, 100, parent, 0, 0, NULL);
7039 ok(window[pos] != 0, "CreateWindowEx failed\n");
7040 pos++;
7041 assert(pos < size);
7042 window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
7043 0, 0, 100, 100, parent, 0, 0, NULL);
7044 ok(window[pos] != 0, "CreateWindowEx failed\n");
7045 pos++;
7046 }
7047 }
7048
7049 struct window_attributes
7050 {
7051 char class_name[128];
7052 int is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
7053 };
7054
7055 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
7056 {
7057 DWORD style, ex_style, hittest;
7058
7059 style = GetWindowLong(hwnd, GWL_STYLE);
7060 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
7061 attrs->class_name[0] = 0;
7062 GetClassName(hwnd, attrs->class_name, sizeof(attrs->class_name));
7063 hittest = SendMessage(hwnd, WM_NCHITTEST, 0, 0);
7064
7065 attrs->is_visible = (style & WS_VISIBLE) != 0;
7066 attrs->is_enabled = (style & WS_DISABLED) == 0;
7067 attrs->is_groupbox = !lstrcmpi(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
7068 attrs->is_httransparent = hittest == HTTRANSPARENT;
7069 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
7070 }
7071
7072 static int window_to_index(HWND hwnd, HWND *window, int size)
7073 {
7074 int i;
7075
7076 for (i = 0; i < size; i++)
7077 {
7078 if (!window[i]) break;
7079 if (window[i] == hwnd) return i;
7080 }
7081 return -1;
7082 }
7083
7084 static void test_child_window_from_point(void)
7085 {
7086 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7087 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7088 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7089 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7090 WNDCLASSA cls;
7091 HWND hwnd, parent, window[100];
7092 POINT pt;
7093 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
7094 int ret, i;
7095
7096 ret = GetClassInfo(0, "Button", &cls);
7097 ok(ret, "GetClassInfo(Button) failed\n");
7098 cls.lpszClassName = "my_button";
7099 ret = RegisterClass(&cls);
7100 ok(ret, "RegisterClass(my_button) failed\n");
7101
7102 cls.lpszClassName = "my_httrasparent";
7103 cls.lpfnWndProc = my_httrasparent_proc;
7104 ret = RegisterClass(&cls);
7105 ok(ret, "RegisterClass(my_httrasparent) failed\n");
7106
7107 cls.lpszClassName = "my_window";
7108 cls.lpfnWndProc = my_window_proc;
7109 ret = RegisterClass(&cls);
7110 ok(ret, "RegisterClass(my_window) failed\n");
7111
7112 parent = CreateWindowEx(0, "MainWindowClass", NULL,
7113 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7114 100, 100, 200, 200,
7115 0, 0, GetModuleHandle(0), NULL);
7116 ok(parent != 0, "CreateWindowEx failed\n");
7117 trace("parent %p\n", parent);
7118
7119 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
7120
7121 found_invisible = 0;
7122 found_disabled = 0;
7123 found_groupbox = 0;
7124 found_httransparent = 0;
7125 found_extransparent = 0;
7126
7127 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7128 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
7129 {
7130 struct window_attributes attrs;
7131
7132 pt.x = pt.y = 50;
7133 hwnd = RealChildWindowFromPoint(parent, pt);
7134 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
7135 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
7136 /* FIXME: remove once Wine is fixed */
7137 if (ret != real_child_pos[i])
7138 todo_wine ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7139 else
7140 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7141
7142 get_window_attributes(hwnd, &attrs);
7143 if (!attrs.is_visible) found_invisible++;
7144 if (!attrs.is_enabled) found_disabled++;
7145 if (attrs.is_groupbox) found_groupbox++;
7146 if (attrs.is_httransparent) found_httransparent++;
7147 if (attrs.is_extransparent) found_extransparent++;
7148
7149 if (ret != real_child_pos[i] && ret != -1)
7150 {
7151 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7152 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7153 get_window_attributes(window[real_child_pos[i]], &attrs);
7154 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7155 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7156 }
7157 if (ret == -1)
7158 {
7159 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
7160 break;
7161 }
7162 DestroyWindow(hwnd);
7163 }
7164
7165 DestroyWindow(parent);
7166
7167 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
7168 ok(found_disabled, "found %d disabled windows\n", found_disabled);
7169 todo_wine
7170 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
7171 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
7172 todo_wine
7173 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
7174
7175 ret = UnregisterClass("my_button", cls.hInstance);
7176 ok(ret, "UnregisterClass(my_button) failed\n");
7177 ret = UnregisterClass("my_httrasparent", cls.hInstance);
7178 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
7179 ret = UnregisterClass("my_window", cls.hInstance);
7180 ok(ret, "UnregisterClass(my_window) failed\n");
7181 }
7182
7183 static void test_map_points(void)
7184 {
7185 BOOL ret;
7186 POINT p;
7187 HWND wnd, wnd0, dwnd;
7188 INT n;
7189 DWORD err;
7190 POINT pos = { 100, 200 };
7191 int width = 150;
7192 int height = 150;
7193 RECT window_rect;
7194 RECT client_rect;
7195
7196 /* Create test windows */
7197 wnd = CreateWindow("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
7198 ok(wnd != NULL, "Failed %p\n", wnd);
7199 wnd0 = CreateWindow("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
7200 ok(wnd0 != NULL, "Failed %p\n", wnd);
7201 dwnd = CreateWindow("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
7202 DestroyWindow(dwnd);
7203 ok(dwnd != NULL, "Failed %p\n", dwnd);
7204
7205 /* Verify window rect and client rect (they should have the same width and height) */
7206 GetWindowRect(wnd, &window_rect);
7207 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
7208 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
7209 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
7210 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
7211 GetClientRect(wnd, &client_rect);
7212 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
7213 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
7214 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
7215 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
7216
7217 /* Test MapWindowPoints */
7218
7219 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7220
7221 SetLastError(0xdeadbeef);
7222 n = MapWindowPoints(NULL, NULL, NULL, 0);
7223 err = GetLastError();
7224 ok(n == 0, "Got %d, expected %d\n", n, 0);
7225 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7226
7227 SetLastError(0xdeadbeef);
7228 n = MapWindowPoints(wnd, wnd, NULL, 0);
7229 err = GetLastError();
7230 ok(n == 0, "Got %d, expected %d\n", n, 0);
7231 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7232
7233 n = MapWindowPoints(wnd, NULL, NULL, 0);
7234 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7235 n, MAKELONG(window_rect.left, window_rect.top));
7236
7237 n = MapWindowPoints(NULL, wnd, NULL, 0);
7238 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7239 n, MAKELONG(-window_rect.left, -window_rect.top));
7240
7241 SetLastError(0xdeadbeef);
7242 p.x = p.y = 100;
7243 n = MapWindowPoints(dwnd, NULL, &p, 1);
7244 err = GetLastError();
7245 ok(n == 0, "Got %d, expected %d\n", n, 0);
7246 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7247 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7248
7249 SetLastError(0xdeadbeef);
7250 p.x = p.y = 100;
7251 n = MapWindowPoints(dwnd, wnd, &p, 1);
7252 err = GetLastError();
7253 ok(n == 0, "Got %d, expected %d\n", n, 0);
7254 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7255 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7256
7257 SetLastError(0xdeadbeef);
7258 p.x = p.y = 100;
7259 n = MapWindowPoints(NULL, dwnd, &p, 1);
7260 err = GetLastError();
7261 ok(n == 0, "Got %d, expected %d\n", n, 0);
7262 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7263 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7264
7265 SetLastError(0xdeadbeef);
7266 p.x = p.y = 100;
7267 n = MapWindowPoints(wnd, dwnd, &p, 1);
7268 err = GetLastError();
7269 ok(n == 0, "Got %d, expected %d\n", n, 0);
7270 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7271 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7272
7273 SetLastError(0xdeadbeef);
7274 p.x = p.y = 100;
7275 n = MapWindowPoints(dwnd, dwnd, &p, 1);
7276 err = GetLastError();
7277 ok(n == 0, "Got %d, expected %d\n", n, 0);
7278 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7279 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7280
7281 SetLastError(0xdeadbeef);
7282 p.x = p.y = 100;
7283 n = MapWindowPoints(NULL, NULL, &p, 1);
7284 err = GetLastError();
7285 ok(n == 0, "Got %d, expected %d\n", n, 0);
7286 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7287 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7288
7289 SetLastError(0xdeadbeef);
7290 p.x = p.y = 100;
7291 n = MapWindowPoints(wnd, wnd, &p, 1);
7292 err = GetLastError();
7293 ok(n == 0, "Got %d, expected %d\n", n, 0);
7294 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7295 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7296
7297 p.x = p.y = 100;
7298 n = MapWindowPoints(wnd, NULL, &p, 1);
7299 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7300 n, MAKELONG(window_rect.left, window_rect.top));
7301 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7302 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7303
7304 p.x = p.y = 100;
7305 n = MapWindowPoints(NULL, wnd, &p, 1);
7306 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7307 n, MAKELONG(-window_rect.left, -window_rect.top));
7308 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7309 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7310
7311 SetLastError(0xdeadbeef);
7312 p.x = p.y = 0;
7313 n = MapWindowPoints(wnd0, NULL, &p, 1);
7314 err = GetLastError();
7315 ok(n == 0, "Got %x, expected 0\n", n);
7316 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7317 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7318
7319 SetLastError(0xdeadbeef);
7320 p.x = p.y = 0;
7321 n = MapWindowPoints(NULL, wnd0, &p, 1);
7322 err = GetLastError();
7323 ok(n == 0, "Got %x, expected 0\n", n);
7324 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7325 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7326
7327 /* Test ClientToScreen */
7328
7329 /* ClientToScreen(wnd, NULL); crashes on Windows */
7330
7331 SetLastError(0xdeadbeef);
7332 ret = ClientToScreen(NULL, NULL);
7333 err = GetLastError();
7334 ok(!ret, "Should fail\n");
7335 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7336
7337 SetLastError(0xdeadbeef);
7338 p.x = p.y = 100;
7339 ret = ClientToScreen(NULL, &p);
7340 err = GetLastError();
7341 ok(!ret, "Should fail\n");
7342 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7343 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7344
7345 SetLastError(0xdeadbeef);
7346 p.x = p.y = 100;
7347 ret = ClientToScreen(dwnd, &p);
7348 err = GetLastError();
7349 ok(!ret, "Should fail\n");
7350 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7351 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7352
7353 p.x = p.y = 100;
7354 ret = ClientToScreen(wnd, &p);
7355 ok(ret, "Failed with error %u\n", GetLastError());
7356 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7357 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7358
7359 p.x = p.y = 0;
7360 ret = ClientToScreen(wnd0, &p);
7361 ok(ret, "Failed with error %u\n", GetLastError());
7362 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7363
7364 /* Test ScreenToClient */
7365
7366 /* ScreenToClient(wnd, NULL); crashes on Windows */
7367
7368 SetLastError(0xdeadbeef);
7369 ret = ScreenToClient(NULL, NULL);
7370 err = GetLastError();
7371 ok(!ret, "Should fail\n");
7372 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7373
7374 SetLastError(0xdeadbeef);
7375 p.x = p.y = 100;
7376 ret = ScreenToClient(NULL, &p);
7377 err = GetLastError();
7378 ok(!ret, "Should fail\n");
7379 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7380 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7381
7382 SetLastError(0xdeadbeef);
7383 p.x = p.y = 100;
7384 ret = ScreenToClient(dwnd, &p);
7385 err = GetLastError();
7386 ok(!ret, "Should fail\n");
7387 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7388 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7389
7390 p.x = p.y = 100;
7391 ret = ScreenToClient(wnd, &p);
7392 ok(ret, "Failed with error %u\n", GetLastError());
7393 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7394 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7395
7396 p.x = p.y = 0;
7397 ret = ScreenToClient(wnd0, &p);
7398 ok(ret, "Failed with error %u\n", GetLastError());
7399 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7400
7401 DestroyWindow(wnd);
7402 DestroyWindow(wnd0);
7403 }
7404
7405 static void test_update_region(void)
7406 {
7407 HWND hwnd, parent, child;
7408 HRGN rgn1, rgn2;
7409 const RECT rc = {15, 15, 40, 40};
7410 const POINT wnd_orig = {30, 20};
7411 const POINT child_orig = {10, 5};
7412
7413 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7414 WS_VISIBLE | WS_CLIPCHILDREN,
7415 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
7416 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
7417 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
7418 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
7419 child = CreateWindowExA(0, "MainWindowClass", NULL,
7420 WS_VISIBLE | WS_CHILD,
7421 child_orig.x, child_orig.y, 100, 50,
7422 hwnd, NULL, GetModuleHandleA(0), 0);
7423 assert(parent && hwnd && child);
7424
7425 ValidateRgn(parent, NULL);
7426 ValidateRgn(hwnd, NULL);
7427 InvalidateRect(hwnd, &rc, FALSE);
7428 ValidateRgn(child, NULL);
7429
7430 rgn1 = CreateRectRgn(0, 0, 0, 0);
7431 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
7432 "has invalid area after ValidateRgn(NULL)\n");
7433 GetUpdateRgn(hwnd, rgn1, FALSE);
7434 rgn2 = CreateRectRgnIndirect(&rc);
7435 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
7436 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
7437 "has invalid area after ValidateRgn(NULL)\n");
7438
7439 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
7440 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
7441
7442 /* parent now has non-simple update region, it consist of
7443 * two rects, that was exposed after hwnd moving ... */
7444 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
7445 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
7446 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7447 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
7448 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
7449 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
7450 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7451 GetUpdateRgn(parent, rgn2, FALSE);
7452 todo_wine
7453 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7454
7455 /* hwnd has the same invalid region as before moving */
7456 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
7457 GetUpdateRgn(hwnd, rgn2, FALSE);
7458 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7459
7460 /* hwnd's invalid area maps to child during moving */
7461 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
7462 rc.right - child_orig.x, rc.bottom - child_orig.y);
7463 GetUpdateRgn(child, rgn2, FALSE);
7464 todo_wine
7465 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7466
7467 DeleteObject(rgn1);
7468 DeleteObject(rgn2);
7469 DestroyWindow(parent);
7470 }
7471
7472 START_TEST(win)
7473 {
7474 HMODULE user32 = GetModuleHandleA( "user32.dll" );
7475 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
7476 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
7477 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
7478 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
7479 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
7480 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
7481 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
7482 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
7483 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
7484 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
7485 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
7486 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
7487 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
7488 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
7489 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
7490 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
7491 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
7492 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
7493
7494 if (!RegisterWindowClasses()) assert(0);
7495
7496 SetLastError(0xdeafbeef);
7497 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
7498 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
7499
7500 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
7501 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
7502
7503 /* make sure that these tests are executed first */
7504 test_FindWindowEx();
7505 test_SetParent();
7506
7507 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
7508 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7509 WS_MAXIMIZEBOX | WS_POPUP,
7510 100, 100, 200, 200,
7511 0, 0, GetModuleHandle(0), NULL);
7512 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
7513 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
7514 WS_MAXIMIZEBOX | WS_POPUP,
7515 100, 100, 200, 200,
7516 0, 0, GetModuleHandle(0), NULL);
7517 assert( hwndMain );
7518 assert( hwndMain2 );
7519
7520 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
7521
7522 /* Add the tests below this line */
7523 test_child_window_from_point();
7524 test_thick_child_size(hwndMain);
7525 test_fullscreen();
7526 test_hwnd_message();
7527 test_nonclient_area(hwndMain);
7528 test_params();
7529 test_GetWindowModuleFileName();
7530 test_capture_1();
7531 test_capture_2();
7532 test_capture_3(hwndMain, hwndMain2);
7533 test_capture_4();
7534 test_rtl_layout();
7535 test_FlashWindowEx();
7536
7537 test_CreateWindow();
7538 test_parent_owner();
7539 test_enum_thread_windows();
7540
7541 test_mdi();
7542 test_icons();
7543 test_SetWindowPos(hwndMain, hwndMain2);
7544 test_SetMenu(hwndMain);
7545 test_SetFocus(hwndMain);
7546 test_SetActiveWindow(hwndMain);
7547 test_NCRedraw();
7548
7549 test_children_zorder(hwndMain);
7550 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
7551 test_popup_zorder(hwndMain2, hwndMain, 0);
7552 test_GetLastActivePopup();
7553 test_keyboard_input(hwndMain);
7554 test_mouse_input(hwndMain);
7555 test_validatergn(hwndMain);
7556 test_nccalcscroll( hwndMain);
7557 test_scrollwindow( hwndMain);
7558 test_scrollvalidate( hwndMain);
7559 test_scrolldc( hwndMain);
7560 test_scroll();
7561 test_IsWindowUnicode();
7562 test_vis_rgn(hwndMain);
7563
7564 test_AdjustWindowRect();
7565 test_window_styles();
7566 test_dialog_styles();
7567 test_redrawnow();
7568 test_csparentdc();
7569 test_SetWindowLong();
7570 test_ShowWindow();
7571 if (0) test_gettext(); /* crashes on NT4 */
7572 test_GetUpdateRect();
7573 test_Expose();
7574 test_layered_window();
7575
7576 test_SetForegroundWindow(hwndMain);
7577 if(!winetest_interactive)
7578 skip("bug 5957: skipping test_shell_window, it crashes ros/win7 explorer\n");
7579 else
7580 test_shell_window();
7581 test_handles( hwndMain );
7582 test_winregion();
7583 test_map_points();
7584 test_update_region();
7585
7586 /* add the tests above this line */
7587 if (hhook) UnhookWindowsHookEx(hhook);
7588
7589 DestroyWindow(hwndMain2);
7590 DestroyWindow(hwndMain);
7591 }