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