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