7cdbc6fc1fa9d1bc1e7213610b47c081b611e433
[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 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2011 ok( (res && res != small_icon && res != icon2) || broken(!res), "wrong small2 icon %p\n", res );
2012 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2013 ok( res == 0, "wrong previous small icon %p/0\n", res );
2014 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2015 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2016 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2017 ok( res == icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, icon );
2018 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2019 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2020 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2021 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2022 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2023 ok( res == small_icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, small_icon );
2024
2025 /* make sure the big icon hasn't changed */
2026 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2027 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2028
2029 DestroyWindow( hwnd );
2030 }
2031
2032 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2033 {
2034 if (msg == WM_NCCALCSIZE)
2035 {
2036 RECT *rect = (RECT *)lparam;
2037 /* first time around increase the rectangle, next time decrease it */
2038 if (rect->left == 100) InflateRect( rect, 10, 10 );
2039 else InflateRect( rect, -10, -10 );
2040 return 0;
2041 }
2042 return DefWindowProcA( hwnd, msg, wparam, lparam );
2043 }
2044
2045 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2046 {
2047 RECT orig_win_rc, rect;
2048 LONG_PTR old_proc;
2049 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2050 HWND hwnd_desktop;
2051 RECT rc1, rc2;
2052 BOOL ret;
2053
2054 SetRect(&rect, 111, 222, 333, 444);
2055 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2056 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2057 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2058
2059 SetRect(&rect, 111, 222, 333, 444);
2060 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2061 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2062 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2063
2064 GetWindowRect(hwnd, &orig_win_rc);
2065
2066 old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2067 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2068 ok(ret, "Got %d\n", ret);
2069 GetWindowRect( hwnd, &rect );
2070 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2071 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2072 GetClientRect( hwnd, &rect );
2073 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2074 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2075 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2076
2077 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2078 ok(ret, "Got %d\n", ret);
2079 GetWindowRect( hwnd, &rect );
2080 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2081 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2082 GetClientRect( hwnd, &rect );
2083 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2084 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2085 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
2086
2087 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2088 orig_win_rc.right, orig_win_rc.bottom, 0);
2089 ok(ret, "Got %d\n", ret);
2090 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
2091
2092 /* Win9x truncates coordinates to 16-bit irrespectively */
2093 if (!is_win9x)
2094 {
2095 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2096 ok(ret, "Got %d\n", ret);
2097 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2098 ok(ret, "Got %d\n", ret);
2099
2100 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2101 ok(ret, "Got %d\n", ret);
2102 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2103 ok(ret, "Got %d\n", ret);
2104 }
2105
2106 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2107 orig_win_rc.right, orig_win_rc.bottom, 0);
2108 ok(ret, "Got %d\n", ret);
2109
2110 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2111 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2112 ok(ret, "Got %d\n", ret);
2113 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2114 ret = SetWindowPos(hwnd, HWND_TOP, 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_NOTOPMOST, 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 not be set\n");
2120
2121 hwnd_desktop = GetDesktopWindow();
2122 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2123 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2124 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2125 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2126 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2127 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2128 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2129
2130 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2131 ok(ret, "Got %d\n", ret);
2132 check_active_state(hwnd, hwnd, hwnd);
2133
2134 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2135 ok(ret, "Got %d\n", ret);
2136 check_active_state(hwnd2, hwnd2, hwnd2);
2137
2138 /* Returns TRUE also for windows that are not siblings */
2139 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2140 ok(ret, "Got %d\n", ret);
2141 check_active_state(hwnd2, hwnd2, hwnd2);
2142
2143 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2144 ok(ret, "Got %d\n", ret);
2145 check_active_state(hwnd2, hwnd2, hwnd2);
2146
2147 /* Does not seem to do anything even without passing flags, still returns TRUE */
2148 GetWindowRect(hwnd_child, &rc1);
2149 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2150 ok(ret, "Got %d\n", ret);
2151 GetWindowRect(hwnd_child, &rc2);
2152 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2153 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2154 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2155 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2156 check_active_state(hwnd2, hwnd2, hwnd2);
2157
2158 /* Same thing the other way around. */
2159 GetWindowRect(hwnd2, &rc1);
2160 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2161 ok(ret, "Got %d\n", ret);
2162 GetWindowRect(hwnd2, &rc2);
2163 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2164 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2165 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2166 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2167 check_active_state(hwnd2, hwnd2, hwnd2);
2168
2169 /* .. and with these windows. */
2170 GetWindowRect(hwnd_grandchild, &rc1);
2171 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2172 ok(ret, "Got %d\n", ret);
2173 GetWindowRect(hwnd_grandchild, &rc2);
2174 ok(rc1.left == rc2.left && rc1.top == rc2.top &&
2175 rc1.right == rc2.right && rc1.bottom == rc2.bottom,
2176 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2177 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
2178 check_active_state(hwnd2, hwnd2, hwnd2);
2179
2180 /* Add SWP_NOZORDER and it will be properly resized. */
2181 GetWindowRect(hwnd_grandchild, &rc1);
2182 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2183 ok(ret, "Got %d\n", ret);
2184 GetWindowRect(hwnd_grandchild, &rc2);
2185 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2186 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2187 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2188 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2189 check_active_state(hwnd2, hwnd2, hwnd2);
2190
2191 /* Given a sibling window, the window is properly resized. */
2192 GetWindowRect(hwnd_child, &rc1);
2193 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2194 ok(ret, "Got %d\n", ret);
2195 GetWindowRect(hwnd_child, &rc2);
2196 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2197 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2198 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2199 rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6, rc2.left, rc2.top, rc2.right, rc2.bottom);
2200 check_active_state(hwnd2, hwnd2, hwnd2);
2201
2202 /* Involving the desktop window changes things. */
2203 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2204 ok(!ret, "Got %d\n", ret);
2205 check_active_state(hwnd2, hwnd2, hwnd2);
2206
2207 GetWindowRect(hwnd_child, &rc1);
2208 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2209 ok(!ret, "Got %d\n", ret);
2210 GetWindowRect(hwnd_child, &rc2);
2211 ok(rc1.top == rc2.top && rc1.left == rc2.left &&
2212 rc1.bottom == rc2.bottom && rc1.right == rc2.right,
2213 "(%d, %d, %d, %d) != (%d, %d, %d, %d)\n",
2214 rc1.top, rc1.left, rc1.bottom, rc1.right, rc2.top, rc2.left, rc2.bottom, rc2.right);
2215 check_active_state(hwnd2, hwnd2, hwnd2);
2216
2217 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2218 ok(!ret, "Got %d\n", ret);
2219 check_active_state(hwnd2, hwnd2, hwnd2);
2220
2221 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2222 ok(!ret, "Got %d\n", ret);
2223 check_active_state(hwnd2, hwnd2, hwnd2);
2224
2225 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2226 ok(!ret, "Got %d\n", ret);
2227 check_active_state(hwnd2, hwnd2, hwnd2);
2228
2229 DestroyWindow(hwnd_grandchild);
2230 DestroyWindow(hwnd_child);
2231 DestroyWindow(hwnd_child2);
2232
2233 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2234 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2235 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2236 ok(ret, "Got %d\n", ret);
2237 flush_events( TRUE );
2238 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2239 DestroyWindow(hwnd_child);
2240 }
2241
2242 static void test_SetMenu(HWND parent)
2243 {
2244 HWND child;
2245 HMENU hMenu, ret;
2246 BOOL retok;
2247 DWORD style;
2248
2249 hMenu = CreateMenu();
2250 assert(hMenu);
2251
2252 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2253 if (0)
2254 {
2255 /* fails on (at least) Wine, NT4, XP SP2 */
2256 test_nonclient_area(parent);
2257 }
2258 ret = GetMenu(parent);
2259 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2260 /* test whether we can destroy a menu assigned to a window */
2261 retok = DestroyMenu(hMenu);
2262 ok( retok, "DestroyMenu error %d\n", GetLastError());
2263 retok = IsMenu(hMenu);
2264 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2265 ret = GetMenu(parent);
2266 /* This test fails on Win9x */
2267 if (!is_win9x)
2268 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2269 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2270 test_nonclient_area(parent);
2271
2272 hMenu = CreateMenu();
2273 assert(hMenu);
2274
2275 /* parent */
2276 ret = GetMenu(parent);
2277 ok(ret == 0, "unexpected menu id %p\n", ret);
2278
2279 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2280 test_nonclient_area(parent);
2281 ret = GetMenu(parent);
2282 ok(ret == 0, "unexpected menu id %p\n", ret);
2283
2284 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2285 if (0)
2286 {
2287 /* fails on (at least) Wine, NT4, XP SP2 */
2288 test_nonclient_area(parent);
2289 }
2290 ret = GetMenu(parent);
2291 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2292
2293 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2294 test_nonclient_area(parent);
2295 ret = GetMenu(parent);
2296 ok(ret == 0, "unexpected menu id %p\n", ret);
2297
2298 /* child */
2299 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2300 assert(child);
2301
2302 ret = GetMenu(child);
2303 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2304
2305 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2306 test_nonclient_area(child);
2307 ret = GetMenu(child);
2308 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2309
2310 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2311 test_nonclient_area(child);
2312 ret = GetMenu(child);
2313 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2314
2315 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2316 test_nonclient_area(child);
2317 ret = GetMenu(child);
2318 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2319
2320 style = GetWindowLongA(child, GWL_STYLE);
2321 SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
2322 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2323 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2324 SetWindowLongA(child, GWL_STYLE, style);
2325
2326 SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
2327 ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
2328 SetWindowLongA(child, GWL_STYLE, style);
2329
2330 DestroyWindow(child);
2331 DestroyMenu(hMenu);
2332 }
2333
2334 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2335 {
2336 HWND child[5], hwnd;
2337 INT_PTR i;
2338
2339 assert(total <= 5);
2340
2341 hwnd = GetWindow(parent, GW_CHILD);
2342 ok(!hwnd, "have to start without children to perform the test\n");
2343
2344 for (i = 0; i < total; i++)
2345 {
2346 if (style[i] & DS_CONTROL)
2347 {
2348 child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2349 0,0,0,0, parent, (HMENU)i, 0, NULL);
2350 if (style[i] & WS_VISIBLE)
2351 ShowWindow(child[i], SW_SHOW);
2352
2353 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2354 }
2355 else
2356 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2357 parent, (HMENU)i, 0, NULL);
2358 trace("child[%ld] = %p\n", i, child[i]);
2359 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2360 }
2361
2362 hwnd = GetWindow(parent, GW_CHILD);
2363 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2364 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2365 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2366
2367 for (i = 0; i < total; i++)
2368 {
2369 trace("hwnd[%ld] = %p\n", i, hwnd);
2370 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2371
2372 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2373 }
2374
2375 for (i = 0; i < total; i++)
2376 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2377 }
2378
2379 static void test_children_zorder(HWND parent)
2380 {
2381 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2382 WS_CHILD };
2383 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2384
2385 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2386 WS_CHILD | WS_VISIBLE, WS_CHILD,
2387 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2388 const int complex_order_1[1] = { 0 };
2389 const int complex_order_2[2] = { 1, 0 };
2390 const int complex_order_3[3] = { 1, 0, 2 };
2391 const int complex_order_4[4] = { 1, 0, 2, 3 };
2392 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2393 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2394 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2395 WS_CHILD | WS_VISIBLE };
2396 const int complex_order_6[3] = { 0, 1, 2 };
2397
2398 /* simple WS_CHILD */
2399 test_window_tree(parent, simple_style, simple_order, 5);
2400
2401 /* complex children styles */
2402 test_window_tree(parent, complex_style, complex_order_1, 1);
2403 test_window_tree(parent, complex_style, complex_order_2, 2);
2404 test_window_tree(parent, complex_style, complex_order_3, 3);
2405 test_window_tree(parent, complex_style, complex_order_4, 4);
2406 test_window_tree(parent, complex_style, complex_order_5, 5);
2407
2408 /* another set of complex children styles */
2409 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2410 }
2411
2412 #define check_z_order(hwnd, next, prev, owner, topmost) \
2413 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2414 __FILE__, __LINE__)
2415
2416 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2417 BOOL topmost, const char *file, int line)
2418 {
2419 HWND test;
2420 DWORD ex_style;
2421
2422 test = GetWindow(hwnd, GW_HWNDNEXT);
2423 /* skip foreign windows */
2424 while (test && test != next &&
2425 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2426 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2427 GetWindow(test, GW_OWNER) == next))
2428 {
2429 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2430 test = GetWindow(test, GW_HWNDNEXT);
2431 }
2432 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2433
2434 test = GetWindow(hwnd, GW_HWNDPREV);
2435 /* skip foreign windows */
2436 while (test && test != prev &&
2437 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2438 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2439 GetWindow(test, GW_OWNER) == hwnd))
2440 {
2441 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2442 test = GetWindow(test, GW_HWNDPREV);
2443 }
2444 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2445
2446 test = GetWindow(hwnd, GW_OWNER);
2447 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2448
2449 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
2450 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2451 hwnd, topmost ? "" : "NOT ");
2452 }
2453
2454 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2455 {
2456 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2457
2458 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2459
2460 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2461
2462 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2463 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2464
2465 hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
2466 WS_OVERLAPPED | WS_CAPTION,
2467 100, 100, 100, 100,
2468 0, 0, GetModuleHandleA(NULL), NULL);
2469 trace("hwnd_F %p\n", hwnd_F);
2470 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2471
2472 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2473 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2474 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2475 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2476
2477 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2478 style,
2479 100, 100, 100, 100,
2480 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2481 trace("hwnd_C %p\n", hwnd_C);
2482 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2483 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2484 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2485 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2486
2487 hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2488 style,
2489 100, 100, 100, 100,
2490 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2491 trace("hwnd_B %p\n", hwnd_B);
2492 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2493 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2494 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2495 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2496 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2497
2498 hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2499 style,
2500 100, 100, 100, 100,
2501 0, 0, GetModuleHandleA(NULL), NULL);
2502 trace("hwnd_A %p\n", hwnd_A);
2503 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2504 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2505 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2506 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2507 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2508 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2509
2510 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);
2511
2512 /* move hwnd_F and its popups up */
2513 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2514 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2515 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2516 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2517 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2518 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2519 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2520
2521 /* move hwnd_F and its popups down */
2522 #if 0 /* enable once Wine is fixed to pass this test */
2523 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2524 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2525 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2526 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2527 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2528 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2529 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2530 #endif
2531
2532 /* make hwnd_C owned by a topmost window */
2533 DestroyWindow( hwnd_C );
2534 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2535 style,
2536 100, 100, 100, 100,
2537 hwnd_A, 0, GetModuleHandleA(NULL), NULL);
2538 trace("hwnd_C %p\n", hwnd_C);
2539 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2540 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2541 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2542 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2543 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2544 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2545
2546 DestroyWindow(hwnd_A);
2547 DestroyWindow(hwnd_B);
2548 DestroyWindow(hwnd_C);
2549 DestroyWindow(hwnd_F);
2550 }
2551
2552 static void test_vis_rgn( HWND hwnd )
2553 {
2554 RECT win_rect, rgn_rect;
2555 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2556 HDC hdc;
2557
2558 ShowWindow(hwnd,SW_SHOW);
2559 hdc = GetDC( hwnd );
2560 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2561 GetWindowRect( hwnd, &win_rect );
2562 GetRgnBox( hrgn, &rgn_rect );
2563 if (is_win9x)
2564 {
2565 trace("win9x, mapping to screen coords\n");
2566 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2567 }
2568 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2569 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2570 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2571 rgn_rect.left, win_rect.left );
2572 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2573 rgn_rect.top, win_rect.top );
2574 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2575 rgn_rect.right, win_rect.right );
2576 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2577 rgn_rect.bottom, win_rect.bottom );
2578 ReleaseDC( hwnd, hdc );
2579 }
2580
2581 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2582 {
2583 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2584 {
2585 HWND child = GetWindow(hwnd, GW_CHILD);
2586 ok(child != 0, "couldn't find child window\n");
2587 SetFocus(child);
2588 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2589 return 0;
2590 }
2591 return DefWindowProcA(hwnd, msg, wp, lp);
2592 }
2593
2594 static void test_SetFocus(HWND hwnd)
2595 {
2596 HWND child, child2, ret;
2597 WNDPROC old_wnd_proc;
2598
2599 /* check if we can set focus to non-visible windows */
2600
2601 ShowWindow(hwnd, SW_SHOW);
2602 SetFocus(0);
2603 SetFocus(hwnd);
2604 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2605 ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2606 ShowWindow(hwnd, SW_HIDE);
2607 SetFocus(0);
2608 SetFocus(hwnd);
2609 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2610 ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2611 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2612 assert(child);
2613 SetFocus(child);
2614 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2615 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2616 ShowWindow(child, SW_SHOW);
2617 ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2618 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2619 ShowWindow(child, SW_HIDE);
2620 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2621 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2622 ShowWindow(child, SW_SHOW);
2623 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
2624 assert(child2);
2625 ShowWindow(child2, SW_SHOW);
2626 SetFocus(child2);
2627 ShowWindow(child, SW_HIDE);
2628 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2629 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
2630 ShowWindow(child, SW_SHOW);
2631 SetFocus(child);
2632 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2633 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2634 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2635
2636 ShowWindow(child, SW_HIDE);
2637 SetFocus(hwnd);
2638 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2639 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2640 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2641 ShowWindow(child, SW_HIDE);
2642 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2643
2644 ShowWindow(hwnd, SW_SHOW);
2645 ShowWindow(child, SW_SHOW);
2646 SetFocus(child);
2647 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2648 EnableWindow(hwnd, FALSE);
2649 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2650 EnableWindow(hwnd, TRUE);
2651
2652 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2653 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2654 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2655 todo_wine
2656 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2657 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2658 ShowWindow(hwnd, SW_RESTORE);
2659 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2660 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2661 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2662 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2663 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2664 todo_wine
2665 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2666 old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2667 ShowWindow(hwnd, SW_RESTORE);
2668 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2669 todo_wine
2670 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2671 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2672
2673 SetFocus( hwnd );
2674 SetParent( child, GetDesktopWindow());
2675 SetParent( child2, child );
2676 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2677 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2678 ret = SetFocus( child2 );
2679 ok( ret == 0, "SetFocus %p should fail\n", child2);
2680 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2681 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2682 ret = SetFocus( child );
2683 ok( ret == 0, "SetFocus %p should fail\n", child);
2684 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2685 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2686 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
2687 SetFocus( child2 );
2688 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2689 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
2690 SetFocus( hwnd );
2691 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2692 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2693 SetFocus( child );
2694 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
2695 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2696
2697 DestroyWindow( child2 );
2698 DestroyWindow( child );
2699 }
2700
2701 static void test_SetActiveWindow(HWND hwnd)
2702 {
2703 HWND hwnd2;
2704
2705 flush_events( TRUE );
2706 ShowWindow(hwnd, SW_HIDE);
2707 SetFocus(0);
2708 SetActiveWindow(0);
2709 check_wnd_state(0, 0, 0, 0);
2710
2711 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2712
2713 ShowWindow(hwnd, SW_SHOW);
2714 check_wnd_state(hwnd, hwnd, hwnd, 0);
2715
2716 hwnd2 = SetActiveWindow(0);
2717 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2718 if (!GetActiveWindow()) /* doesn't always work on vista */
2719 {
2720 check_wnd_state(0, 0, 0, 0);
2721 hwnd2 = SetActiveWindow(hwnd);
2722 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2723 }
2724 check_wnd_state(hwnd, hwnd, hwnd, 0);
2725
2726 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
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_SHOWWINDOW);
2730 check_wnd_state(hwnd, hwnd, hwnd, 0);
2731
2732 ShowWindow(hwnd, SW_HIDE);
2733 check_wnd_state(0, 0, 0, 0);
2734
2735 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2736 SetActiveWindow(hwnd);
2737 check_wnd_state(hwnd, hwnd, hwnd, 0);
2738
2739 ShowWindow(hwnd, SW_SHOW);
2740 check_wnd_state(hwnd, hwnd, hwnd, 0);
2741
2742 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2743 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2744
2745 DestroyWindow(hwnd2);
2746 check_wnd_state(hwnd, hwnd, hwnd, 0);
2747
2748 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2749 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2750
2751 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2752 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2753
2754 DestroyWindow(hwnd2);
2755 check_wnd_state(hwnd, hwnd, hwnd, 0);
2756 }
2757
2758 struct create_window_thread_params
2759 {
2760 HWND window;
2761 HANDLE window_created;
2762 HANDLE test_finished;
2763 };
2764
2765 static DWORD WINAPI create_window_thread(void *param)
2766 {
2767 struct create_window_thread_params *p = param;
2768 DWORD res;
2769 BOOL ret;
2770
2771 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2772
2773 ret = SetEvent(p->window_created);
2774 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2775
2776 res = WaitForSingleObject(p->test_finished, INFINITE);
2777 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2778
2779 DestroyWindow(p->window);
2780 return 0;
2781 }
2782
2783 static void test_SetForegroundWindow(HWND hwnd)
2784 {
2785 struct create_window_thread_params thread_params;
2786 HANDLE thread;
2787 DWORD res, tid;
2788 BOOL ret;
2789 HWND hwnd2;
2790 MSG msg;
2791 LONG style;
2792
2793 flush_events( TRUE );
2794 ShowWindow(hwnd, SW_HIDE);
2795 SetFocus(0);
2796 SetActiveWindow(0);
2797 check_wnd_state(0, 0, 0, 0);
2798
2799 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2800
2801 ShowWindow(hwnd, SW_SHOW);
2802 check_wnd_state(hwnd, hwnd, hwnd, 0);
2803
2804 hwnd2 = SetActiveWindow(0);
2805 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2806 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2807 check_wnd_state(hwnd, hwnd, hwnd, 0);
2808 else
2809 check_wnd_state(0, 0, 0, 0);
2810
2811 ret = SetForegroundWindow(hwnd);
2812 if (!ret)
2813 {
2814 skip( "SetForegroundWindow not working\n" );
2815 return;
2816 }
2817 check_wnd_state(hwnd, hwnd, hwnd, 0);
2818
2819 SetLastError(0xdeadbeef);
2820 ret = SetForegroundWindow(0);
2821 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2822 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2823 broken(GetLastError() == 0xdeadbeef), /* win9x */
2824 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2825 check_wnd_state(hwnd, hwnd, hwnd, 0);
2826
2827 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
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_SHOWWINDOW);
2831 check_wnd_state(hwnd, hwnd, hwnd, 0);
2832
2833 hwnd2 = GetForegroundWindow();
2834 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2835 ret = SetForegroundWindow( GetDesktopWindow() );
2836 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2837 hwnd2 = GetForegroundWindow();
2838 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2839
2840 ShowWindow(hwnd, SW_HIDE);
2841 check_wnd_state(0, 0, 0, 0);
2842
2843 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2844 ret = SetForegroundWindow(hwnd);
2845 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
2846 check_wnd_state(hwnd, hwnd, hwnd, 0);
2847
2848 ShowWindow(hwnd, SW_SHOW);
2849 check_wnd_state(hwnd, hwnd, hwnd, 0);
2850
2851 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2852 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2853
2854 DestroyWindow(hwnd2);
2855 check_wnd_state(hwnd, hwnd, hwnd, 0);
2856
2857 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2858 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2859
2860 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2861 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2862
2863 DestroyWindow(hwnd2);
2864 check_wnd_state(hwnd, hwnd, hwnd, 0);
2865
2866 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
2867 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2868
2869 thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
2870 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2871 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
2872 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2873 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
2874 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2875 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2876 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2877 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
2878
2879 SetForegroundWindow(hwnd2);
2880 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2881
2882 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
2883 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2884 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
2885 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
2886
2887 SetForegroundWindow(hwnd);
2888 check_wnd_state(hwnd, hwnd, hwnd, 0);
2889 style = GetWindowLongA(hwnd2, GWL_STYLE) | WS_CHILD;
2890 ok(SetWindowLongA(hwnd2, GWL_STYLE, style), "SetWindowLong failed\n");
2891 ok(SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
2892 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2893
2894 SetForegroundWindow(hwnd);
2895 check_wnd_state(hwnd, hwnd, hwnd, 0);
2896 ok(SetWindowLongA(hwnd2, GWL_STYLE, style & (~WS_POPUP)), "SetWindowLong failed\n");
2897 ok(!SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
2898 check_wnd_state(hwnd, hwnd, hwnd, 0);
2899
2900 SetEvent(thread_params.test_finished);
2901 WaitForSingleObject(thread, INFINITE);
2902 CloseHandle(thread_params.test_finished);
2903 CloseHandle(thread_params.window_created);
2904 CloseHandle(thread);
2905 DestroyWindow(hwnd2);
2906 }
2907
2908 static WNDPROC old_button_proc;
2909
2910 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2911 {
2912 LRESULT ret;
2913 USHORT key_state;
2914
2915 key_state = GetKeyState(VK_LBUTTON);
2916 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2917
2918 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2919
2920 if (msg == WM_LBUTTONDOWN)
2921 {
2922 HWND hwnd, capture;
2923
2924 check_wnd_state(button, button, button, button);
2925
2926 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2927 assert(hwnd);
2928 trace("hwnd %p\n", hwnd);
2929
2930 check_wnd_state(button, button, button, button);
2931
2932 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2933
2934 check_wnd_state(button, button, button, button);
2935
2936 DestroyWindow(hwnd);
2937
2938 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2939 assert(hwnd);
2940 trace("hwnd %p\n", hwnd);
2941
2942 check_wnd_state(button, button, button, button);
2943
2944 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2945 * match internal button state.
2946 */
2947 SendMessageA(button, WM_KILLFOCUS, 0, 0);
2948 check_wnd_state(button, button, button, 0);
2949
2950 ShowWindow(hwnd, SW_SHOW);
2951 check_wnd_state(hwnd, hwnd, hwnd, 0);
2952
2953 capture = SetCapture(hwnd);
2954 ok(capture == 0, "SetCapture() = %p\n", capture);
2955
2956 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2957
2958 DestroyWindow(hwnd);
2959
2960 check_wnd_state(button, 0, button, 0);
2961 }
2962
2963 return ret;
2964 }
2965
2966 static void test_capture_1(void)
2967 {
2968 HWND button, capture;
2969
2970 capture = GetCapture();
2971 ok(capture == 0, "GetCapture() = %p\n", capture);
2972
2973 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2974 assert(button);
2975 trace("button %p\n", button);
2976
2977 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2978
2979 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2980
2981 capture = SetCapture(button);
2982 ok(capture == 0, "SetCapture() = %p\n", capture);
2983 check_wnd_state(button, 0, button, button);
2984
2985 DestroyWindow(button);
2986 /* old active window test depends on previously executed window
2987 * activation tests, and fails under NT4.
2988 check_wnd_state(oldActive, 0, oldFocus, 0);*/
2989 }
2990
2991 static void test_capture_2(void)
2992 {
2993 HWND button, hwnd, capture, oldFocus, oldActive;
2994
2995 oldFocus = GetFocus();
2996 oldActive = GetActiveWindow();
2997 check_wnd_state(oldActive, 0, oldFocus, 0);
2998
2999 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3000 assert(button);
3001 trace("button %p\n", button);
3002
3003 check_wnd_state(button, button, button, 0);
3004
3005 capture = SetCapture(button);
3006 ok(capture == 0, "SetCapture() = %p\n", capture);
3007
3008 check_wnd_state(button, button, button, button);
3009
3010 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3011 * internal button state.
3012 */
3013 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3014 check_wnd_state(button, button, button, button);
3015
3016 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3017 assert(hwnd);
3018 trace("hwnd %p\n", hwnd);
3019
3020 check_wnd_state(button, button, button, button);
3021
3022 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3023
3024 check_wnd_state(button, button, button, button);
3025
3026 DestroyWindow(hwnd);
3027
3028 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3029 assert(hwnd);
3030 trace("hwnd %p\n", hwnd);
3031
3032 check_wnd_state(button, button, button, button);
3033
3034 ShowWindow(hwnd, SW_SHOW);
3035
3036 check_wnd_state(hwnd, hwnd, hwnd, button);
3037
3038 capture = SetCapture(hwnd);
3039 ok(capture == button, "SetCapture() = %p\n", capture);
3040
3041 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3042
3043 DestroyWindow(hwnd);
3044 check_wnd_state(button, button, button, 0);
3045
3046 DestroyWindow(button);
3047 check_wnd_state(oldActive, 0, oldFocus, 0);
3048 }
3049
3050 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3051 {
3052 BOOL ret;
3053
3054 ShowWindow(hwnd1, SW_HIDE);
3055 ShowWindow(hwnd2, SW_HIDE);
3056
3057 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3058 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3059
3060 SetCapture(hwnd1);
3061 check_wnd_state(0, 0, 0, hwnd1);
3062
3063 SetCapture(hwnd2);
3064 check_wnd_state(0, 0, 0, hwnd2);
3065
3066 ShowWindow(hwnd1, SW_SHOW);
3067 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3068
3069 ret = ReleaseCapture();
3070 ok (ret, "releasecapture did not return TRUE.\n");
3071 ret = ReleaseCapture();
3072 ok (ret, "releasecapture did not return TRUE after second try.\n");
3073 }
3074
3075 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3076 {
3077 GUITHREADINFO gti;
3078 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3079 BOOL status;
3080 switch (msg)
3081 {
3082 case WM_CAPTURECHANGED:
3083
3084 /* now try to release capture from menu. this should fail */
3085 if (pGetGUIThreadInfo)
3086 {
3087 memset(&gti, 0, sizeof(GUITHREADINFO));
3088 gti.cbSize = sizeof(GUITHREADINFO);
3089 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3090 ok(status, "GetGUIThreadInfo() failed!\n");
3091 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3092 }
3093 cap_wnd = GetCapture();
3094
3095 ok(cap_wnd == (HWND)lParam, "capture window %p does not match lparam %lx\n", cap_wnd, lParam);
3096 todo_wine ok(cap_wnd == hWnd, "capture window %p does not match hwnd %p\n", cap_wnd, hWnd);
3097
3098 /* check that re-setting the capture for the menu fails */
3099 set_cap_wnd = SetCapture(cap_wnd);
3100 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3101 "SetCapture should have failed!\n");
3102 if (set_cap_wnd)
3103 {
3104 DestroyWindow(hWnd);
3105 break;
3106 }
3107
3108 /* check that SetCapture fails for another window and that it does not touch the error code */
3109 set_cap_wnd = SetCapture(hWnd);
3110 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3111
3112 /* check that ReleaseCapture fails and does not touch the error code */
3113 status = ReleaseCapture();
3114 ok(!status, "ReleaseCapture should have failed!\n");
3115
3116 /* check that thread info did not change */
3117 if (pGetGUIThreadInfo)
3118 {
3119 memset(&gti, 0, sizeof(GUITHREADINFO));
3120 gti.cbSize = sizeof(GUITHREADINFO);
3121 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3122 ok(status, "GetGUIThreadInfo() failed!\n");
3123 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3124 }
3125
3126 /* verify that no capture change took place */
3127 cap_wnd2 = GetCapture();
3128 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3129
3130 /* we are done. kill the window */
3131 DestroyWindow(hWnd);
3132 break;
3133
3134 default:
3135 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3136 }
3137 return 0;
3138 }
3139
3140 /* Test that no-one can mess around with the current capture while a menu is open */
3141 static void test_capture_4(void)
3142 {
3143 BOOL ret;
3144 HMENU hmenu;
3145 HWND hwnd;
3146 WNDCLASSA wclass;
3147 HINSTANCE hInstance = GetModuleHandleA( NULL );
3148 ATOM aclass;
3149
3150 if (!pGetGUIThreadInfo)
3151 {
3152 win_skip("GetGUIThreadInfo is not available\n");
3153 return;
3154 }
3155 wclass.lpszClassName = "TestCapture4Class";
3156 wclass.style = CS_HREDRAW | CS_VREDRAW;
3157 wclass.lpfnWndProc = test_capture_4_proc;
3158 wclass.hInstance = hInstance;
3159 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
3160 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
3161 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3162 wclass.lpszMenuName = 0;
3163 wclass.cbClsExtra = 0;
3164 wclass.cbWndExtra = 0;
3165 aclass = RegisterClassA( &wclass );
3166 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3167 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3168 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3169 400, 200, NULL, NULL, hInstance, NULL);
3170 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3171 if (!hwnd) return;
3172 hmenu = CreatePopupMenu();
3173
3174 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3175 ok( ret, "AppendMenuA has failed!\n");
3176
3177 /* set main window to have initial capture */
3178 SetCapture(hwnd);
3179
3180 if (is_win9x)
3181 {
3182 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3183 }
3184 else
3185 {
3186 /* create popup (it will self-destruct) */
3187 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3188 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3189 }
3190
3191 /* clean up */
3192 DestroyMenu(hmenu);
3193 DestroyWindow(hwnd);
3194 }
3195
3196 /* PeekMessage wrapper that ignores the messages we don't care about */
3197 static BOOL peek_message( MSG *msg )
3198 {
3199 BOOL ret;
3200 do
3201 {
3202 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3203 } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
3204 return ret;
3205 }
3206
3207 static void test_keyboard_input(HWND hwnd)
3208 {
3209 MSG msg;
3210 BOOL ret;
3211
3212 flush_events( TRUE );
3213 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3214 UpdateWindow(hwnd);
3215 flush_events( TRUE );
3216
3217 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3218
3219 SetFocus(hwnd);
3220 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3221
3222 flush_events( TRUE );
3223
3224 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3225 ret = peek_message(&msg);
3226 ok( ret, "no message available\n");
3227 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3228 ret = peek_message(&msg);
3229 ok( !ret, "message %04x available\n", msg.message);
3230
3231 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3232
3233 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3234 ret = peek_message(&msg);
3235 ok(ret, "no message available\n");
3236 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3237 ret = peek_message(&msg);
3238 ok( !ret, "message %04x available\n", msg.message);
3239
3240 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3241
3242 keybd_event(VK_SPACE, 0, 0, 0);
3243 if (!peek_message(&msg))
3244 {
3245 skip( "keybd_event didn't work, skipping keyboard test\n" );
3246 return;
3247 }
3248 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3249 ret = peek_message(&msg);
3250 ok( !ret, "message %04x available\n", msg.message);
3251
3252 SetFocus(0);
3253 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3254
3255 flush_events( TRUE );
3256
3257 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3258 ret = peek_message(&msg);
3259 ok(ret, "no message available\n");
3260 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3261 ret = peek_message(&msg);
3262 ok( !ret, "message %04x available\n", msg.message);
3263
3264 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3265
3266 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3267 ret = peek_message(&msg);
3268 ok(ret, "no message available\n");
3269 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3270 ret = peek_message(&msg);
3271 ok( !ret, "message %04x available\n", msg.message);
3272
3273 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3274
3275 keybd_event(VK_SPACE, 0, 0, 0);
3276 ret = peek_message(&msg);
3277 ok(ret, "no message available\n");
3278 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3279 ret = peek_message(&msg);
3280 ok( !ret, "message %04x available\n", msg.message);
3281 }
3282
3283 static BOOL wait_for_message( MSG *msg )
3284 {
3285 BOOL ret;
3286
3287 for (;;)
3288 {
3289 ret = peek_message(msg);
3290 if (ret)
3291 {
3292 if (msg->message == WM_PAINT) DispatchMessageA(msg);
3293 else break;
3294 }
3295 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3296 }
3297 if (!ret) msg->message = 0;
3298 return ret;
3299 }
3300
3301 static void test_mouse_input(HWND hwnd)
3302 {
3303 RECT rc;
3304 POINT pt;
3305 int x, y;
3306 HWND popup;
3307 MSG msg;
3308 BOOL ret;
3309 LRESULT res;
3310
3311 ShowWindow(hwnd, SW_SHOWNORMAL);
3312 UpdateWindow(hwnd);
3313 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3314
3315 GetWindowRect(hwnd, &rc);
3316 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
3317
3318 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3319 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3320 hwnd, 0, 0, NULL);
3321 assert(popup != 0);
3322 ShowWindow(popup, SW_SHOW);
3323 UpdateWindow(popup);
3324 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3325
3326 GetWindowRect(popup, &rc);
3327 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
3328
3329 x = rc.left + (rc.right - rc.left) / 2;
3330 y = rc.top + (rc.bottom - rc.top) / 2;
3331 trace("setting cursor to (%d,%d)\n", x, y);
3332
3333 SetCursorPos(x, y);
3334 GetCursorPos(&pt);
3335 if (x != pt.x || y != pt.y)
3336 {
3337 skip( "failed to set mouse position, skipping mouse input tests\n" );
3338 goto done;
3339 }
3340
3341 flush_events( TRUE );
3342
3343 /* Check that setting the same position may generate WM_MOUSEMOVE */
3344 SetCursorPos(x, y);
3345 msg.message = 0;
3346 ret = peek_message(&msg);
3347 if (ret)
3348 {
3349 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3350 msg.hwnd, msg.message);
3351 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3352 x, y, msg.pt.x, msg.pt.y);
3353 }
3354
3355 /* force the system to update its internal queue mouse position,
3356 * otherwise it won't generate relative mouse movements below.
3357 */
3358 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3359 flush_events( TRUE );
3360
3361 msg.message = 0;
3362 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3363 flush_events( FALSE );
3364 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3365 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3366 {
3367 if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
3368 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3369 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3370 DispatchMessageA(&msg);
3371 }
3372 ret = peek_message(&msg);
3373 ok( !ret, "message %04x available\n", msg.message);
3374
3375 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3376 ShowWindow(popup, SW_HIDE);
3377 ret = wait_for_message( &msg );
3378 if (ret)
3379 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3380 flush_events( TRUE );
3381
3382 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3383 ShowWindow(hwnd, SW_HIDE);
3384 ret = wait_for_message( &msg );
3385 ok( !ret, "message %04x available\n", msg.message);
3386 flush_events( TRUE );
3387
3388 /* test mouse clicks */
3389
3390 ShowWindow(hwnd, SW_SHOW);
3391 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3392 flush_events( TRUE );
3393 ShowWindow(popup, SW_SHOW);
3394 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3395 flush_events( TRUE );
3396
3397 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3398 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3399 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3400 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3401
3402 ret = wait_for_message( &msg );
3403 if (!ret)
3404 {
3405 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3406 goto done;
3407 }
3408 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3409 {
3410 ret = wait_for_message( &msg );
3411 ok(ret, "no message available\n");
3412 }
3413
3414 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3415 msg.hwnd, popup, msg.message);
3416
3417 ret = wait_for_message( &msg );
3418 ok(ret, "no message available\n");
3419 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3420 msg.hwnd, popup, msg.message);
3421
3422 ret = wait_for_message( &msg );
3423 ok(ret, "no message available\n");
3424 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3425 msg.hwnd, popup, msg.message);
3426
3427 ret = wait_for_message( &msg );
3428 ok(ret, "no message available\n");
3429 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3430 msg.hwnd, popup, msg.message);
3431
3432 ret = peek_message(&msg);
3433 ok(!ret, "message %04x available\n", msg.message);
3434
3435 ShowWindow(popup, SW_HIDE);
3436 flush_events( TRUE );
3437
3438 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3439 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3440 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3441 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3442
3443 ret = wait_for_message( &msg );
3444 ok(ret, "no message available\n");
3445 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3446 msg.hwnd, hwnd, msg.message);
3447 ret = wait_for_message( &msg );
3448 ok(ret, "no message available\n");
3449 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3450 msg.hwnd, hwnd, msg.message);
3451
3452 test_lbuttondown_flag = TRUE;
3453 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3454 test_lbuttondown_flag = FALSE;
3455
3456 ret = wait_for_message( &msg );
3457 ok(ret, "no message available\n");
3458 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3459 msg.hwnd, popup, msg.message);
3460 ok(peek_message(&msg), "no message available\n");
3461 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3462 msg.hwnd, popup, msg.message);
3463 ok(peek_message(&msg), "no message available\n");
3464
3465 /* Test WM_MOUSEACTIVATE */
3466 #define TEST_MOUSEACTIVATE(A,B) \
3467 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3468 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3469
3470 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3471 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3472 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3473 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3474 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3475 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3476 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3477 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3478 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3479 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3480 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3481 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3482 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3483 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3484 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3485 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3486 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3487 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3488 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3489 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3490 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3491 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3492 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3493 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3494
3495 done:
3496 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3497 flush_events( TRUE );
3498
3499 DestroyWindow(popup);
3500 }
3501
3502 static void test_validatergn(HWND hwnd)
3503 {
3504 HWND child;
3505 RECT rc, rc2;
3506 HRGN rgn;
3507 int ret;
3508 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3509 ShowWindow(hwnd, SW_SHOW);
3510 UpdateWindow( hwnd);
3511 /* test that ValidateRect validates children*/
3512 InvalidateRect( child, NULL, 1);
3513 GetWindowRect( child, &rc);
3514 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3515 ret = GetUpdateRect( child, &rc2, 0);
3516 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3517 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3518 "Update rectangle is empty!\n");
3519 ValidateRect( hwnd, &rc);
3520 ret = GetUpdateRect( child, &rc2, 0);
3521 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3522 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3523 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3524 rc2.right, rc2.bottom);
3525
3526 /* now test ValidateRgn */
3527 InvalidateRect( child, NULL, 1);
3528 GetWindowRect( child, &rc);
3529 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3530 rgn = CreateRectRgnIndirect( &rc);
3531 ValidateRgn( hwnd, rgn);
3532 ret = GetUpdateRect( child, &rc2, 0);
3533 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3534 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3535 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
3536 rc2.right, rc2.bottom);
3537
3538 DeleteObject( rgn);
3539 DestroyWindow( child );
3540 }
3541
3542 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3543 {
3544 RECT rc;
3545 MoveWindow( hwnd, 0, 0, x, y, 0);
3546 GetWindowRect( hwnd, prc);
3547 rc = *prc;
3548 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3549 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
3550 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
3551 }
3552
3553 static void test_nccalcscroll(HWND parent)
3554 {
3555 RECT rc1;
3556 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3557 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3558 HWND hwnd = CreateWindowExA(0, "static", NULL,
3559 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3560 10, 10, 200, 200, parent, 0, 0, NULL);
3561 ShowWindow( parent, SW_SHOW);
3562 UpdateWindow( parent);
3563
3564 /* test window too low for a horizontal scroll bar */
3565 nccalchelper( hwnd, 100, sbheight, &rc1);
3566 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
3567 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
3568
3569 /* test window just high enough for a horizontal scroll bar */
3570 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3571 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
3572 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3573
3574 /* test window too narrow for a vertical scroll bar */
3575 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3576 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
3577 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
3578
3579 /* test window just wide enough for a vertical scroll bar */
3580 nccalchelper( hwnd, sbwidth, 100, &rc1);
3581 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
3582 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3583
3584 /* same test, but with client edge: not enough width */
3585 SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
3586 nccalchelper( hwnd, sbwidth, 100, &rc1);
3587 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3588 "Width should be %d size is %d,%d - %d,%d\n",
3589 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3590
3591 DestroyWindow( hwnd);
3592 }
3593
3594 static void test_SetParent(void)
3595 {
3596 HWND desktop = GetDesktopWindow();
3597 HMENU hMenu;
3598 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3599 BOOL bret;
3600
3601 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3602 100, 100, 200, 200, 0, 0, 0, NULL);
3603 assert(parent != 0);
3604 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3605 0, 0, 50, 50, parent, 0, 0, NULL);
3606 assert(child1 != 0);
3607 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3608 0, 0, 50, 50, child1, 0, 0, NULL);
3609 assert(child2 != 0);
3610 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3611 0, 0, 50, 50, child2, 0, 0, NULL);
3612 assert(child3 != 0);
3613 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3614 0, 0, 50, 50, child3, 0, 0, NULL);
3615 assert(child4 != 0);
3616
3617 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3618 parent, child1, child2, child3, child4);
3619
3620 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3621 check_parents(child1, parent, parent, parent, 0, parent, parent);
3622 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3623 check_parents(child3, child2, child2, child2, 0, child2, parent);
3624 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3625
3626 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3627 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3628 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3629 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3630 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3631
3632 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3633 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3634 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3635 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3636 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3637 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3638 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3639 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3640 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3641
3642 if (!is_win9x) /* Win9x doesn't survive this test */
3643 {
3644 ok(!SetParent(parent, child1), "SetParent should fail\n");
3645 ok(!SetParent(child2, child3), "SetParent should fail\n");
3646 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3647 ret = SetParent(parent, child2);
3648 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
3649 if (ret) /* nt4, win2k */
3650 {
3651 ret = SetParent(parent, child3);
3652 ok(ret != 0, "SetParent should not fail\n");
3653 ret = SetParent(child2, parent);
3654 ok(!ret, "SetParent should fail\n");
3655 ret = SetParent(parent, child4);
3656 ok(ret != 0, "SetParent should not fail\n");
3657 check_parents(parent, child4, child4, 0, 0, child4, parent);
3658 check_parents(child1, parent, parent, parent, 0, child4, parent);
3659 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3660 check_parents(child3, child2, child2, child2, 0, child2, parent);
3661 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3662 }
3663 else
3664 {
3665 ret = SetParent(parent, child3);
3666 ok(ret != 0, "SetParent should not fail\n");
3667 ret = SetParent(child2, parent);
3668 ok(!ret, "SetParent should fail\n");
3669 ret = SetParent(parent, child4);
3670 ok(!ret, "SetParent should fail\n");
3671 check_parents(parent, child3, child3, 0, 0, child2, parent);
3672 check_parents(child1, parent, parent, parent, 0, child2, parent);
3673 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3674 check_parents(child3, child2, child2, child2, 0, child2, parent);
3675 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3676 }
3677 }
3678 else
3679 skip("Win9x/WinMe crash\n");
3680
3681 hMenu = CreateMenu();
3682 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3683 100, 100, 200, 200, 0, hMenu, 0, NULL);
3684 assert(sibling != 0);
3685
3686 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3687 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3688
3689 ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
3690 ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
3691 ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
3692 ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
3693 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3694 SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
3695 ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3696 ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
3697 ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3698 SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
3699 ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
3700 ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3701
3702 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3703
3704 ok(!IsWindow(parent), "parent still exists\n");
3705 ok(!IsWindow(sibling), "sibling still exists\n");
3706 ok(!IsWindow(child1), "child1 still exists\n");
3707 ok(!IsWindow(child2), "child2 still exists\n");
3708 ok(!IsWindow(child3), "child3 still exists\n");
3709 ok(!IsWindow(child4), "child4 still exists\n");
3710
3711 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3712 100, 100, 200, 200, 0, 0, 0, NULL);
3713 assert(parent != 0);
3714 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3715 0, 0, 50, 50, parent, 0, 0, NULL);
3716 assert(child1 != 0);
3717 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
3718 0, 0, 50, 50, 0, 0, 0, NULL);
3719 assert(popup != 0);
3720
3721 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
3722
3723 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3724 check_parents(child1, parent, parent, parent, 0, parent, parent);
3725 check_parents(popup, desktop, 0, 0, 0, popup, popup);
3726
3727 SetActiveWindow(parent);
3728 SetFocus(parent);
3729 check_active_state(parent, 0, parent);
3730
3731 ret = SetParent(popup, child1);
3732 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
3733 check_parents(popup, child1, child1, 0, 0, parent, popup);
3734 check_active_state(popup, 0, popup);
3735
3736 SetActiveWindow(parent);
3737 SetFocus(popup);
3738 check_active_state(popup, 0, popup);
3739
3740 EnableWindow(child1, FALSE);
3741 check_active_state(popup, 0, popup);
3742 SetFocus(parent);
3743 check_active_state(parent, 0, parent);
3744 SetFocus(popup);
3745 check_active_state(popup, 0, popup);
3746 EnableWindow(child1, TRUE);
3747
3748 ShowWindow(child1, SW_MINIMIZE);
3749 SetFocus(parent);
3750 check_active_state(parent, 0, parent);
3751 SetFocus(popup);
3752 check_active_state(popup, 0, popup);
3753 ShowWindow(child1, SW_HIDE);
3754
3755 SetActiveWindow(parent);
3756 SetFocus(parent);
3757 check_active_state(parent, 0, parent);
3758
3759 bret = SetForegroundWindow(popup);
3760 ok(bret, "SetForegroundWindow() failed\n");
3761 check_active_state(popup, popup, popup);
3762
3763 ShowWindow(parent, SW_SHOW);
3764 SetActiveWindow(popup);
3765 ok(DestroyWindow(popup), "DestroyWindow() failed\n");
3766 check_active_state(parent, parent, parent);
3767
3768 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
3769
3770 ok(!IsWindow(parent), "parent still exists\n");
3771 ok(!IsWindow(child1), "child1 still exists\n");
3772 ok(!IsWindow(popup), "popup still exists\n");
3773 }
3774
3775 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3776 {
3777 LPCREATESTRUCTA lpcs;
3778 LPSTYLESTRUCT lpss;
3779
3780 switch (msg)
3781 {
3782 case WM_NCCREATE:
3783 case WM_CREATE:
3784 lpcs = (LPCREATESTRUCTA)lparam;
3785 lpss = lpcs->lpCreateParams;
3786 if (lpss)
3787 {
3788 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3789 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3790 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3791 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3792 else
3793 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3794
3795 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3796 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3797 lpss->styleOld, lpcs->dwExStyle);
3798
3799 ok(lpss->styleNew == lpcs->style,
3800 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3801 lpss->styleNew, lpcs->style);
3802 }
3803 break;
3804 }
3805 return DefWindowProcA(hwnd, msg, wparam, lparam);
3806 }
3807
3808 static ATOM atomStyleCheckClass;
3809
3810 static void register_style_check_class(void)
3811 {
3812 WNDCLASSA wc =
3813 {
3814 0,
3815 StyleCheckProc,
3816 0,
3817 0,
3818 GetModuleHandleA(NULL),
3819 NULL,
3820 LoadCursorA(0, (LPCSTR)IDC_ARROW),
3821 (HBRUSH)(COLOR_BTNFACE+1),
3822 NULL,
3823 "WineStyleCheck",
3824 };
3825
3826 atomStyleCheckClass = RegisterClassA(&wc);
3827 assert(atomStyleCheckClass);
3828 }
3829
3830 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3831 {
3832 DWORD dwActualStyle;
3833 DWORD dwActualExStyle;
3834 STYLESTRUCT ss;
3835 HWND hwnd;
3836 HWND hwndParent = NULL;
3837
3838 ss.styleNew = dwStyleIn;
3839 ss.styleOld = dwExStyleIn;
3840
3841 if (dwStyleIn & WS_CHILD)
3842 {
3843 hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3844 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3845 }
3846
3847 hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
3848 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3849 assert(hwnd);
3850
3851 flush_events( TRUE );
3852
3853 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3854 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3855 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3856 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3857
3858 /* try setting the styles explicitly */
3859 SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
3860 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3861 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3862 /* WS_EX_WINDOWEDGE can't always be changed */
3863 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3864 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3865 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3866 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3867 else
3868 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3869 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3870 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3871
3872 SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
3873 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
3874 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
3875 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3876 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
3877 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
3878 /* WS_EX_WINDOWEDGE can't always be changed */
3879 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
3880 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3881 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
3882 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
3883 else
3884 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
3885 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
3886 /* FIXME: Remove the condition below once Wine is fixed */
3887 if (dwActualExStyle != dwExStyleOut)
3888 todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3889 else
3890 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
3891
3892 DestroyWindow(hwnd);
3893 if (hwndParent) DestroyWindow(hwndParent);
3894 }
3895
3896 /* tests what window styles the window manager automatically adds */
3897 static void test_window_styles(void)
3898 {
3899 register_style_check_class();
3900
3901 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3902 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3903 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3904 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3905 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
3906 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3907 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3908 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
3909 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
3910 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
3911 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
3912 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
3913 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
3914 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3915 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3916 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3917 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3918 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3919 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3920 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3921 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3922 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
3923 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
3924 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3925 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3926 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3927 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3928 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3929 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
3930 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3931 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
3932 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3933 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3934
3935 if (pGetLayeredWindowAttributes)
3936 {
3937 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
3938 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
3939 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
3940 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
3941 }
3942 }
3943
3944 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3945 {
3946 return 0;
3947 }
3948
3949 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
3950 {
3951 struct
3952 {
3953 DLGTEMPLATE dt;
3954 WORD menu_name;
3955 WORD class_id;
3956 WORD class_atom;
3957 WCHAR caption[1];
3958 } dlg_data;
3959 DWORD style, ex_style;
3960 HWND hwnd, parent = 0;
3961
3962 if (style_in & WS_CHILD)
3963 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3964 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3965
3966 dlg_data.dt.style = style_in;
3967 dlg_data.dt.dwExtendedStyle = ex_style_in;
3968 dlg_data.dt.cdit = 0;
3969 dlg_data.dt.x = 0;
3970 dlg_data.dt.y = 0;
3971 dlg_data.dt.cx = 100;
3972 dlg_data.dt.cy = 100;
3973 dlg_data.menu_name = 0;
3974 dlg_data.class_id = 0;
3975 dlg_data.class_atom = 0;
3976 dlg_data.caption[0] = 0;
3977
3978 hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
3979 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
3980
3981 flush_events( TRUE );
3982
3983 style = GetWindowLongA(hwnd, GWL_STYLE);
3984 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
3985 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
3986 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
3987
3988 /* try setting the styles explicitly */
3989 SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
3990 style = GetWindowLongA(hwnd, GWL_STYLE);
3991 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
3992 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
3993 /* WS_EX_WINDOWEDGE can't always be changed */
3994 if (ex_style_in & WS_EX_DLGMODALFRAME)
3995 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3996 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
3997 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
3998 else
3999 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4000 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4001
4002 SetWindowLongA(hwnd, GWL_STYLE, style_in);
4003 style = GetWindowLongA(hwnd, GWL_STYLE);
4004 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4005 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4006 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
4007 else style_out = style_in | WS_CLIPSIBLINGS;
4008 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
4009 /* WS_EX_WINDOWEDGE can't always be changed */
4010 if (ex_style_in & WS_EX_DLGMODALFRAME)
4011 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4012 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4013 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4014 else
4015 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4016 /* FIXME: Remove the condition below once Wine is fixed */
4017 if (ex_style != ex_style_out)
4018 todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4019 else
4020 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4021
4022 DestroyWindow(hwnd);
4023 DestroyWindow(parent);
4024 }
4025
4026 static void test_dialog_styles(void)
4027 {
4028 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4029 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4030 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4031 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4032 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4033 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4034 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4035 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4036 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4037 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4038 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4039 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4040 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4041 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4042 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4043 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4044 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4045 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4046 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4047 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4048 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4049 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4050 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4051 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4052 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4053 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4054 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4055 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4056 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4057 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4058 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4059 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4060 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4061 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4062 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4063 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4064 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4065 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4066 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4067 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4068 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4069 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4070 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4071 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4072 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4073 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4074 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4075 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);
4076 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4077 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4078 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4079 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);
4080 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4081 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4082 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4083 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4084 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4085 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4086 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4087 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4088 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4089 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4090 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4091 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4092 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4093 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4094 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4095 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4096 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4097 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4098 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4099 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4100 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4101 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4102 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4103
4104 if (pGetLayeredWindowAttributes)
4105 {
4106 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4107 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);
4108 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4109 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4110 }
4111 }
4112
4113 static void test_scrollwindow( HWND hwnd)
4114 {
4115 HDC hdc;
4116 RECT rc, rc2, rc3;
4117 COLORREF colr;
4118
4119 ShowWindow( hwnd, SW_SHOW);
4120 UpdateWindow( hwnd);
4121 flush_events( TRUE );
4122 GetClientRect( hwnd, &rc);
4123 hdc = GetDC( hwnd);
4124 /* test ScrollWindow(Ex) with no clip rectangle */
4125 /* paint the lower half of the window black */
4126 rc2 = rc;
4127 rc2.top = ( rc2.top + rc2.bottom) / 2;
4128 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4129 /* paint the upper half of the window white */
4130 rc2.bottom = rc2.top;
4131 rc2.top =0;
4132 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4133 /* scroll lower half up */
4134 rc2 = rc;
4135 rc2.top = ( rc2.top + rc2.bottom) / 2;
4136 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4137 flush_events(FALSE);
4138 /* expected: black should have scrolled to the upper half */
4139 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4140 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4141 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4142 /* paint the lower half of the window black */
4143 rc2 = rc;
4144 rc2.top = ( rc2.top + rc2.bottom) / 2;
4145 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4146 /* paint the upper half of the window white */
4147 rc2.bottom = rc2.top;
4148 rc2.top =0;
4149 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4150 /* scroll lower half up */
4151 rc2 = rc;
4152 rc2.top = ( rc2.top + rc2.bottom) / 2;
4153 rc3 = rc;
4154 rc3.left = rc3.right / 4;
4155 rc3.right -= rc3.right / 4;
4156 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4157 flush_events(FALSE);
4158 /* expected: black should have scrolled to the upper half */
4159 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4160 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4161
4162 /* clean up */
4163 ReleaseDC( hwnd, hdc);
4164 }
4165
4166 static void test_scrollvalidate( HWND parent)
4167 {
4168 HDC hdc;
4169 HRGN hrgn=CreateRectRgn(0,0,0,0);
4170 HRGN exprgn, tmprgn, clipping;
4171 RECT rc, rcu, cliprc;
4172 /* create two overlapping child windows. The visual region
4173 * of hwnd1 is clipped by the overlapping part of
4174 * hwnd2 because of the WS_CLIPSIBLING style */
4175 HWND hwnd1, hwnd2;
4176
4177 clipping = CreateRectRgn(0,0,0,0);
4178 tmprgn = CreateRectRgn(0,0,0,0);
4179 exprgn = CreateRectRgn(0,0,0,0);
4180 hwnd2 = CreateWindowExA(0, "static", NULL,
4181 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4182 75, 30, 100, 100, parent, 0, 0, NULL);
4183 hwnd1 = CreateWindowExA(0, "static", NULL,
4184 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4185 25, 50, 100, 100, parent, 0, 0, NULL);
4186 ShowWindow( parent, SW_SHOW);
4187 UpdateWindow( parent);
4188 GetClientRect( hwnd1, &rc);
4189 cliprc=rc;
4190 SetRectRgn( clipping, 10, 10, 90, 90);
4191 hdc = GetDC( hwnd1);
4192 /* for a visual touch */
4193 TextOutA( hdc, 0,10, "0123456789", 10);
4194 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4195 if (winetest_debug > 0) dump_region(hrgn);
4196 /* create a region with what is expected */
4197 SetRectRgn( exprgn, 39,0,49,74);
4198 SetRectRgn( tmprgn, 88,79,98,93);
4199 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4200 SetRectRgn( tmprgn, 0,93,98,98);
4201 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4202 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4203 trace("update rect is %d,%d - %d,%d\n",
4204 rcu.left,rcu.top,rcu.right,rcu.bottom);
4205 /* now with clipping region */
4206 SelectClipRgn( hdc, clipping);
4207 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4208 if (winetest_debug > 0) dump_region(hrgn);
4209 /* create a region with what is expected */
4210 SetRectRgn( exprgn, 39,10,49,74);
4211 SetRectRgn( tmprgn, 80,79,90,85);
4212 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4213 SetRectRgn( tmprgn, 10,85,90,90);
4214 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4215 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4216 trace("update rect is %d,%d - %d,%d\n",
4217 rcu.left,rcu.top,rcu.right,rcu.bottom);
4218 ReleaseDC( hwnd1, hdc);
4219
4220 /* test scrolling a window with an update region */
4221 DestroyWindow( hwnd2);
4222 ValidateRect( hwnd1, NULL);
4223 SetRect( &rc, 40,40, 50,50);
4224 InvalidateRect( hwnd1, &rc, 1);
4225 GetClientRect( hwnd1, &rc);
4226 cliprc=rc;
4227 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
4228 SW_SCROLLCHILDREN | SW_INVALIDATE);
4229 if (winetest_debug > 0) dump_region(hrgn);
4230 SetRectRgn( exprgn, 88,0,98,98);
4231 SetRectRgn( tmprgn, 30, 40, 50, 50);
4232 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4233 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4234
4235 /* clear an update region */
4236 UpdateWindow( hwnd1 );
4237
4238 SetRect( &rc, 0,40, 100,60);
4239 SetRect( &cliprc, 0,0, 100,100);
4240 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4241 if (winetest_debug > 0) dump_region( hrgn );
4242 SetRectRgn( exprgn, 0, 40, 98, 60 );
4243 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
4244
4245 /* now test ScrollWindowEx with a combination of
4246 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
4247 /* make hwnd2 the child of hwnd1 */
4248 hwnd2 = CreateWindowExA(0, "static", NULL,
4249 WS_CHILD| WS_VISIBLE | WS_BORDER ,
4250 50, 50, 100, 100, hwnd1, 0, 0, NULL);
4251 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
4252 GetClientRect( hwnd1, &rc);
4253 cliprc=rc;
4254
4255 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
4256 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4257 ValidateRect( hwnd1, NULL);
4258 ValidateRect( hwnd2, NULL);
4259 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
4260 SW_SCROLLCHILDREN | SW_INVALIDATE);
4261 if (winetest_debug > 0) dump_region(hrgn);
4262 SetRectRgn( exprgn, 88,0,98,88);
4263 SetRectRgn( tmprgn, 0,88,98,98);
4264 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4265 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4266
4267 /* SW_SCROLLCHILDREN */
4268 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4269 ValidateRect( hwnd1, NULL);
4270 ValidateRect( hwnd2, NULL);
4271 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
4272 if (winetest_debug > 0) dump_region(hrgn);
4273 /* expected region is the same as in previous test */
4274 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4275
4276 /* no SW_SCROLLCHILDREN */
4277 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
4278 ValidateRect( hwnd1, NULL);
4279 ValidateRect( hwnd2, NULL);
4280 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4281 if (winetest_debug > 0) dump_region(hrgn);
4282 /* expected region is the same as in previous test */
4283 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4284
4285 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
4286 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
4287 ValidateRect( hwnd1, NULL);
4288 ValidateRect( hwnd2, NULL);
4289 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
4290 if (winetest_debug > 0) dump_region(hrgn);
4291 SetRectRgn( exprgn, 88,0,98,20);
4292 SetRectRgn( tmprgn, 20,20,98,30);
4293 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4294 SetRectRgn( tmprgn, 20,30,30,88);
4295 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4296 SetRectRgn( tmprgn, 0,88,30,98);
4297 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4298 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4299
4300 /* clean up */
4301 DeleteObject( hrgn);
4302 DeleteObject( exprgn);
4303 DeleteObject( tmprgn);
4304 DestroyWindow( hwnd1);
4305 DestroyWindow( hwnd2);
4306 }
4307
4308 /* couple of tests of return values of scrollbar functions
4309 * called on a scrollbarless window */
4310 static void test_scroll(void)
4311 {
4312 BOOL ret;
4313 INT min, max;
4314 SCROLLINFO si;
4315 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
4316 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
4317 100, 100, 200, 200, 0, 0, 0, NULL);
4318 /* horizontal */
4319 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
4320 if (!ret) /* win9x */
4321 {
4322 win_skip( "GetScrollRange doesn't work\n" );
4323 DestroyWindow( hwnd);
4324 return;
4325 }
4326 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4327 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4328 si.cbSize = sizeof( si);
4329 si.fMask = SIF_PAGE;
4330 si.nPage = 0xdeadbeef;
4331 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
4332 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4333 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4334 /* vertical */
4335 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
4336 ok( ret, "GetScrollRange returns FALSE\n");
4337 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
4338 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
4339 si.cbSize = sizeof( si);
4340 si.fMask = SIF_PAGE;
4341 si.nPage = 0xdeadbeef;
4342 ret = GetScrollInfo( hwnd, SB_VERT, &si);
4343 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
4344 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
4345 /* clean up */
4346 DestroyWindow( hwnd);
4347 }
4348
4349 static void test_scrolldc( HWND parent)
4350 {
4351 HDC hdc;
4352 HRGN exprgn, tmprgn, hrgn;
4353 RECT rc, rc2, rcu, cliprc;
4354 HWND hwnd1;
4355 COLORREF colr;
4356
4357 hrgn = CreateRectRgn(0,0,0,0);
4358 tmprgn = CreateRectRgn(0,0,0,0);
4359 exprgn = CreateRectRgn(0,0,0,0);
4360
4361 hwnd1 = CreateWindowExA(0, "static", NULL,
4362 WS_CHILD| WS_VISIBLE,
4363 25, 50, 100, 100, parent, 0, 0, NULL);
4364 ShowWindow( parent, SW_SHOW);
4365 UpdateWindow( parent);
4366 flush_events( TRUE );
4367 GetClientRect( hwnd1, &rc);
4368 hdc = GetDC( hwnd1);
4369 /* paint the upper half of the window black */
4370 rc2 = rc;
4371 rc2.bottom = ( rc.top + rc.bottom) /2;
4372 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4373 /* clip region is the lower half */
4374 cliprc=rc;
4375 cliprc.top = (rc.top + rc.bottom) /2;
4376 /* test whether scrolled pixels are properly clipped */
4377 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4378 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4379 /* this scroll should not cause any visible changes */
4380 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
4381 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
4382 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4383 /* test with NULL clip rect */
4384 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
4385 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
4386 trace("update rect: %d,%d - %d,%d\n",
4387 rcu.left, rcu.top, rcu.right, rcu.bottom);
4388 if (winetest_debug > 0) dump_region(hrgn);
4389 SetRect(&rc2, 0, 0, 100, 100);
4390 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
4391 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
4392
4393 SetRectRgn( exprgn, 0, 0, 20, 80);
4394 SetRectRgn( tmprgn, 0, 80, 100, 100);
4395 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4396 if (winetest_debug > 0) dump_region(exprgn);
4397 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4398 /* test clip rect > scroll rect */
4399 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
4400 rc2=rc;
4401 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
4402 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4403 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
4404 SetRectRgn( exprgn, 25, 25, 75, 35);
4405 SetRectRgn( tmprgn, 25, 35, 35, 75);
4406 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
4407 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
4408 trace("update rect: %d,%d - %d,%d\n",
4409 rcu.left, rcu.top, rcu.right, rcu.bottom);
4410 if (winetest_debug > 0) dump_region(hrgn);
4411
4412 /* clean up */
4413 DeleteObject(hrgn);
4414 DeleteObject(exprgn);
4415 DeleteObject(tmprgn);
4416 DestroyWindow(hwnd1);
4417 }
4418
4419 static void test_params(void)
4420 {
4421 HWND hwnd;
4422 INT rc;
4423
4424 ok(!IsWindow(0), "IsWindow(0)\n");
4425 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
4426 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
4427
4428 /* Just a param check */
4429 if (pGetMonitorInfoA)
4430 {
4431 SetLastError(0xdeadbeef);
4432 rc = GetWindowTextA(hwndMain2, NULL, 1024);
4433 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
4434 }
4435 else
4436 {
4437 /* Skips actually on Win95 and NT4 */
4438 win_skip("Test would crash on Win95\n");
4439 }
4440
4441 SetLastError(0xdeadbeef);
4442 hwnd=CreateWindowA("LISTBOX", "TestList",
4443 (LBS_STANDARD & ~LBS_SORT),
4444 0, 0, 100, 100,
4445 NULL, (HMENU)1, NULL, 0);
4446
4447 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
4448 "CreateWindow with invalid menu handle should fail\n");
4449 if (!hwnd)
4450 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
4451 GetLastError() == 0xdeadbeef, /* Win9x */
4452 "wrong last error value %d\n", GetLastError());
4453 }
4454
4455 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
4456 {
4457 HWND hwnd = 0;
4458
4459 hwnd = CreateWindowExA(exStyle, class, class, style,
4460 110, 100,
4461 225, 200,
4462 0,
4463 menu ? hmenu : 0,
4464 0, 0);
4465 if (!hwnd) {
4466 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
4467 return;
4468 }
4469 ShowWindow(hwnd, SW_SHOW);
4470
4471 test_nonclient_area(hwnd);
4472
4473 SetMenu(hwnd, 0);
4474 DestroyWindow(hwnd);
4475 }
4476
4477 static BOOL AWR_init(void)
4478 {
4479 WNDCLASSA class;
4480
4481 class.style = CS_HREDRAW | CS_VREDRAW;
4482 class.lpfnWndProc = DefWindowProcA;
4483 class.cbClsExtra = 0;
4484 class.cbWndExtra = 0;
4485 class.hInstance = 0;
4486 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
4487 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4488 class.hbrBackground = 0;
4489 class.lpszMenuName = 0;
4490 class.lpszClassName = szAWRClass;
4491
4492 if (!RegisterClassA(&class)) {
4493 ok(FALSE, "RegisterClass failed\n");
4494 return FALSE;
4495 }
4496
4497 hmenu = CreateMenu();
4498 if (!hmenu)
4499 return FALSE;
4500 ok(hmenu != 0, "Failed to create menu\n");
4501 ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
4502
4503 return TRUE;
4504 }
4505
4506
4507 static void test_AWR_window_size(BOOL menu)
4508 {
4509 LONG styles[] = {
4510 WS_POPUP,
4511 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
4512 WS_SYSMENU,
4513 WS_THICKFRAME,
4514 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
4515 WS_HSCROLL, WS_VSCROLL
4516 };
4517 LONG exStyles[] = {
4518 WS_EX_CLIENTEDGE,
4519 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
4520 WS_EX_APPWINDOW,
4521 #if 0
4522 /* These styles have problems on (at least) WinXP (SP2) and Wine */
4523 WS_EX_DLGMODALFRAME,
4524 WS_EX_STATICEDGE,
4525 #endif
4526 };
4527
4528 int i;
4529
4530 /* A exhaustive check of all the styles takes too long
4531 * so just do a (hopefully representative) sample
4532 */
4533 for (i = 0; i < COUNTOF(styles); ++i)
4534 test_AWRwindow(szAWRClass, styles[i], 0, menu);
4535 for (i = 0; i < COUNTOF(exStyles); ++i) {
4536 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
4537 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
4538 }
4539 }
4540 #undef COUNTOF
4541
4542 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
4543
4544 static void test_AdjustWindowRect(void)
4545 {
4546 if (!AWR_init())
4547 return;
4548
4549 SHOWSYSMETRIC(SM_CYCAPTION);
4550 SHOWSYSMETRIC(SM_CYSMCAPTION);
4551 SHOWSYSMETRIC(SM_CYMENU);
4552 SHOWSYSMETRIC(SM_CXEDGE);
4553 SHOWSYSMETRIC(SM_CYEDGE);
4554 SHOWSYSMETRIC(SM_CXVSCROLL);
4555 SHOWSYSMETRIC(SM_CYHSCROLL);
4556 SHOWSYSMETRIC(SM_CXFRAME);
4557 SHOWSYSMETRIC(SM_CYFRAME);
4558 SHOWSYSMETRIC(SM_CXDLGFRAME);
4559 SHOWSYSMETRIC(SM_CYDLGFRAME);
4560 SHOWSYSMETRIC(SM_CXBORDER);
4561 SHOWSYSMETRIC(SM_CYBORDER);
4562
4563 test_AWR_window_size(FALSE);
4564 test_AWR_window_size(TRUE);
4565
4566 DestroyMenu(hmenu);
4567 }
4568 #undef SHOWSYSMETRIC
4569
4570
4571 /* Global variables to trigger exit from loop */
4572 static int redrawComplete, WMPAINT_count;
4573
4574 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4575 {
4576 switch (msg)
4577 {
4578 case WM_PAINT:
4579 trace("doing WM_PAINT %d\n", WMPAINT_count);
4580 WMPAINT_count++;
4581 if (WMPAINT_count > 10 && redrawComplete == 0) {
4582 PAINTSTRUCT ps;
4583 BeginPaint(hwnd, &ps);
4584 EndPaint(hwnd, &ps);
4585 return 1;
4586 }
4587 return 0;
4588 }
4589 return DefWindowProcA(hwnd, msg, wparam, lparam);
4590 }
4591
4592 /* Ensure we exit from RedrawNow regardless of invalidated area */
4593 static void test_redrawnow(void)
4594 {
4595 WNDCLASSA cls;
4596 HWND hwndMain;
4597
4598 cls.style = CS_DBLCLKS;
4599 cls.lpfnWndProc = redraw_window_procA;
4600 cls.cbClsExtra = 0;
4601 cls.cbWndExtra = 0;
4602 cls.hInstance = GetModuleHandleA(0);
4603 cls.hIcon = 0;
4604 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4605 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4606 cls.lpszMenuName = NULL;
4607 cls.lpszClassName = "RedrawWindowClass";
4608
4609 if(!RegisterClassA(&cls)) {
4610 trace("Register failed %d\n", GetLastError());
4611 return;
4612 }
4613
4614 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4615 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
4616
4617 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4618 ShowWindow(hwndMain, SW_SHOW);
4619 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4620 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
4621 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
4622 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
4623 redrawComplete = TRUE;
4624 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
4625
4626 /* clean up */
4627 DestroyWindow( hwndMain);
4628 }
4629
4630 struct parentdc_stat {
4631 RECT client;
4632 RECT clip;
4633 RECT paint;
4634 };
4635
4636 struct parentdc_test {
4637 struct parentdc_stat main, main_todo;
4638 struct parentdc_stat child1, child1_todo;
4639 struct parentdc_stat child2, child2_todo;
4640 };
4641
4642 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4643 {
4644 RECT rc;
4645 PAINTSTRUCT ps;
4646
4647 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
4648
4649 switch (msg)
4650 {
4651 case WM_PAINT:
4652 GetClientRect(hwnd, &rc);
4653 CopyRect(&t->client, &rc);
4654 GetWindowRect(hwnd, &rc);
4655 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
4656 t->client.left, t->client.top, t->client.right, t->client.bottom,
4657 rc.left, rc.top, rc.right, rc.bottom);
4658 BeginPaint(hwnd, &ps);
4659 CopyRect(&t->paint, &ps.rcPaint);
4660 GetClipBox(ps.hdc, &rc);
4661 CopyRect(&t->clip, &rc);
4662 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
4663 rc.left, rc.top, rc.right, rc.bottom,
4664 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
4665 EndPaint(hwnd, &ps);
4666 return 0;
4667 }
4668 return DefWindowProcA(hwnd, msg, wparam, lparam);
4669 }
4670
4671 static void zero_parentdc_stat(struct parentdc_stat *t)
4672 {
4673 SetRectEmpty(&t->client);
4674 SetRectEmpty(&t->clip);
4675 SetRectEmpty(&t->paint);
4676 }
4677
4678 static void zero_parentdc_test(struct parentdc_test *t)
4679 {
4680 zero_parentdc_stat(&t->main);
4681 zero_parentdc_stat(&t->child1);
4682 zero_parentdc_stat(&t->child2);
4683 }
4684
4685 #define parentdc_field_ok(t, w, r, f, got) \
4686 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
4687 ": expected %d, got %d\n", \
4688 t.w.r.f, got.w.r.f)
4689
4690 #define parentdc_todo_field_ok(t, w, r, f, got) \
4691 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
4692 else parentdc_field_ok(t, w, r, f, got)
4693
4694 #define parentdc_rect_ok(t, w, r, got) \
4695 parentdc_todo_field_ok(t, w, r, left, got); \
4696 parentdc_todo_field_ok(t, w, r, top, got); \
4697 parentdc_todo_field_ok(t, w, r, right, got); \
4698 parentdc_todo_field_ok(t, w, r, bottom, got);
4699
4700 #define parentdc_win_ok(t, w, got) \
4701 parentdc_rect_ok(t, w, client, got); \
4702 parentdc_rect_ok(t, w, clip, got); \
4703 parentdc_rect_ok(t, w, paint, got);
4704
4705 #define parentdc_ok(t, got) \
4706 parentdc_win_ok(t, main, got); \
4707 parentdc_win_ok(t, child1, got); \
4708 parentdc_win_ok(t, child2, got);
4709
4710 static void test_csparentdc(void)
4711 {
4712 WNDCLASSA clsMain, cls;
4713 HWND hwndMain, hwnd1, hwnd2;
4714 RECT rc;
4715
4716 struct parentdc_test test_answer;
4717
4718 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
4719 const struct parentdc_test test1 =
4720 {
4721 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
4722 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4723 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4724 };
4725
4726 const struct parentdc_test test2 =
4727 {
4728 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
4729 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4730 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4731 };
4732
4733 const struct parentdc_test test3 =
4734 {
4735 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4736 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4737 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4738 };
4739
4740 const struct parentdc_test test4 =
4741 {
4742 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
4743 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
4744 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4745 };
4746
4747 const struct parentdc_test test5 =
4748 {
4749 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
4750 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4751 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
4752 };
4753
4754 const struct parentdc_test test6 =
4755 {
4756 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4757 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
4758 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4759 };
4760
4761 const struct parentdc_test test7 =
4762 {
4763 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4764 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
4765 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
4766 };
4767 #undef nothing_todo
4768
4769 clsMain.style = CS_DBLCLKS;
4770 clsMain.lpfnWndProc = parentdc_window_procA;
4771 clsMain.cbClsExtra = 0;
4772 clsMain.cbWndExtra = 0;
4773 clsMain.hInstance = GetModuleHandleA(0);
4774 clsMain.hIcon = 0;
4775 clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4776 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
4777 clsMain.lpszMenuName = NULL;
4778 clsMain.lpszClassName = "ParentDcMainWindowClass";
4779
4780 if(!RegisterClassA(&clsMain)) {
4781 trace("Register failed %d\n", GetLastError());
4782 return;
4783 }
4784
4785 cls.style = CS_DBLCLKS | CS_PARENTDC;
4786 cls.lpfnWndProc = parentdc_window_procA;
4787 cls.cbClsExtra = 0;
4788 cls.cbWndExtra = 0;
4789 cls.hInstance = GetModuleHandleA(0);
4790 cls.hIcon = 0;
4791 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
4792 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4793 cls.lpszMenuName = NULL;
4794 cls.lpszClassName = "ParentDcWindowClass";
4795
4796 if(!RegisterClassA(&cls)) {
4797 trace("Register failed %d\n", GetLastError());
4798 return;
4799 }
4800
4801 SetRect(&rc, 0, 0, 150, 150);
4802 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
4803 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
4804 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
4805 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
4806 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
4807 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
4808 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
4809 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
4810 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
4811 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
4812 ShowWindow(hwndMain, SW_SHOW);
4813 ShowWindow(hwnd1, SW_SHOW);
4814 ShowWindow(hwnd2, SW_SHOW);
4815 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
4816 flush_events( TRUE );
4817
4818 zero_parentdc_test(&test_answer);
4819 InvalidateRect(hwndMain, NULL, TRUE);
4820 flush_events( TRUE );
4821 parentdc_ok(test1, test_answer);
4822
4823 zero_parentdc_test(&test_answer);
4824 SetRect(&rc, 0, 0, 50, 50);
4825 InvalidateRect(hwndMain, &rc, TRUE);
4826 flush_events( TRUE );
4827 parentdc_ok(test2, test_answer);
4828
4829 zero_parentdc_test(&test_answer);
4830 SetRect(&rc, 0, 0, 10, 10);
4831 InvalidateRect(hwndMain, &rc, TRUE);
4832 flush_events( TRUE );
4833 parentdc_ok(test3, test_answer);
4834
4835 zero_parentdc_test(&test_answer);
4836 SetRect(&rc, 40, 40, 50, 50);
4837 InvalidateRect(hwndMain, &rc, TRUE);
4838 flush_events( TRUE );
4839 parentdc_ok(test4, test_answer);
4840
4841 zero_parentdc_test(&test_answer);
4842 SetRect(&rc, 20, 20, 60, 60);
4843 InvalidateRect(hwndMain, &rc, TRUE);
4844 flush_events( TRUE );
4845 parentdc_ok(test5, test_answer);
4846
4847 zero_parentdc_test(&test_answer);
4848 SetRect(&rc, 0, 0, 10, 10);
4849 InvalidateRect(hwnd1, &rc, TRUE);
4850 flush_events( TRUE );
4851 parentdc_ok(test6, test_answer);
4852
4853 zero_parentdc_test(&test_answer);
4854 SetRect(&rc, -5, -5, 65, 65);
4855 InvalidateRect(hwnd1, &rc, TRUE);
4856 flush_events( TRUE );
4857 parentdc_ok(test7, test_answer);
4858
4859 DestroyWindow(hwndMain);
4860 DestroyWindow(hwnd1);
4861 DestroyWindow(hwnd2);
4862 }
4863
4864 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4865 {
4866 return DefWindowProcA(hwnd, msg, wparam, lparam);
4867 }
4868
4869 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4870 {
4871 return DefWindowProcW(hwnd, msg, wparam, lparam);
4872 }
4873
4874 static void test_IsWindowUnicode(void)
4875 {
4876 static const char ansi_class_nameA[] = "ansi class name";
4877 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
4878 static const char unicode_class_nameA[] = "unicode class name";
4879 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
4880 WNDCLASSA classA;
4881 WNDCLASSW classW;
4882 HWND hwnd;
4883 ATOM atom;
4884
4885 memset(&classW, 0, sizeof(classW));
4886 classW.hInstance = GetModuleHandleA(0);
4887 classW.lpfnWndProc = def_window_procW;
4888 classW.lpszClassName = unicode_class_nameW;
4889 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
4890
4891 memset(&classA, 0, sizeof(classA));
4892 classA.hInstance = GetModuleHandleA(0);
4893 classA.lpfnWndProc = def_window_procA;
4894 classA.lpszClassName = ansi_class_nameA;
4895 atom = RegisterClassA(&classA);
4896 assert(atom);
4897
4898 /* unicode class: window proc */
4899 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4900 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4901 assert(hwnd);
4902
4903 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4904 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4905 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4906 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4907 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4908
4909 DestroyWindow(hwnd);
4910
4911 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4912 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4913 assert(hwnd);
4914
4915 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4916 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4917 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4918 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4919 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4920
4921 DestroyWindow(hwnd);
4922
4923 /* ansi class: window proc */
4924 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4925 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4926 assert(hwnd);
4927
4928 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4929 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4930 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4931 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4932 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4933
4934 DestroyWindow(hwnd);
4935
4936 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4937 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4938 assert(hwnd);
4939
4940 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4941 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
4942 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4943 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
4944 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4945
4946 DestroyWindow(hwnd);
4947
4948 /* unicode class: class proc */
4949 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
4950 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4951 assert(hwnd);
4952
4953 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4954 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4955 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4956 /* do not restore class window proc back to unicode */
4957
4958 DestroyWindow(hwnd);
4959
4960 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
4961 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4962 assert(hwnd);
4963
4964 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4965 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4966 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4967
4968 DestroyWindow(hwnd);
4969
4970 /* ansi class: class proc */
4971 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4972 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4973 assert(hwnd);
4974
4975 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4976 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4977 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4978 /* do not restore class window proc back to ansi */
4979
4980 DestroyWindow(hwnd);
4981
4982 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4983 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4984 assert(hwnd);
4985
4986 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4987 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4988 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4989
4990 DestroyWindow(hwnd);
4991 }
4992
4993 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4994 {
4995 MINMAXINFO *minmax;
4996
4997 if (msg != WM_GETMINMAXINFO)
4998 return DefWindowProcA(hwnd, msg, wp, lp);
4999
5000 minmax = (MINMAXINFO *)lp;
5001
5002 if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
5003 {
5004 minmax->ptReserved.x = 0;
5005 minmax->ptReserved.y = 0;
5006 minmax->ptMaxSize.x = 400;
5007 minmax->ptMaxSize.y = 400;
5008 minmax->ptMaxPosition.x = 300;
5009 minmax->ptMaxPosition.y = 300;
5010 minmax->ptMaxTrackSize.x = 200;
5011 minmax->ptMaxTrackSize.y = 200;
5012 minmax->ptMinTrackSize.x = 100;
5013 minmax->ptMinTrackSize.y = 100;
5014 }
5015 else
5016 DefWindowProcA(hwnd, msg, wp, lp);
5017 return 1;
5018 }
5019
5020 static int expected_cx, expected_cy;
5021 static RECT expected_rect, broken_rect;
5022
5023 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5024 {
5025 switch(msg)
5026 {
5027 case WM_GETMINMAXINFO:
5028 {
5029 RECT rect;
5030 GetWindowRect( hwnd, &rect );
5031 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
5032 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
5033 return DefWindowProcA(hwnd, msg, wp, lp);
5034 }
5035 case WM_NCCREATE:
5036 case WM_CREATE:
5037 {
5038 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5039 RECT rect;
5040 GetWindowRect( hwnd, &rect );
5041 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
5042 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
5043 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
5044 "wrong x size %d/%d\n", cs->cx, expected_cx );
5045 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5046 "wrong y size %d/%d\n", cs->cy, expected_cy );
5047 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5048 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5049 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5050 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5051 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5052 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5053 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5054 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5055 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
5056 rect.left, rect.top, rect.right, rect.bottom,
5057 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
5058 return DefWindowProcA(hwnd, msg, wp, lp);
5059 }
5060 case WM_NCCALCSIZE:
5061 {
5062 RECT rect, *r = (RECT *)lp;
5063 GetWindowRect( hwnd, &rect );
5064 ok( !memcmp( &rect, r, sizeof(rect) ),
5065 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
5066 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
5067 return DefWindowProcA(hwnd, msg, wp, lp);
5068 }
5069 default:
5070 return DefWindowProcA(hwnd, msg, wp, lp);
5071 }
5072 }
5073
5074 static void test_CreateWindow(void)
5075 {
5076 WNDCLASSA cls;
5077 HWND hwnd, parent;
5078 HMENU hmenu;
5079 RECT rc, rc_minmax;
5080 MINMAXINFO minmax;
5081 BOOL res;
5082
5083 #define expect_menu(window, menu) \
5084 SetLastError(0xdeadbeef); \
5085 res = (GetMenu(window) == (HMENU)menu); \
5086 ok(res, "GetMenu error %d\n", GetLastError())
5087
5088 #define expect_style(window, style)\
5089 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5090
5091 #define expect_ex_style(window, ex_style)\
5092 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5093
5094 #define expect_gle_broken_9x(gle)\
5095 ok(GetLastError() == gle ||\
5096 broken(GetLastError() == 0xdeadbeef),\
5097 "IsMenu set error %d\n", GetLastError())
5098
5099 hmenu = CreateMenu();
5100 assert(hmenu != 0);
5101 parent = GetDesktopWindow();
5102 assert(parent != 0);
5103
5104 SetLastError(0xdeadbeef);
5105 res = IsMenu(hmenu);
5106 ok(res, "IsMenu error %d\n", GetLastError());
5107
5108 /* WS_CHILD */
5109 SetLastError(0xdeadbeef);
5110 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5111 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5112 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5113 expect_menu(hwnd, 1);
5114 expect_style(hwnd, WS_CHILD);
5115 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5116 DestroyWindow(hwnd);
5117
5118 SetLastError(0xdeadbeef);
5119 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5120 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5121 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5122 expect_menu(hwnd, 1);
5123 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5124 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5125 DestroyWindow(hwnd);
5126
5127 SetLastError(0xdeadbeef);
5128 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
5129 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5130 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5131 expect_menu(hwnd, 1);
5132 expect_style(hwnd, WS_CHILD);
5133 expect_ex_style(hwnd, 0);
5134 DestroyWindow(hwnd);
5135
5136 SetLastError(0xdeadbeef);
5137 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
5138 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5139 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5140 expect_menu(hwnd, 1);
5141 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5142 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5143 DestroyWindow(hwnd);
5144
5145 /* WS_POPUP */
5146 SetLastError(0xdeadbeef);
5147 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5148 0, 0, 100, 100, parent, hmenu, 0, NULL);
5149 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5150 expect_menu(hwnd, hmenu);
5151 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5152 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5153 DestroyWindow(hwnd);
5154 SetLastError(0xdeadbeef);
5155 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5156 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5157
5158 hmenu = CreateMenu();
5159 assert(hmenu != 0);
5160 SetLastError(0xdeadbeef);
5161 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5162 0, 0, 100, 100, parent, hmenu, 0, NULL);
5163 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5164 expect_menu(hwnd, hmenu);
5165 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5166 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5167 DestroyWindow(hwnd);
5168 SetLastError(0xdeadbeef);
5169 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5170 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5171
5172 hmenu = CreateMenu();
5173 assert(hmenu != 0);
5174 SetLastError(0xdeadbeef);
5175 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
5176 0, 0, 100, 100, parent, hmenu, 0, NULL);
5177 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5178 expect_menu(hwnd, hmenu);
5179 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5180 expect_ex_style(hwnd, 0);
5181 DestroyWindow(hwnd);
5182 SetLastError(0xdeadbeef);
5183 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5184 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5185
5186 hmenu = CreateMenu();
5187 assert(hmenu != 0);
5188 SetLastError(0xdeadbeef);
5189 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
5190 0, 0, 100, 100, parent, hmenu, 0, NULL);
5191 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5192 expect_menu(hwnd, hmenu);
5193 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5194 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5195 DestroyWindow(hwnd);
5196 SetLastError(0xdeadbeef);
5197 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5198 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5199
5200 /* WS_CHILD | WS_POPUP */
5201 SetLastError(0xdeadbeef);
5202 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5203 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5204 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5205 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5206 if (hwnd)
5207 DestroyWindow(hwnd);
5208
5209 hmenu = CreateMenu();
5210 assert(hmenu != 0);
5211 SetLastError(0xdeadbeef);
5212 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
5213 0, 0, 100, 100, parent, hmenu, 0, NULL);
5214 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5215 expect_menu(hwnd, hmenu);
5216 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5217 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5218 DestroyWindow(hwnd);
5219 SetLastError(0xdeadbeef);
5220 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5221 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5222
5223 SetLastError(0xdeadbeef);
5224 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5225 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5226 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5227 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5228 if (hwnd)
5229 DestroyWindow(hwnd);
5230
5231 hmenu = CreateMenu();
5232 assert(hmenu != 0);
5233 SetLastError(0xdeadbeef);
5234 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5235 0, 0, 100, 100, parent, hmenu, 0, NULL);
5236 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5237 expect_menu(hwnd, hmenu);
5238 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5239 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5240 DestroyWindow(hwnd);
5241 SetLastError(0xdeadbeef);
5242 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5243 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5244
5245 SetLastError(0xdeadbeef);
5246 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5247 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5248 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5249 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5250 if (hwnd)
5251 DestroyWindow(hwnd);
5252
5253 hmenu = CreateMenu();
5254 assert(hmenu != 0);
5255 SetLastError(0xdeadbeef);
5256 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
5257 0, 0, 100, 100, parent, hmenu, 0, NULL);
5258 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5259 expect_menu(hwnd, hmenu);
5260 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
5261 expect_ex_style(hwnd, 0);
5262 DestroyWindow(hwnd);
5263 SetLastError(0xdeadbeef);
5264 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5265 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5266
5267 SetLastError(0xdeadbeef);
5268 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5269 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5270 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
5271 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5272 if (hwnd)
5273 DestroyWindow(hwnd);
5274
5275 hmenu = CreateMenu();
5276 assert(hmenu != 0);
5277 SetLastError(0xdeadbeef);
5278 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
5279 0, 0, 100, 100, parent, hmenu, 0, NULL);
5280 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5281 expect_menu(hwnd, hmenu);
5282 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5283 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5284 DestroyWindow(hwnd);
5285 SetLastError(0xdeadbeef);
5286 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5287 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5288
5289 /* test child window sizing */
5290 cls.style = 0;
5291 cls.lpfnWndProc = minmax_wnd_proc;
5292 cls.cbClsExtra = 0;
5293 cls.cbWndExtra = 0;
5294 cls.hInstance = GetModuleHandleA(NULL);
5295 cls.hIcon = 0;
5296 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5297 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5298 cls.lpszMenuName = NULL;
5299 cls.lpszClassName = "MinMax_WndClass";
5300 RegisterClassA(&cls);
5301
5302 SetLastError(0xdeadbeef);
5303 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5304 0, 0, 100, 100, 0, 0, 0, NULL);
5305 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5306 expect_menu(parent, 0);
5307 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
5308 expect_ex_style(parent, WS_EX_WINDOWEDGE);
5309
5310 memset(&minmax, 0, sizeof(minmax));
5311 SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5312 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
5313 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
5314 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5315 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
5316
5317 GetWindowRect(parent, &rc);
5318 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
5319 GetClientRect(parent, &rc);
5320 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
5321
5322 InflateRect(&rc, 200, 200);
5323 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
5324
5325 SetLastError(0xdeadbeef);
5326 hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
5327 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
5328 parent, (HMENU)1, 0, NULL);
5329 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5330 expect_menu(hwnd, 1);
5331 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
5332 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5333
5334 memset(&minmax, 0, sizeof(minmax));
5335 SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
5336 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
5337
5338 GetWindowRect(hwnd, &rc);
5339 OffsetRect(&rc, -rc.left, -rc.top);
5340 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
5341 rc.left, rc.top, rc.right, rc.bottom,
5342 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
5343 DestroyWindow(hwnd);
5344
5345 cls.lpfnWndProc = winsizes_wnd_proc;
5346 cls.lpszClassName = "Sizes_WndClass";
5347 RegisterClassA(&cls);
5348
5349 expected_cx = expected_cy = 200000;
5350 SetRect( &expected_rect, 0, 0, 200000, 200000 );
5351 broken_rect = expected_rect;
5352 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
5353 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5354 GetClientRect( hwnd, &rc );
5355 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
5356 "invalid rect right %u\n", rc.right );
5357 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
5358 "invalid rect bottom %u\n", rc.bottom );
5359 DestroyWindow(hwnd);
5360
5361 expected_cx = expected_cy = -10;
5362 SetRect( &expected_rect, 0, 0, 0, 0 );
5363 SetRect( &broken_rect, 0, 0, -10, -10 );
5364 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
5365 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5366 GetClientRect( hwnd, &rc );
5367 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5368 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5369 DestroyWindow(hwnd);
5370
5371 expected_cx = expected_cy = -200000;
5372 SetRect( &expected_rect, 0, 0, 0, 0 );
5373 SetRect( &broken_rect, 0, 0, -200000, -200000 );
5374 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
5375 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5376 GetClientRect( hwnd, &rc );
5377 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
5378 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
5379 DestroyWindow(hwnd);
5380
5381 /* we need a parent at 0,0 so that child coordinates match */
5382 DestroyWindow(parent);
5383 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
5384 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
5385
5386 expected_cx = 100;
5387 expected_cy = 0x7fffffff;
5388 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
5389 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
5390 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
5391 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5392 GetClientRect( hwnd, &rc );
5393 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
5394 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
5395 "invalid rect bottom %u\n", rc.bottom );
5396 DestroyWindow(hwnd);
5397
5398 expected_cx = 0x7fffffff;
5399 expected_cy = 0x7fffffff;
5400 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
5401 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
5402 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
5403 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5404 GetClientRect( hwnd, &rc );
5405 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
5406 "invalid rect right %u\n", rc.right );
5407 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
5408 "invalid rect bottom %u\n", rc.bottom );
5409 DestroyWindow(hwnd);
5410
5411 /* top level window */
5412 expected_cx = expected_cy = 200000;
5413 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
5414 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
5415 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5416 GetClientRect( hwnd, &rc );
5417 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
5418 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
5419 DestroyWindow(hwnd);
5420
5421 if (pGetLayout && pSetLayout)
5422 {
5423 HDC hdc = GetDC( parent );
5424 pSetLayout( hdc, LAYOUT_RTL );
5425 if (pGetLayout( hdc ))
5426 {
5427 ReleaseDC( parent, hdc );
5428 DestroyWindow( parent );
5429 SetLastError( 0xdeadbeef );
5430 parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
5431 0, 0, 100, 100, 0, 0, 0, NULL);
5432 ok( parent != 0, "creation failed err %u\n", GetLastError());
5433 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5434 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5435 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5436 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
5437 DestroyWindow( hwnd );
5438 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
5439 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5440 expect_ex_style( hwnd, 0 );
5441 DestroyWindow( hwnd );
5442 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
5443 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
5444 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5445 expect_ex_style( hwnd, 0 );
5446 DestroyWindow( hwnd );
5447
5448 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
5449 {
5450 DWORD layout;
5451
5452 SetLastError( 0xdeadbeef );
5453 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
5454 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
5455 SetLastError( 0xdeadbeef );
5456 res = pGetProcessDefaultLayout( &layout );
5457 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5458 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
5459 SetLastError( 0xdeadbeef );
5460 res = pSetProcessDefaultLayout( 7 );
5461 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5462 res = pGetProcessDefaultLayout( &layout );
5463 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5464 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
5465 SetLastError( 0xdeadbeef );
5466 res = pSetProcessDefaultLayout( LAYOUT_RTL );
5467 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
5468 res = pGetProcessDefaultLayout( &layout );
5469 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
5470 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
5471 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5472 0, 0, 100, 100, 0, 0, 0, NULL);
5473 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5474 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
5475 DestroyWindow( hwnd );
5476 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5477 0, 0, 100, 100, parent, 0, 0, NULL);
5478 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
5479 expect_ex_style( hwnd, WS_EX_APPWINDOW );
5480 DestroyWindow( hwnd );
5481 pSetProcessDefaultLayout( 0 );
5482 }
5483 else win_skip( "SetProcessDefaultLayout not supported\n" );
5484 }
5485 else win_skip( "SetLayout not supported\n" );
5486 }
5487 else win_skip( "SetLayout not available\n" );
5488
5489 DestroyWindow(parent);
5490
5491 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
5492 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
5493
5494 #undef expect_gle_broken_9x
5495 #undef expect_menu
5496 #undef expect_style
5497 #undef expect_ex_style
5498 }
5499
5500 /* function that remembers whether the system the test is running on sets the
5501 * last error for user32 functions to make the tests stricter */
5502 static int check_error(DWORD actual, DWORD expected)
5503 {
5504 static int sets_last_error = -1;
5505 if (sets_last_error == -1)
5506 sets_last_error = (actual != 0xdeadbeef);
5507 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
5508 }
5509
5510 static void test_SetWindowLong(void)
5511 {
5512 LONG_PTR retval;
5513 WNDPROC old_window_procW;
5514
5515 SetLastError(0xdeadbeef);
5516 retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
5517 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
5518 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
5519 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
5520
5521 SetLastError(0xdeadbeef);
5522 retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
5523 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
5524 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
5525 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
5526
5527 SetLastError(0xdeadbeef);
5528 retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5529 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
5530 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
5531 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5532 retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
5533 ok((WNDPROC)retval == main_window_procA,
5534 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5535 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
5536
5537 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
5538 SetLastError(0xdeadbeef);
5539 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
5540 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
5541 {
5542 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
5543 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
5544 ok((WNDPROC)retval == old_window_procW,
5545 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
5546 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
5547
5548 /* set it back to ANSI */
5549 SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
5550 }
5551 }
5552
5553 static void test_ShowWindow(void)
5554 {
5555 HWND hwnd;
5556 DWORD style;
5557 RECT rcMain, rc, rcMinimized;
5558 LPARAM ret;
5559
5560 SetRect(&rcMain, 120, 120, 210, 210);
5561
5562 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
5563 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5564 WS_MAXIMIZEBOX | WS_POPUP,
5565 rcMain.left, rcMain.top,
5566 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
5567 0, 0, 0, NULL);
5568 assert(hwnd);
5569
5570 style = GetWindowLongA(hwnd, GWL_STYLE);
5571 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5572 ok(!(style & WS_VISIBLE), "window should not be visible\n");
5573 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5574 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5575 GetWindowRect(hwnd, &rc);
5576 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5577 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5578 rc.left, rc.top, rc.right, rc.bottom);
5579
5580 ret = ShowWindow(hwnd, SW_SHOW);
5581 ok(!ret, "not expected ret: %lu\n", ret);
5582 style = GetWindowLongA(hwnd, GWL_STYLE);
5583 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5584 ok(style & WS_VISIBLE, "window should be visible\n");
5585 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5586 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5587 GetWindowRect(hwnd, &rc);
5588 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5589 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5590 rc.left, rc.top, rc.right, rc.bottom);
5591
5592 ret = ShowWindow(hwnd, SW_MINIMIZE);
5593 ok(ret, "not expected ret: %lu\n", ret);
5594 style = GetWindowLongA(hwnd, GWL_STYLE);
5595 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5596 ok(style & WS_VISIBLE, "window should be visible\n");
5597 ok(style & WS_MINIMIZE, "window should be minimized\n");
5598 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5599 GetWindowRect(hwnd, &rcMinimized);
5600 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
5601 /* shouldn't be able to resize minimized windows */
5602 ret = SetWindowPos(hwnd, 0, 0, 0,
5603 (rcMinimized.right - rcMinimized.left) * 2,
5604 (rcMinimized.bottom - rcMinimized.top) * 2,
5605 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
5606 ok(ret, "not expected ret: %lu\n", ret);
5607 GetWindowRect(hwnd, &rc);
5608 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
5609
5610 ShowWindow(hwnd, SW_RESTORE);
5611 ok(ret, "not expected ret: %lu\n", ret);
5612 style = GetWindowLongA(hwnd, GWL_STYLE);
5613 ok(!(style & WS_DISABLED), "window should not be disabled\n");
5614 ok(style & WS_VISIBLE, "window should be visible\n");
5615 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5616 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5617 GetWindowRect(hwnd, &rc);
5618 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5619 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5620 rc.left, rc.top, rc.right, rc.bottom);
5621
5622 ret = EnableWindow(hwnd, FALSE);
5623 ok(!ret, "not expected ret: %lu\n", ret);
5624 style = GetWindowLongA(hwnd, GWL_STYLE);
5625 ok(style & WS_DISABLED, "window should be disabled\n");
5626
5627 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
5628 ok(!ret, "not expected ret: %lu\n", ret);
5629 style = GetWindowLongA(hwnd, GWL_STYLE);
5630 ok(style & WS_DISABLED, "window should be disabled\n");
5631 ok(style & WS_VISIBLE, "window should be visible\n");
5632 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5633 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5634 GetWindowRect(hwnd, &rc);
5635 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5636 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5637 rc.left, rc.top, rc.right, rc.bottom);
5638
5639 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5640 ok(!ret, "not expected ret: %lu\n", ret);
5641 style = GetWindowLongA(hwnd, GWL_STYLE);
5642 ok(style & WS_DISABLED, "window should be disabled\n");
5643 ok(style & WS_VISIBLE, "window should be visible\n");
5644 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5645 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5646 GetWindowRect(hwnd, &rc);
5647 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5648 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5649 rc.left, rc.top, rc.right, rc.bottom);
5650
5651 ret = ShowWindow(hwnd, SW_MINIMIZE);
5652 ok(ret, "not expected ret: %lu\n", ret);
5653 style = GetWindowLongA(hwnd, GWL_STYLE);
5654 ok(style & WS_DISABLED, "window should be disabled\n");
5655 ok(style & WS_VISIBLE, "window should be visible\n");
5656 ok(style & WS_MINIMIZE, "window should be minimized\n");
5657 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5658 GetWindowRect(hwnd, &rc);
5659 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5660
5661 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
5662 ok(!ret, "not expected ret: %lu\n", ret);
5663 style = GetWindowLongA(hwnd, GWL_STYLE);
5664 ok(style & WS_DISABLED, "window should be disabled\n");
5665 ok(style & WS_VISIBLE, "window should be visible\n");
5666 ok(style & WS_MINIMIZE, "window should be minimized\n");
5667 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5668 GetWindowRect(hwnd, &rc);
5669 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
5670
5671 ret = ShowWindow(hwnd, SW_RESTORE);
5672 ok(ret, "not expected ret: %lu\n", ret);
5673 style = GetWindowLongA(hwnd, GWL_STYLE);
5674 ok(style & WS_DISABLED, "window should be disabled\n");
5675 ok(style & WS_VISIBLE, "window should be visible\n");
5676 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
5677 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
5678 GetWindowRect(hwnd, &rc);
5679 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
5680 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
5681 rc.left, rc.top, rc.right, rc.bottom);
5682
5683 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5684 ok(!ret, "not expected ret: %lu\n", ret);
5685 ok(IsWindow(hwnd), "window should exist\n");
5686
5687 ret = EnableWindow(hwnd, TRUE);
5688 ok(ret, "not expected ret: %lu\n", ret);
5689
5690 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
5691 ok(!ret, "not expected ret: %lu\n", ret);
5692 ok(!IsWindow(hwnd), "window should not exist\n");
5693 }
5694
5695 static DWORD CALLBACK gettext_msg_thread( LPVOID arg )
5696 {
5697 HWND hwnd = arg;
5698 char buf[32];
5699 INT buf_len;
5700
5701 /* test GetWindowTextA */
5702 num_gettext_msgs = 0;
5703 memset( buf, 0, sizeof(buf) );
5704 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5705 ok( buf_len != 0, "expected a nonempty window text\n" );
5706 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
5707 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5708
5709 return 0;
5710 }
5711
5712 static DWORD CALLBACK settext_msg_thread( LPVOID arg )
5713 {
5714 HWND hwnd = arg;
5715 BOOL success;
5716
5717 /* test SetWindowTextA */
5718 num_settext_msgs = 0;
5719 success = SetWindowTextA( hwnd, "thread_caption" );
5720 ok( success, "SetWindowTextA failed\n" );
5721 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5722
5723 return 0;
5724 }
5725
5726 static void test_gettext(void)
5727 {
5728 DWORD tid, num_msgs;
5729 HANDLE thread;
5730 BOOL success;
5731 char buf[32];
5732 INT buf_len;
5733 HWND hwnd;
5734 LRESULT r;
5735 MSG msg;
5736
5737 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
5738 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
5739
5740 /* test GetWindowTextA */
5741 num_gettext_msgs = 0;
5742 memset( buf, 0, sizeof(buf) );
5743 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5744 ok( buf_len != 0, "expected a nonempty window text\n" );
5745 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
5746 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5747
5748 /* test WM_GETTEXT */
5749 num_gettext_msgs = 0;
5750 memset( buf, 0, sizeof(buf) );
5751 r = SendMessageA( hwnd, WM_GETTEXT, sizeof(buf), (LONG_PTR)buf );
5752 ok( r != 0, "expected a nonempty window text\n" );
5753 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
5754 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5755
5756 /* test SetWindowTextA */
5757 num_settext_msgs = 0;
5758 success = SetWindowTextA( hwnd, "new_caption" );
5759 ok( success, "SetWindowTextA failed\n" );
5760 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5761
5762 num_gettext_msgs = 0;
5763 memset( buf, 0, sizeof(buf) );
5764 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5765 ok( buf_len != 0, "expected a nonempty window text\n" );
5766 ok( !strcmp(buf, "new_caption"), "got wrong window text '%s'\n", buf );
5767 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5768
5769 /* test WM_SETTEXT */
5770 num_settext_msgs = 0;
5771 r = SendMessageA( hwnd, WM_SETTEXT, 0, (ULONG_PTR)"another_caption" );
5772 ok( r != 0, "WM_SETTEXT failed\n" );
5773 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
5774
5775 num_gettext_msgs = 0;
5776 memset( buf, 0, sizeof(buf) );
5777 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5778 ok( buf_len != 0, "expected a nonempty window text\n" );
5779 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
5780 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5781
5782 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5783 DispatchMessageA( &msg );
5784
5785 /* test interthread GetWindowTextA */
5786 num_msgs = 0;
5787 thread = CreateThread( NULL, 0, gettext_msg_thread, hwnd, 0, &tid );
5788 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
5789 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
5790 {
5791 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5792 DispatchMessageA( &msg );
5793 num_msgs++;
5794 }
5795 CloseHandle( thread );
5796 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
5797
5798 /* test interthread SetWindowText */
5799 num_msgs = 0;
5800 thread = CreateThread( NULL, 0, settext_msg_thread, hwnd, 0, &tid );
5801 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
5802 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
5803 {
5804 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
5805 DispatchMessageA( &msg );
5806 num_msgs++;
5807 }
5808 CloseHandle( thread );
5809 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
5810
5811 num_gettext_msgs = 0;
5812 memset( buf, 0, sizeof(buf) );
5813 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
5814 ok( buf_len != 0, "expected a nonempty window text\n" );
5815 ok( !strcmp(buf, "thread_caption"), "got wrong window text '%s'\n", buf );
5816 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
5817
5818 /* seems to crash on every modern Windows version */
5819 if (0)
5820 {
5821 r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
5822 ok( r == 0, "settext should return zero\n");
5823
5824 r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
5825 ok( r == 0, "settext should return zero (%ld)\n", r);
5826
5827 r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
5828 ok( r == 0, "settext should return zero (%ld)\n", r);
5829
5830 r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
5831 ok( r == 0, "settext should return zero (%ld)\n", r);
5832 }
5833
5834 DestroyWindow(hwnd);
5835 }
5836
5837
5838 static void test_GetUpdateRect(void)
5839 {
5840 MSG msg;
5841 BOOL ret, parent_wm_paint, grandparent_wm_paint;
5842 RECT rc1, rc2;
5843 HWND hgrandparent, hparent, hchild;
5844 WNDCLASSA cls;
5845 static const char classNameA[] = "GetUpdateRectClass";
5846
5847 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
5848 0, 0, 100, 100, NULL, NULL, 0, NULL);
5849
5850 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
5851 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5852
5853 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
5854 10, 10, 30, 30, hparent, NULL, 0, NULL);
5855
5856 ShowWindow(hgrandparent, SW_SHOW);
5857 UpdateWindow(hgrandparent);
5858 flush_events( TRUE );
5859
5860 ShowWindow(hchild, SW_HIDE);
5861 SetRect(&rc2, 0, 0, 0, 0);
5862 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5863 ok(!ret, "GetUpdateRect returned not empty region\n");
5864 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5865 rc1.left, rc1.top, rc1.right, rc1.bottom,
5866 rc2.left, rc2.top, rc2.right, rc2.bottom);
5867
5868 SetRect(&rc2, 10, 10, 40, 40);
5869 ret = GetUpdateRect(hparent, &rc1, FALSE);
5870 ok(ret, "GetUpdateRect returned empty region\n");
5871 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5872 rc1.left, rc1.top, rc1.right, rc1.bottom,
5873 rc2.left, rc2.top, rc2.right, rc2.bottom);
5874
5875 parent_wm_paint = FALSE;
5876 grandparent_wm_paint = FALSE;
5877 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5878 {
5879 if (msg.message == WM_PAINT)
5880 {
5881 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5882 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5883 }
5884 DispatchMessageA(&msg);
5885 }
5886 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5887 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5888
5889 DestroyWindow(hgrandparent);
5890
5891 cls.style = 0;
5892 cls.lpfnWndProc = DefWindowProcA;
5893 cls.cbClsExtra = 0;
5894 cls.cbWndExtra = 0;
5895 cls.hInstance = GetModuleHandleA(0);
5896 cls.hIcon = 0;
5897 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5898 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5899 cls.lpszMenuName = NULL;
5900 cls.lpszClassName = classNameA;
5901
5902 if(!RegisterClassA(&cls)) {
5903 trace("Register failed %d\n", GetLastError());
5904 return;
5905 }
5906
5907 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
5908 0, 0, 100, 100, NULL, NULL, 0, NULL);
5909
5910 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
5911 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
5912
5913 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
5914 10, 10, 30, 30, hparent, NULL, 0, NULL);
5915
5916 ShowWindow(hgrandparent, SW_SHOW);
5917 UpdateWindow(hgrandparent);
5918 flush_events( TRUE );
5919
5920 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5921 ok(!ret, "GetUpdateRect returned not empty region\n");
5922
5923 ShowWindow(hchild, SW_HIDE);
5924
5925 SetRect(&rc2, 0, 0, 0, 0);
5926 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
5927 ok(!ret, "GetUpdateRect returned not empty region\n");
5928 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5929 rc1.left, rc1.top, rc1.right, rc1.bottom,
5930 rc2.left, rc2.top, rc2.right, rc2.bottom);
5931
5932 SetRect(&rc2, 10, 10, 40, 40);
5933 ret = GetUpdateRect(hparent, &rc1, FALSE);
5934 ok(ret, "GetUpdateRect returned empty region\n");
5935 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
5936 rc1.left, rc1.top, rc1.right, rc1.bottom,
5937 rc2.left, rc2.top, rc2.right, rc2.bottom);
5938
5939 parent_wm_paint = FALSE;
5940 grandparent_wm_paint = FALSE;
5941 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
5942 {
5943 if (msg.message == WM_PAINT)
5944 {
5945 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
5946 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
5947 }
5948 DispatchMessageA(&msg);
5949 }
5950 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
5951 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
5952
5953 DestroyWindow(hgrandparent);
5954 }
5955
5956
5957 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5958 {
5959 if(msg == WM_PAINT)
5960 {
5961 PAINTSTRUCT ps;
5962 RECT updateRect;
5963 DWORD waitResult;
5964 HWND win;
5965 const int waitTime = 2000;
5966
5967 BeginPaint(hwnd, &ps);
5968
5969 /* create and destroy window to create an exposed region on this window */
5970 win = CreateWindowA("static", "win", WS_VISIBLE,
5971 10,10,50,50, NULL, NULL, 0, NULL);
5972 DestroyWindow(win);
5973
5974 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
5975
5976 ValidateRect(hwnd, NULL);
5977 EndPaint(hwnd, &ps);
5978
5979 if(waitResult != WAIT_TIMEOUT)
5980 {
5981 GetUpdateRect(hwnd, &updateRect, FALSE);
5982 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
5983 }
5984
5985 return 1;
5986 }
5987 return DefWindowProcA(hwnd, msg, wParam, lParam);
5988 }
5989
5990 static void test_Expose(void)
5991 {
5992 WNDCLASSA cls;
5993 HWND mw;
5994
5995 memset(&cls, 0, sizeof(WNDCLASSA));
5996 cls.lpfnWndProc = TestExposedRegion_WndProc;
5997 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5998 cls.lpszClassName = "TestExposeClass";
5999 RegisterClassA(&cls);
6000
6001 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
6002 0, 0, 200, 100, NULL, NULL, 0, NULL);
6003
6004 UpdateWindow(mw);
6005 DestroyWindow(mw);
6006 }
6007
6008 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6009 {
6010 static UINT ncredrawflags;
6011 PAINTSTRUCT ps;
6012
6013 switch(msg)
6014 {
6015 case WM_CREATE:
6016 ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
6017 return 0;
6018 case WM_NCPAINT:
6019 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
6020 break;
6021 case WM_PAINT:
6022 BeginPaint(hwnd, &ps);
6023 EndPaint(hwnd, &ps);
6024 return 0;
6025 }
6026 return DefWindowProcA(hwnd, msg, wParam, lParam);
6027 }
6028
6029 static void run_NCRedrawLoop(UINT flags)
6030 {
6031 HWND hwnd;
6032 MSG msg;
6033
6034 UINT loopcount = 0;
6035
6036 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
6037 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
6038 NULL, NULL, 0, &flags);
6039 ShowWindow(hwnd, SW_SHOW);
6040 UpdateWindow(hwnd);
6041 flush_events( FALSE );
6042 while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
6043 {
6044 if (msg.message == WM_PAINT) loopcount++;
6045 if (loopcount >= 100) break;
6046 TranslateMessage(&msg);
6047 DispatchMessageA(&msg);
6048 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
6049 }
6050 if (flags == (RDW_INVALIDATE | RDW_FRAME))
6051 todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
6052 else
6053 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
6054 DestroyWindow(hwnd);
6055 }
6056
6057 static void test_NCRedraw(void)
6058 {
6059 WNDCLASSA wndclass;
6060
6061 wndclass.lpszClassName = "TestNCRedrawClass";
6062 wndclass.style = CS_HREDRAW | CS_VREDRAW;
6063 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
6064 wndclass.cbClsExtra = 0;
6065 wndclass.cbWndExtra = 0;
6066 wndclass.hInstance = 0;
6067 wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
6068 wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6069 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
6070 wndclass.lpszMenuName = NULL;
6071
6072 RegisterClassA(&wndclass);
6073
6074 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
6075 run_NCRedrawLoop(RDW_INVALIDATE);
6076 }
6077
6078 static void test_GetWindowModuleFileName(void)
6079 {
6080 HWND hwnd;
6081 HINSTANCE hinst;
6082 UINT ret1, ret2;
6083 char buf1[MAX_PATH], buf2[MAX_PATH];
6084
6085 if (!pGetWindowModuleFileNameA)
6086 {
6087 win_skip("GetWindowModuleFileNameA is not available\n");
6088 return;
6089 }
6090
6091 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
6092 assert(hwnd);
6093
6094 hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
6095 ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
6096
6097 buf1[0] = 0;
6098 SetLastError(0xdeadbeef);
6099 ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
6100 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
6101
6102 buf2[0] = 0;
6103 SetLastError(0xdeadbeef);
6104 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6105 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
6106 "GetWindowModuleFileNameA error %u\n", GetLastError());
6107
6108 if (ret2)
6109 {
6110 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
6111 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
6112 }
6113 hinst = GetModuleHandleA(NULL);
6114
6115 SetLastError(0xdeadbeef);
6116 ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
6117 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
6118 "expected %u, got %u\n", ret1 - 2, ret2);
6119 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6120 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6121 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6122
6123 SetLastError(0xdeadbeef);
6124 ret2 = GetModuleFileNameA(hinst, buf2, 0);
6125 ok(!ret2, "GetModuleFileName should return 0\n");
6126 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6127 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6128 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6129
6130 SetLastError(0xdeadbeef);
6131 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
6132 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
6133 "expected %u, got %u\n", ret1 - 2, ret2);
6134 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6135 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6136 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6137
6138 SetLastError(0xdeadbeef);
6139 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
6140 ok(!ret2, "expected 0, got %u\n", ret2);
6141 ok(GetLastError() == 0xdeadbeef /* XP */ ||
6142 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
6143 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
6144
6145 DestroyWindow(hwnd);
6146
6147 buf2[0] = 0;
6148 hwnd = (HWND)0xdeadbeef;
6149 SetLastError(0xdeadbeef);
6150 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6151 ok(!ret1, "expected 0, got %u\n", ret1);
6152 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
6153 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
6154
6155 hwnd = FindWindowA("Shell_TrayWnd", NULL);
6156 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
6157 SetLastError(0xdeadbeef);
6158 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
6159 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
6160
6161 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
6162 {
6163 ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
6164 hwnd = GetDesktopWindow();
6165 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
6166 SetLastError(0xdeadbeef);
6167 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
6168 ok(!ret2 ||
6169 ret1 == ret2 || /* vista */
6170 broken(ret2), /* some win98 return user.exe as file name */
6171 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
6172 }
6173 }
6174
6175 static void test_hwnd_message(void)
6176 {
6177 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
6178 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
6179
6180 HWND parent = 0, hwnd, found;
6181 RECT rect;
6182
6183 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
6184 on CreateWindowExA and crash later in the test.
6185 Use UNICODE here to fail on win9x */
6186 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
6187 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
6188 if (!hwnd)
6189 {
6190 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
6191 return;
6192 }
6193
6194 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
6195 if (pGetAncestor)
6196 {
6197 char buffer[100];
6198 HWND root, desktop = GetDesktopWindow();
6199
6200 parent = pGetAncestor(hwnd, GA_PARENT);
6201 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
6202 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
6203 root = pGetAncestor(hwnd, GA_ROOT);
6204 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
6205 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
6206 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
6207 trace("parent %p root %p desktop %p\n", parent, root, desktop);
6208 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
6209 ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
6210 GetWindowRect( parent, &rect );
6211 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
6212 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6213 }
6214 GetWindowRect( hwnd, &rect );
6215 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
6216 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
6217
6218 /* test FindWindow behavior */
6219
6220 found = FindWindowExA( 0, 0, 0, "message window" );
6221 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6222 SetLastError(0xdeadbeef);
6223 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
6224 ok( found == 0, "found message window %p/%p\n", found, hwnd );
6225 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
6226 if (parent)
6227 {
6228 found = FindWindowExA( parent, 0, 0, "message window" );
6229 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
6230 }
6231
6232 /* test IsChild behavior */
6233
6234 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
6235
6236 /* test IsWindowVisible behavior */
6237
6238 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
6239 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
6240
6241 DestroyWindow(hwnd);
6242 }
6243
6244 static void test_layered_window(void)
6245 {
6246 HWND hwnd;
6247 COLORREF key = 0;
6248 BYTE alpha = 0;
6249 DWORD flags = 0;
6250 POINT pt = { 0, 0 };
6251 SIZE sz = { 200, 200 };
6252 HDC hdc;
6253 HBITMAP hbm;
6254 BOOL ret;
6255
6256 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
6257 {
6258 win_skip( "layered windows not supported\n" );
6259 return;
6260 }
6261
6262 hdc = CreateCompatibleDC( 0 );
6263 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
6264 SelectObject( hdc, hbm );
6265
6266 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
6267 100, 100, 200, 200, 0, 0, 0, NULL);
6268 assert( hwnd );
6269 SetLastError( 0xdeadbeef );
6270 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6271 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6272 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6273 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6274 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
6275 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
6276 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
6277 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6278 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6279 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6280 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6281 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6282 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6283 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6284 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
6285 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6286 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6287 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6288 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
6289 ok( alpha == 44, "wrong alpha %u\n", alpha );
6290 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
6291 SetLastError( 0xdeadbeef );
6292 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6293 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6294 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6295
6296 /* clearing WS_EX_LAYERED resets attributes */
6297 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6298 SetLastError( 0xdeadbeef );
6299 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6300 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
6301 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6302 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
6303 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6304 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6305 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
6306 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6307 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
6308 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
6309 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
6310 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6311 if (pUpdateLayeredWindowIndirect)
6312 {
6313 UPDATELAYEREDWINDOWINFO info;
6314 info.cbSize = sizeof(info);
6315 info.hdcDst = 0;
6316 info.pptDst = NULL;
6317 info.psize = &sz;
6318 info.hdcSrc = hdc;
6319 info.pptSrc = &pt;
6320 info.crKey = 0;
6321 info.pblend = NULL;
6322 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
6323 info.prcDirty = NULL;
6324 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6325 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6326 sz.cx--;
6327 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6328 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6329 ok( GetLastError() == ERROR_INCORRECT_SIZE || broken(GetLastError() == ERROR_MR_MID_NOT_FOUND),
6330 "wrong error %u\n", GetLastError() );
6331 info.dwFlags = ULW_OPAQUE;
6332 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6333 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
6334 sz.cx++;
6335 info.dwFlags = ULW_OPAQUE | 0xf00;
6336 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6337 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6338 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6339 info.cbSize--;
6340 info.dwFlags = ULW_OPAQUE;
6341 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
6342 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6343 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6344 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
6345 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
6346 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
6347 }
6348
6349 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
6350 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6351 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6352 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6353 ok( key == 0x654321, "wrong color key %x\n", key );
6354 ok( alpha == 22, "wrong alpha %u\n", alpha );
6355 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
6356 SetLastError( 0xdeadbeef );
6357 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
6358 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
6359 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
6360
6361 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
6362 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6363 alpha = 0;
6364 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6365 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6366 ok( key == 0x888888, "wrong color key %x\n", key );
6367 /* alpha not changed on vista if LWA_ALPHA is not set */
6368 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
6369 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
6370
6371 /* color key may or may not be changed without LWA_COLORKEY */
6372 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
6373 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6374 alpha = 0;
6375 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6376 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6377 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
6378 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
6379 ok( flags == 0, "wrong flags %x\n", flags );
6380
6381 /* default alpha and color key is 0 */
6382 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
6383 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
6384 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
6385 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
6386 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
6387 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
6388 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
6389 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
6390 ok( flags == 0, "wrong flags %x\n", flags );
6391
6392 DestroyWindow( hwnd );
6393 DeleteDC( hdc );
6394 DeleteObject( hbm );
6395 }
6396
6397 static MONITORINFO mi;
6398
6399 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
6400 {
6401 switch (msg)
6402 {
6403 case WM_NCCREATE:
6404 {
6405 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
6406 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
6407 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
6408 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
6409 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6410 cs->x, cs->y, cs->cx, cs->cy);
6411 break;
6412 }
6413 case WM_GETMINMAXINFO:
6414 {
6415 MINMAXINFO *minmax = (MINMAXINFO *)lp;
6416 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
6417 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
6418 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
6419 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
6420 break;
6421 }
6422 }
6423 return DefWindowProcA(hwnd, msg, wp, lp);
6424 }
6425
6426 static void test_fullscreen(void)
6427 {
6428 static const DWORD t_style[] = {
6429 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
6430 };
6431 static const DWORD t_ex_style[] = {
6432 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
6433 };
6434 WNDCLASSA cls;
6435 HWND hwnd;
6436 int i, j;
6437 POINT pt;
6438 RECT rc;
6439 HMONITOR hmon;
6440 LRESULT ret;
6441
6442 if (!pGetMonitorInfoA || !pMonitorFromPoint)
6443 {
6444 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
6445 return;
6446 }
6447
6448 pt.x = pt.y = 0;
6449 SetLastError(0xdeadbeef);
6450 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
6451 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
6452
6453 mi.cbSize = sizeof(mi);
6454 SetLastError(0xdeadbeef);
6455 ret = pGetMonitorInfoA(hmon, &mi);
6456 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
6457 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
6458 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6459 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6460
6461 cls.style = 0;
6462 cls.lpfnWndProc = fullscreen_wnd_proc;
6463 cls.cbClsExtra = 0;
6464 cls.cbWndExtra = 0;
6465 cls.hInstance = GetModuleHandleA(NULL);
6466 cls.hIcon = 0;
6467 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6468 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6469 cls.lpszMenuName = NULL;
6470 cls.lpszClassName = "fullscreen_class";
6471 RegisterClassA(&cls);
6472
6473 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
6474 {
6475 DWORD style, ex_style;
6476
6477 /* avoid a WM interaction */
6478 assert(!(t_style[i] & WS_VISIBLE));
6479
6480 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
6481 {
6482 int fixup;
6483
6484 style = t_style[i];
6485 ex_style = t_ex_style[j];
6486
6487 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6488 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6489 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6490 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6491 GetWindowRect(hwnd, &rc);
6492 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6493 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6494 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6495 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6496 DestroyWindow(hwnd);
6497
6498 style = t_style[i] | WS_MAXIMIZE;
6499 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6500 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6501 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6502 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6503 GetWindowRect(hwnd, &rc);
6504 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6505 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6506 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6507 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6508 DestroyWindow(hwnd);
6509
6510 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
6511 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6512 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6513 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6514 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6515 GetWindowRect(hwnd, &rc);
6516 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6517 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6518 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6519 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6520 DestroyWindow(hwnd);
6521
6522 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
6523 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6524 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6525 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6526 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6527 GetWindowRect(hwnd, &rc);
6528 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6529 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6530 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6531 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6532 DestroyWindow(hwnd);
6533
6534 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
6535 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6536 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6537 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6538 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6539 GetWindowRect(hwnd, &rc);
6540 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6541 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6542 fixup = min(abs(rc.left), abs(rc.top));
6543 InflateRect(&rc, -fixup, -fixup);
6544 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6545 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6546 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
6547 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
6548 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
6549 DestroyWindow(hwnd);
6550
6551 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
6552 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
6553 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
6554 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
6555 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
6556 GetWindowRect(hwnd, &rc);
6557 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6558 /* Windows makes a maximized window slightly larger (to hide the borders?) */
6559 fixup = min(abs(rc.left), abs(rc.top));
6560 InflateRect(&rc, -fixup, -fixup);
6561 if (style & (WS_CHILD | WS_POPUP))
6562 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
6563 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
6564 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6565 else
6566 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
6567 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
6568 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
6569 DestroyWindow(hwnd);
6570 }
6571 }
6572
6573 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
6574 }
6575
6576 static BOOL test_thick_child_got_minmax;
6577 static const char * test_thick_child_name;
6578 static LONG test_thick_child_style;
6579 static LONG test_thick_child_exStyle;
6580
6581 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
6582 {
6583 MINMAXINFO* minmax;
6584 int expectedMinTrackX;
6585 int expectedMinTrackY;
6586 int actualMinTrackX;
6587 int actualMinTrackY;
6588 int expectedMaxTrackX;
6589 int expectedMaxTrackY;
6590 int actualMaxTrackX;
6591 int actualMaxTrackY;
6592 int expectedMaxSizeX;
6593 int expectedMaxSizeY;
6594 int actualMaxSizeX;
6595 int actualMaxSizeY;
6596 int expectedPosX;
6597 int expectedPosY;
6598 int actualPosX;
6599 int actualPosY;
6600 LONG adjustedStyle;
6601 RECT rect;
6602 switch (msg)
6603 {
6604 case WM_GETMINMAXINFO:
6605 {
6606 minmax = (MINMAXINFO *)lparam;
6607 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
6608 dump_minmax_info( minmax );
6609
6610 test_thick_child_got_minmax = TRUE;
6611
6612
6613 adjustedStyle = test_thick_child_style;
6614 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6615 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6616 GetClientRect(GetParent(hwnd), &rect);
6617 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
6618
6619 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6620 {
6621 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
6622 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
6623 }
6624 else
6625 {
6626 expectedMinTrackX = -2 * rect.left;
6627 expectedMinTrackY = -2 * rect.top;
6628 }
6629 actualMinTrackX = minmax->ptMinTrackSize.x;
6630 actualMinTrackY = minmax->ptMinTrackSize.y;
6631
6632 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
6633 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
6634 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
6635 test_thick_child_name);
6636
6637 actualMaxTrackX = minmax->ptMaxTrackSize.x;
6638 actualMaxTrackY = minmax->ptMaxTrackSize.y;
6639 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
6640 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
6641 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
6642 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
6643 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
6644 test_thick_child_name);
6645
6646 expectedMaxSizeX = rect.right - rect.left;
6647 expectedMaxSizeY = rect.bottom - rect.top;
6648 actualMaxSizeX = minmax->ptMaxSize.x;
6649 actualMaxSizeY = minmax->ptMaxSize.y;
6650
6651 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
6652 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
6653 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
6654 test_thick_child_name);
6655
6656
6657 expectedPosX = rect.left;
6658 expectedPosY = rect.top;
6659 actualPosX = minmax->ptMaxPosition.x;
6660 actualPosY = minmax->ptMaxPosition.y;
6661 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
6662 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
6663 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
6664
6665 break;
6666 }
6667 }
6668
6669 return DefWindowProcA(hwnd, msg, wparam, lparam);
6670 }
6671
6672 #define NUMBER_OF_THICK_CHILD_TESTS 16
6673 static void test_thick_child_size(HWND parentWindow)
6674 {
6675 BOOL success;
6676 RECT childRect;
6677 RECT adjustedParentRect;
6678 HWND childWindow;
6679 LONG childWidth;
6680 LONG childHeight;
6681 LONG expectedWidth;
6682 LONG expectedHeight;
6683 WNDCLASSA cls;
6684 static const char className[] = "THICK_CHILD_CLASS";
6685 int i;
6686 LONG adjustedStyle;
6687 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
6688 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6689 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6690 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6691 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6692 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6693 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6694 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6695 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6696 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6697 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6698 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6699 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6700 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
6701 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
6702 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
6703 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
6704 };
6705
6706 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
6707 0,
6708 0,
6709 0,
6710 0,
6711 WS_EX_DLGMODALFRAME,
6712 WS_EX_DLGMODALFRAME,
6713 WS_EX_DLGMODALFRAME,
6714 WS_EX_DLGMODALFRAME,
6715 WS_EX_STATICEDGE,
6716 WS_EX_STATICEDGE,
6717 WS_EX_STATICEDGE,
6718 WS_EX_STATICEDGE,
6719 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6720 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6721 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6722 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
6723 };
6724 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
6725 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
6726 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
6727 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
6728 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
6729 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
6730 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
6731 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6732 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
6733 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
6734 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
6735 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6736 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
6737 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6738 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6739 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6740 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
6741 };
6742
6743 cls.style = 0;
6744 cls.lpfnWndProc = test_thick_child_size_winproc;
6745 cls.cbClsExtra = 0;
6746 cls.cbWndExtra = 0;
6747 cls.hInstance = GetModuleHandleA(0);
6748 cls.hIcon = 0;
6749 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6750 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6751 cls.lpszMenuName = NULL;
6752 cls.lpszClassName = className;
6753 SetLastError(0xdeadbeef);
6754 success = RegisterClassA(&cls);
6755 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
6756
6757 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
6758 {
6759 test_thick_child_name = styleName[i];
6760 test_thick_child_style = styles[i];
6761 test_thick_child_exStyle = exStyles[i];
6762 test_thick_child_got_minmax = FALSE;
6763
6764 SetLastError(0xdeadbeef);
6765 childWindow = CreateWindowExA( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
6766 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
6767
6768 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
6769
6770 SetLastError(0xdeadbeef);
6771 success = GetWindowRect(childWindow, &childRect);
6772 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
6773 childWidth = childRect.right - childRect.left;
6774 childHeight = childRect.bottom - childRect.top;
6775
6776 adjustedStyle = styles[i];
6777 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
6778 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
6779 GetClientRect(GetParent(childWindow), &adjustedParentRect);
6780 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
6781
6782
6783 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
6784 {
6785 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
6786 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
6787 }
6788 else
6789 {
6790 expectedWidth = -2 * adjustedParentRect.left;
6791 expectedHeight = -2 * adjustedParentRect.top;
6792 }
6793
6794 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
6795 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
6796 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
6797
6798 SetLastError(0xdeadbeef);
6799 success = DestroyWindow(childWindow);
6800 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
6801 }
6802 ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
6803 }
6804
6805 static void test_handles( HWND full_hwnd )
6806 {
6807 HWND hwnd = full_hwnd;
6808 BOOL ret;
6809 RECT rect;
6810
6811 SetLastError( 0xdeadbeef );
6812 ret = GetWindowRect( hwnd, &rect );
6813 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6814
6815 #ifdef _WIN64
6816 if ((ULONG_PTR)full_hwnd >> 32)
6817 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
6818 else
6819 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
6820 SetLastError( 0xdeadbeef );
6821 ret = GetWindowRect( hwnd, &rect );
6822 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6823
6824 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
6825 SetLastError( 0xdeadbeef );
6826 ret = GetWindowRect( hwnd, &rect );
6827 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
6828
6829 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
6830 SetLastError( 0xdeadbeef );
6831 ret = GetWindowRect( hwnd, &rect );
6832 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6833 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6834
6835 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
6836 SetLastError( 0xdeadbeef );
6837 ret = GetWindowRect( hwnd, &rect );
6838 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
6839 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
6840 #endif
6841 }
6842
6843 static void test_winregion(void)
6844 {
6845 HWND hwnd;
6846 RECT r;
6847 int ret, width;
6848 HRGN hrgn;
6849
6850 if (!pGetWindowRgnBox)
6851 {
6852 win_skip("GetWindowRgnBox not supported\n");
6853 return;
6854 }
6855
6856 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
6857 /* NULL prect */
6858 SetLastError(0xdeadbeef);
6859 ret = pGetWindowRgnBox(hwnd, NULL);
6860 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6861 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6862
6863 hrgn = CreateRectRgn(2, 3, 10, 15);
6864 ok( hrgn != NULL, "Region creation failed\n");
6865 if (hrgn)
6866 {
6867 SetWindowRgn(hwnd, hrgn, FALSE);
6868
6869 SetLastError(0xdeadbeef);
6870 ret = pGetWindowRgnBox(hwnd, NULL);
6871 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
6872 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
6873
6874 r.left = r.top = r.right = r.bottom = 0;
6875 ret = pGetWindowRgnBox(hwnd, &r);
6876 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
6877 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
6878 "Expected (2,3,10,15), got (%d,%d,%d,%d)\n", r.left, r.top,
6879 r.right, r.bottom);
6880 if (pMirrorRgn)
6881 {
6882 hrgn = CreateRectRgn(2, 3, 10, 15);
6883 ret = pMirrorRgn( hwnd, hrgn );
6884 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
6885 r.left = r.top = r.right = r.bottom = 0;
6886 GetWindowRect( hwnd, &r );
6887 width = r.right - r.left;
6888 r.left = r.top = r.right = r.bottom = 0;
6889 ret = GetRgnBox( hrgn, &r );
6890 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
6891 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
6892 "Wrong rectangle (%d,%d,%d,%d) for width %d\n", r.left, r.top, r.right, r.bottom, width );
6893 }
6894 else win_skip( "MirrorRgn not supported\n" );
6895 }
6896 DestroyWindow(hwnd);
6897 }
6898
6899 static void test_rtl_layout(void)
6900 {
6901 HWND parent, child;
6902 RECT r;
6903 POINT pt;
6904
6905 if (!pSetProcessDefaultLayout)
6906 {
6907 win_skip( "SetProcessDefaultLayout not supported\n" );
6908 return;
6909 }
6910
6911 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
6912 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
6913
6914 GetWindowRect( parent, &r );
6915 ok( r.left == 100 && r.right == 400, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6916 GetClientRect( parent, &r );
6917 ok( r.left == 0 && r.right == 300, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6918 GetClientRect( child, &r );
6919 ok( r.left == 0 && r.right == 20, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6920 MapWindowPoints( child, parent, (POINT *)&r, 2 );
6921 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6922 GetWindowRect( child, &r );
6923 ok( r.left == 370 && r.right == 390, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6924 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6925 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6926 GetWindowRect( child, &r );
6927 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
6928 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
6929 ok( r.left == 30 && r.right == 10, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6930 pt.x = pt.y = 12;
6931 MapWindowPoints( child, parent, &pt, 1 );
6932 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
6933 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6934 GetWindowRect( parent, &r );
6935 ok( r.left == 100 && r.right == 350, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6936 GetWindowRect( child, &r );
6937 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6938 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
6939 GetWindowRect( child, &r );
6940 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6941 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6942 ok( r.left == 220 && r.right == 240, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6943 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
6944 GetWindowRect( child, &r );
6945 ok( r.left == 320 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6946 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6947 ok( r.left == 10 && r.right == 30, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6948 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
6949 GetWindowRect( child, &r );
6950 ok( r.left == 310 && r.right == 340, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6951 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
6952 ok( r.left == 10 && r.right == 40, "wrong rect %d,%d - %d,%d\n", r.left, r.top, r.right, r.bottom );
6953 DestroyWindow( child );
6954 DestroyWindow( parent );
6955 }
6956
6957 static void test_FlashWindowEx(void)
6958 {
6959 HWND hwnd;
6960 FLASHWINFO finfo;
6961 BOOL prev, ret;
6962
6963 if (!pFlashWindowEx)
6964 {
6965 win_skip( "FlashWindowEx not supported\n" );
6966 return;
6967 }
6968
6969 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
6970 0, 0, 0, 0, 0, 0, 0, NULL );
6971 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6972
6973 finfo.cbSize = sizeof(FLASHWINFO);
6974 finfo.dwFlags = FLASHW_TIMER;
6975 finfo.uCount = 3;
6976 finfo.dwTimeout = 200;
6977 finfo.hwnd = NULL;
6978 SetLastError(0xdeadbeef);
6979 ret = pFlashWindowEx(&finfo);
6980 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
6981 "FlashWindowEx returned with %d\n", GetLastError());
6982
6983 finfo.hwnd = hwnd;
6984 SetLastError(0xdeadbeef);
6985 ret = pFlashWindowEx(NULL);
6986 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
6987 "FlashWindowEx returned with %d\n", GetLastError());
6988
6989 SetLastError(0xdeadbeef);
6990 ret = pFlashWindowEx(&finfo);
6991 todo_wine ok(!ret, "previous window state should not be active\n");
6992
6993 finfo.cbSize = sizeof(FLASHWINFO) - 1;
6994 SetLastError(0xdeadbeef);
6995 ret = pFlashWindowEx(&finfo);
6996 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
6997 "FlashWindowEx succeeded\n");
6998
6999 finfo.cbSize = sizeof(FLASHWINFO) + 1;
7000 SetLastError(0xdeadbeef);
7001 ret = pFlashWindowEx(&finfo);
7002 todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
7003 "FlashWindowEx succeeded\n");
7004 finfo.cbSize = sizeof(FLASHWINFO);
7005
7006 DestroyWindow( hwnd );
7007
7008 SetLastError(0xdeadbeef);
7009 ret = pFlashWindowEx(&finfo);
7010 todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7011 "FlashWindowEx returned with %d\n", GetLastError());
7012
7013 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
7014 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
7015 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
7016 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
7017 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
7018
7019 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
7020 0, 0, 0, 0, 0, 0, 0, NULL );
7021 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7022 finfo.hwnd = hwnd;
7023
7024 SetLastError(0xdeadbeef);
7025 ret = pFlashWindowEx(NULL);
7026 todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
7027 "FlashWindowEx returned with %d\n", GetLastError());
7028
7029 SetLastError(0xdeadbeef);
7030 prev = pFlashWindowEx(&finfo);
7031
7032 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
7033 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
7034 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
7035 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
7036 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
7037
7038 finfo.dwFlags = FLASHW_STOP;
7039 SetLastError(0xdeadbeef);
7040 ret = pFlashWindowEx(&finfo);
7041 todo_wine
7042 ok(prev != ret, "previous window state should be different\n");
7043
7044 DestroyWindow( hwnd );
7045 }
7046
7047 static void test_FindWindowEx(void)
7048 {
7049 HWND hwnd, found;
7050
7051 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
7052 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7053
7054 num_gettext_msgs = 0;
7055 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
7056 ok( found == NULL, "expected a NULL hwnd\n" );
7057 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7058
7059 num_gettext_msgs = 0;
7060 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
7061 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7062 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7063
7064 num_gettext_msgs = 0;
7065 found = FindWindowExA( 0, 0, "MainWindowClass", "caption" );
7066 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7067 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7068
7069 DestroyWindow( hwnd );
7070
7071 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
7072 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7073
7074 num_gettext_msgs = 0;
7075 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
7076 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7077 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7078
7079 num_gettext_msgs = 0;
7080 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
7081 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
7082 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
7083
7084 DestroyWindow( hwnd );
7085
7086 /* test behaviour with a window title that is an empty character */
7087 found = FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
7088 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
7089 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
7090 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
7091 }
7092
7093 static void test_GetLastActivePopup(void)
7094 {
7095 HWND hwndOwner, hwndPopup1, hwndPopup2;
7096
7097 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
7098 WS_VISIBLE | WS_POPUPWINDOW,
7099 100, 100, 200, 200,
7100 NULL, 0, GetModuleHandleA(NULL), NULL);
7101 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
7102 WS_VISIBLE | WS_POPUPWINDOW,
7103 100, 100, 200, 200,
7104 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
7105 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
7106 WS_VISIBLE | WS_POPUPWINDOW,
7107 100, 100, 200, 200,
7108 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
7109 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
7110 DestroyWindow( hwndPopup2 );
7111 DestroyWindow( hwndPopup1 );
7112 DestroyWindow( hwndOwner );
7113 }
7114
7115 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7116 {
7117 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
7118 return DefWindowProcA(hwnd, msg, wp, lp);
7119 }
7120
7121 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7122 {
7123 return DefWindowProcA(hwnd, msg, wp, lp);
7124 }
7125
7126 static void create_window_tree(HWND parent, HWND *window, int size)
7127 {
7128 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
7129 int i, pos;
7130
7131 memset(window, 0, size * sizeof(window[0]));
7132
7133 pos = 0;
7134 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
7135 {
7136 assert(pos < size);
7137 window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
7138 0, 0, 100, 100, parent, 0, 0, NULL);
7139 ok(window[pos] != 0, "CreateWindowEx failed\n");
7140 pos++;
7141 assert(pos < size);
7142 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
7143 0, 0, 100, 100, parent, 0, 0, NULL);
7144 ok(window[pos] != 0, "CreateWindowEx failed\n");
7145 pos++;
7146
7147 assert(pos < size);
7148 window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
7149 0, 0, 100, 100, parent, 0, 0, NULL);
7150 ok(window[pos] != 0, "CreateWindowEx failed\n");
7151 pos++;
7152 assert(pos < size);
7153 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
7154 0, 0, 100, 100, parent, 0, 0, NULL);
7155 ok(window[pos] != 0, "CreateWindowEx failed\n");
7156 pos++;
7157
7158 assert(pos < size);
7159 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7160 0, 0, 100, 100, parent, 0, 0, NULL);
7161 ok(window[pos] != 0, "CreateWindowEx failed\n");
7162 pos++;
7163 assert(pos < size);
7164 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7165 0, 0, 100, 100, parent, 0, 0, NULL);
7166 ok(window[pos] != 0, "CreateWindowEx failed\n");
7167 pos++;
7168 assert(pos < size);
7169 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7170 0, 0, 100, 100, parent, 0, 0, NULL);
7171 ok(window[pos] != 0, "CreateWindowEx failed\n");
7172 pos++;
7173 assert(pos < size);
7174 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7175 0, 0, 100, 100, parent, 0, 0, NULL);
7176 ok(window[pos] != 0, "CreateWindowEx failed\n");
7177 pos++;
7178
7179 assert(pos < size);
7180 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7181 0, 0, 100, 100, parent, 0, 0, NULL);
7182 ok(window[pos] != 0, "CreateWindowEx failed\n");
7183 pos++;
7184 assert(pos < size);
7185 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
7186 0, 0, 100, 100, parent, 0, 0, NULL);
7187 ok(window[pos] != 0, "CreateWindowEx failed\n");
7188 pos++;
7189 assert(pos < size);
7190 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7191 0, 0, 100, 100, parent, 0, 0, NULL);
7192 ok(window[pos] != 0, "CreateWindowEx failed\n");
7193 pos++;
7194 assert(pos < size);
7195 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
7196 0, 0, 100, 100, parent, 0, 0, NULL);
7197 ok(window[pos] != 0, "CreateWindowEx failed\n");
7198 pos++;
7199
7200 assert(pos < size);
7201 window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
7202 0, 0, 100, 100, parent, 0, 0, NULL);
7203 ok(window[pos] != 0, "CreateWindowEx failed\n");
7204 pos++;
7205 assert(pos < size);
7206 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
7207 0, 0, 100, 100, parent, 0, 0, NULL);
7208 ok(window[pos] != 0, "CreateWindowEx failed\n");
7209 pos++;
7210 }
7211 }
7212
7213 struct window_attributes
7214 {
7215 char class_name[128];
7216 BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
7217 };
7218
7219 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
7220 {
7221 DWORD style, ex_style, hittest;
7222
7223 style = GetWindowLongA(hwnd, GWL_STYLE);
7224 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
7225 attrs->class_name[0] = 0;
7226 GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
7227 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
7228
7229 attrs->is_visible = (style & WS_VISIBLE) != 0;
7230 attrs->is_enabled = (style & WS_DISABLED) == 0;
7231 attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
7232 attrs->is_httransparent = hittest == HTTRANSPARENT;
7233 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
7234 }
7235
7236 static int window_to_index(HWND hwnd, HWND *window, int size)
7237 {
7238 int i;
7239
7240 for (i = 0; i < size; i++)
7241 {
7242 if (!window[i]) break;
7243 if (window[i] == hwnd) return i;
7244 }
7245 return -1;
7246 }
7247
7248 static void test_child_window_from_point(void)
7249 {
7250 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
7251 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
7252 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
7253 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
7254 WNDCLASSA cls;
7255 HWND hwnd, parent, window[100];
7256 POINT pt;
7257 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
7258 int ret, i;
7259
7260 ret = GetClassInfoA(0, "Button", &cls);
7261 ok(ret, "GetClassInfo(Button) failed\n");
7262 cls.lpszClassName = "my_button";
7263 ret = RegisterClassA(&cls);
7264 ok(ret, "RegisterClass(my_button) failed\n");
7265
7266 cls.lpszClassName = "my_httrasparent";
7267 cls.lpfnWndProc = my_httrasparent_proc;
7268 ret = RegisterClassA(&cls);
7269 ok(ret, "RegisterClass(my_httrasparent) failed\n");
7270
7271 cls.lpszClassName = "my_window";
7272 cls.lpfnWndProc = my_window_proc;
7273 ret = RegisterClassA(&cls);
7274 ok(ret, "RegisterClass(my_window) failed\n");
7275
7276 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7277 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
7278 100, 100, 200, 200,
7279 0, 0, GetModuleHandleA(NULL), NULL);
7280 ok(parent != 0, "CreateWindowEx failed\n");
7281 trace("parent %p\n", parent);
7282
7283 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
7284
7285 found_invisible = 0;
7286 found_disabled = 0;
7287 found_groupbox = 0;
7288 found_httransparent = 0;
7289 found_extransparent = 0;
7290
7291 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
7292 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
7293 {
7294 struct window_attributes attrs;
7295
7296 pt.x = pt.y = 50;
7297 hwnd = RealChildWindowFromPoint(parent, pt);
7298 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
7299 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
7300 /* FIXME: remove once Wine is fixed */
7301 if (ret != real_child_pos[i])
7302 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);
7303 else
7304 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
7305
7306 get_window_attributes(hwnd, &attrs);
7307 if (!attrs.is_visible) found_invisible++;
7308 if (!attrs.is_enabled) found_disabled++;
7309 if (attrs.is_groupbox) found_groupbox++;
7310 if (attrs.is_httransparent) found_httransparent++;
7311 if (attrs.is_extransparent) found_extransparent++;
7312
7313 if (ret != real_child_pos[i] && ret != -1)
7314 {
7315 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7316 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7317 get_window_attributes(window[real_child_pos[i]], &attrs);
7318 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
7319 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
7320 }
7321 if (ret == -1)
7322 {
7323 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
7324 break;
7325 }
7326 DestroyWindow(hwnd);
7327 }
7328
7329 DestroyWindow(parent);
7330
7331 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
7332 ok(found_disabled, "found %d disabled windows\n", found_disabled);
7333 todo_wine
7334 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
7335 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
7336 todo_wine
7337 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
7338
7339 ret = UnregisterClassA("my_button", cls.hInstance);
7340 ok(ret, "UnregisterClass(my_button) failed\n");
7341 ret = UnregisterClassA("my_httrasparent", cls.hInstance);
7342 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
7343 ret = UnregisterClassA("my_window", cls.hInstance);
7344 ok(ret, "UnregisterClass(my_window) failed\n");
7345 }
7346
7347 static void simulate_click(int x, int y)
7348 {
7349 INPUT input[2];
7350 UINT events_no;
7351
7352 SetCursorPos(x, y);
7353 memset(input, 0, sizeof(input));
7354 input[0].type = INPUT_MOUSE;
7355 U(input[0]).mi.dx = x;
7356 U(input[0]).mi.dy = y;
7357 U(input[0]).mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
7358 input[1].type = INPUT_MOUSE;
7359 U(input[1]).mi.dx = x;
7360 U(input[1]).mi.dy = y;
7361 U(input[1]).mi.dwFlags = MOUSEEVENTF_LEFTUP;
7362 events_no = SendInput(2, input, sizeof(input[0]));
7363 ok(events_no == 2, "SendInput returned %d\n", events_no);
7364 }
7365
7366 static WNDPROC def_static_proc;
7367 static BOOL got_hittest;
7368 static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7369 {
7370 if(msg == WM_NCHITTEST)
7371 got_hittest = TRUE;
7372 if(msg == WM_LBUTTONDOWN)
7373 ok(0, "unexpected call\n");
7374
7375 return def_static_proc(hwnd, msg, wp, lp);
7376 }
7377
7378 static void window_from_point_proc(HWND parent)
7379 {
7380 HANDLE start_event, end_event;
7381 HANDLE win, child_static, child_button;
7382 BOOL got_click;
7383 DWORD ret;
7384 POINT pt;
7385 MSG msg;
7386
7387 start_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_start");
7388 ok(start_event != 0, "OpenEvent failed\n");
7389 end_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_end");
7390 ok(end_event != 0, "OpenEvent failed\n");
7391
7392 child_static = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
7393 0, 0, 100, 100, parent, 0, NULL, NULL);
7394 ok(child_static != 0, "CreateWindowEx failed\n");
7395 pt.x = pt.y = 150;
7396 win = WindowFromPoint(pt);
7397 ok(win == parent, "WindowFromPoint returned %p, expected %p\n", win, parent);
7398
7399 child_button = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7400 100, 0, 100, 100, parent, 0, NULL, NULL);
7401 ok(child_button != 0, "CreateWindowEx failed\n");
7402 pt.x = 250;
7403 win = WindowFromPoint(pt);
7404 ok(win == child_button, "WindowFromPoint returned %p, expected %p\n", win, child_button);
7405
7406 /* without this window simulate click test keeps sending WM_NCHITTEST
7407 * message to child_static in an infinite loop */
7408 win = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7409 0, 0, 100, 100, parent, 0, NULL, NULL);
7410 ok(win != 0, "CreateWindowEx failed\n");
7411 def_static_proc = (void*)SetWindowLongPtrA(child_static,
7412 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
7413 flush_events(TRUE);
7414 SetEvent(start_event);
7415
7416 got_hittest = FALSE;
7417 got_click = FALSE;
7418 while(!got_click && wait_for_message(&msg)) {
7419 if(msg.message == WM_LBUTTONUP) {
7420 ok(msg.hwnd == win, "msg.hwnd = %p, expected %p\n", msg.hwnd, win);
7421 got_click = TRUE;
7422 }
7423 DispatchMessageA(&msg);
7424 }
7425 ok(got_hittest, "transparent window didn't get WM_NCHITTEST message\n");
7426 ok(got_click, "button under static window didn't get WM_LBUTTONUP\n");
7427
7428 ret = WaitForSingleObject(end_event, 5000);
7429 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %x\n", ret);
7430
7431 CloseHandle(start_event);
7432 CloseHandle(end_event);
7433 }
7434
7435 static void test_window_from_point(const char *argv0)
7436 {
7437 HWND hwnd, child, win;
7438 POINT pt;
7439 PROCESS_INFORMATION info;
7440 STARTUPINFOA startup;
7441 char cmd[MAX_PATH];
7442 HANDLE start_event, end_event;
7443
7444 hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP | WS_VISIBLE,
7445 100, 100, 200, 100, 0, 0, NULL, NULL);
7446 ok(hwnd != 0, "CreateWindowEx failed\n");
7447
7448 pt.x = pt.y = 150;
7449 win = WindowFromPoint(pt);
7450 pt.x = 250;
7451 if(win == hwnd)
7452 win = WindowFromPoint(pt);
7453 if(win != hwnd) {
7454 skip("there's another window covering test window\n");
7455 DestroyWindow(hwnd);
7456 return;
7457 }
7458
7459 child = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
7460 0, 0, 100, 100, hwnd, 0, NULL, NULL);
7461 ok(child != 0, "CreateWindowEx failed\n");
7462 pt.x = pt.y = 150;
7463 win = WindowFromPoint(pt);
7464 ok(win == hwnd, "WindowFromPoint returned %p, expected %p\n", win, hwnd);
7465 DestroyWindow(child);
7466
7467 child = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
7468 0, 0, 100, 100, hwnd, 0, NULL, NULL);
7469 ok(child != 0, "CreateWindowEx failed\n");
7470 win = WindowFromPoint(pt);
7471 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7472 DestroyWindow(child);
7473
7474 start_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_start");
7475 ok(start_event != 0, "CreateEvent failed\n");
7476 end_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_end");
7477 ok(start_event != 0, "CreateEvent failed\n");
7478
7479 sprintf(cmd, "%s win create_children %p\n", argv0, hwnd);
7480 memset(&startup, 0, sizeof(startup));
7481 startup.cb = sizeof(startup);
7482 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
7483 &startup, &info), "CreateProcess failed.\n");
7484 ok(wait_for_event(start_event, 1000), "didn't get start_event\n");
7485
7486 child = GetWindow(hwnd, GW_CHILD);
7487 win = WindowFromPoint(pt);
7488 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7489
7490 simulate_click(150, 150);
7491 flush_events(TRUE);
7492
7493 child = GetWindow(child, GW_HWNDNEXT);
7494 pt.x = 250;
7495 win = WindowFromPoint(pt);
7496 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
7497
7498 SetEvent(end_event);
7499 winetest_wait_child_process(info.hProcess);
7500 CloseHandle(start_event);
7501 CloseHandle(end_event);
7502 CloseHandle(info.hProcess);
7503 CloseHandle(info.hThread);
7504
7505 DestroyWindow(hwnd);
7506 }
7507
7508 static void test_map_points(void)
7509 {
7510 BOOL ret;
7511 POINT p;
7512 HWND wnd, wnd0, dwnd;
7513 INT n;
7514 DWORD err;
7515 POINT pos = { 100, 200 };
7516 int width = 150;
7517 int height = 150;
7518 RECT window_rect;
7519 RECT client_rect;
7520
7521 /* Create test windows */
7522 wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
7523 ok(wnd != NULL, "Failed %p\n", wnd);
7524 wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
7525 ok(wnd0 != NULL, "Failed %p\n", wnd);
7526 dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
7527 DestroyWindow(dwnd);
7528 ok(dwnd != NULL, "Failed %p\n", dwnd);
7529
7530 /* Verify window rect and client rect (they should have the same width and height) */
7531 GetWindowRect(wnd, &window_rect);
7532 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
7533 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
7534 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
7535 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
7536 GetClientRect(wnd, &client_rect);
7537 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
7538 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
7539 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
7540 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
7541
7542 /* Test MapWindowPoints */
7543
7544 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
7545
7546 SetLastError(0xdeadbeef);
7547 n = MapWindowPoints(NULL, NULL, NULL, 0);
7548 err = GetLastError();
7549 ok(n == 0, "Got %d, expected %d\n", n, 0);
7550 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7551
7552 SetLastError(0xdeadbeef);
7553 n = MapWindowPoints(wnd, wnd, NULL, 0);
7554 err = GetLastError();
7555 ok(n == 0, "Got %d, expected %d\n", n, 0);
7556 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7557
7558 n = MapWindowPoints(wnd, NULL, NULL, 0);
7559 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7560 n, MAKELONG(window_rect.left, window_rect.top));
7561
7562 n = MapWindowPoints(NULL, wnd, NULL, 0);
7563 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7564 n, MAKELONG(-window_rect.left, -window_rect.top));
7565
7566 SetLastError(0xdeadbeef);
7567 p.x = p.y = 100;
7568 n = MapWindowPoints(dwnd, NULL, &p, 1);
7569 err = GetLastError();
7570 ok(n == 0, "Got %d, expected %d\n", n, 0);
7571 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7572 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7573
7574 SetLastError(0xdeadbeef);
7575 p.x = p.y = 100;
7576 n = MapWindowPoints(dwnd, wnd, &p, 1);
7577 err = GetLastError();
7578 ok(n == 0, "Got %d, expected %d\n", n, 0);
7579 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7580 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7581
7582 SetLastError(0xdeadbeef);
7583 p.x = p.y = 100;
7584 n = MapWindowPoints(NULL, dwnd, &p, 1);
7585 err = GetLastError();
7586 ok(n == 0, "Got %d, expected %d\n", n, 0);
7587 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7588 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7589
7590 SetLastError(0xdeadbeef);
7591 p.x = p.y = 100;
7592 n = MapWindowPoints(wnd, dwnd, &p, 1);
7593 err = GetLastError();
7594 ok(n == 0, "Got %d, expected %d\n", n, 0);
7595 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7596 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7597
7598 SetLastError(0xdeadbeef);
7599 p.x = p.y = 100;
7600 n = MapWindowPoints(dwnd, dwnd, &p, 1);
7601 err = GetLastError();
7602 ok(n == 0, "Got %d, expected %d\n", n, 0);
7603 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7604 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7605
7606 SetLastError(0xdeadbeef);
7607 p.x = p.y = 100;
7608 n = MapWindowPoints(NULL, NULL, &p, 1);
7609 err = GetLastError();
7610 ok(n == 0, "Got %d, expected %d\n", n, 0);
7611 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7612 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7613
7614 SetLastError(0xdeadbeef);
7615 p.x = p.y = 100;
7616 n = MapWindowPoints(wnd, wnd, &p, 1);
7617 err = GetLastError();
7618 ok(n == 0, "Got %d, expected %d\n", n, 0);
7619 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7620 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7621
7622 p.x = p.y = 100;
7623 n = MapWindowPoints(wnd, NULL, &p, 1);
7624 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
7625 n, MAKELONG(window_rect.left, window_rect.top));
7626 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7627 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7628
7629 p.x = p.y = 100;
7630 n = MapWindowPoints(NULL, wnd, &p, 1);
7631 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
7632 n, MAKELONG(-window_rect.left, -window_rect.top));
7633 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7634 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7635
7636 SetLastError(0xdeadbeef);
7637 p.x = p.y = 0;
7638 n = MapWindowPoints(wnd0, NULL, &p, 1);
7639 err = GetLastError();
7640 ok(n == 0, "Got %x, expected 0\n", n);
7641 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7642 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7643
7644 SetLastError(0xdeadbeef);
7645 p.x = p.y = 0;
7646 n = MapWindowPoints(NULL, wnd0, &p, 1);
7647 err = GetLastError();
7648 ok(n == 0, "Got %x, expected 0\n", n);
7649 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7650 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
7651
7652 /* Test ClientToScreen */
7653
7654 /* ClientToScreen(wnd, NULL); crashes on Windows */
7655
7656 SetLastError(0xdeadbeef);
7657 ret = ClientToScreen(NULL, NULL);
7658 err = GetLastError();
7659 ok(!ret, "Should fail\n");
7660 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7661
7662 SetLastError(0xdeadbeef);
7663 p.x = p.y = 100;
7664 ret = ClientToScreen(NULL, &p);
7665 err = GetLastError();
7666 ok(!ret, "Should fail\n");
7667 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7668 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7669
7670 SetLastError(0xdeadbeef);
7671 p.x = p.y = 100;
7672 ret = ClientToScreen(dwnd, &p);
7673 err = GetLastError();
7674 ok(!ret, "Should fail\n");
7675 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7676 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7677
7678 p.x = p.y = 100;
7679 ret = ClientToScreen(wnd, &p);
7680 ok(ret, "Failed with error %u\n", GetLastError());
7681 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
7682 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
7683
7684 p.x = p.y = 0;
7685 ret = ClientToScreen(wnd0, &p);
7686 ok(ret, "Failed with error %u\n", GetLastError());
7687 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7688
7689 /* Test ScreenToClient */
7690
7691 /* ScreenToClient(wnd, NULL); crashes on Windows */
7692
7693 SetLastError(0xdeadbeef);
7694 ret = ScreenToClient(NULL, NULL);
7695 err = GetLastError();
7696 ok(!ret, "Should fail\n");
7697 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7698
7699 SetLastError(0xdeadbeef);
7700 p.x = p.y = 100;
7701 ret = ScreenToClient(NULL, &p);
7702 err = GetLastError();
7703 ok(!ret, "Should fail\n");
7704 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7705 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7706
7707 SetLastError(0xdeadbeef);
7708 p.x = p.y = 100;
7709 ret = ScreenToClient(dwnd, &p);
7710 err = GetLastError();
7711 ok(!ret, "Should fail\n");
7712 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
7713 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
7714
7715 p.x = p.y = 100;
7716 ret = ScreenToClient(wnd, &p);
7717 ok(ret, "Failed with error %u\n", GetLastError());
7718 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
7719 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
7720
7721 p.x = p.y = 0;
7722 ret = ScreenToClient(wnd0, &p);
7723 ok(ret, "Failed with error %u\n", GetLastError());
7724 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
7725
7726 DestroyWindow(wnd);
7727 DestroyWindow(wnd0);
7728 }
7729
7730 static void test_update_region(void)
7731 {
7732 HWND hwnd, parent, child;
7733 HRGN rgn1, rgn2;
7734 const RECT rc = {15, 15, 40, 40};
7735 const POINT wnd_orig = {30, 20};
7736 const POINT child_orig = {10, 5};
7737
7738 parent = CreateWindowExA(0, "MainWindowClass", NULL,
7739 WS_VISIBLE | WS_CLIPCHILDREN,
7740 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
7741 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
7742 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
7743 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
7744 child = CreateWindowExA(0, "MainWindowClass", NULL,
7745 WS_VISIBLE | WS_CHILD,
7746 child_orig.x, child_orig.y, 100, 50,
7747 hwnd, NULL, GetModuleHandleA(0), 0);
7748 assert(parent && hwnd && child);
7749
7750 ValidateRgn(parent, NULL);
7751 ValidateRgn(hwnd, NULL);
7752 InvalidateRect(hwnd, &rc, FALSE);
7753 ValidateRgn(child, NULL);
7754
7755 rgn1 = CreateRectRgn(0, 0, 0, 0);
7756 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
7757 "has invalid area after ValidateRgn(NULL)\n");
7758 GetUpdateRgn(hwnd, rgn1, FALSE);
7759 rgn2 = CreateRectRgnIndirect(&rc);
7760 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
7761 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
7762 "has invalid area after ValidateRgn(NULL)\n");
7763
7764 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
7765 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
7766
7767 /* parent now has non-simple update region, it consist of
7768 * two rects, that was exposed after hwnd moving ... */
7769 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
7770 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
7771 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7772 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
7773 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
7774 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
7775 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
7776 GetUpdateRgn(parent, rgn2, FALSE);
7777 todo_wine
7778 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7779
7780 /* hwnd has the same invalid region as before moving */
7781 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
7782 GetUpdateRgn(hwnd, rgn2, FALSE);
7783 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7784
7785 /* hwnd's invalid area maps to child during moving */
7786 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
7787 rc.right - child_orig.x, rc.bottom - child_orig.y);
7788 GetUpdateRgn(child, rgn2, FALSE);
7789 todo_wine
7790 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
7791
7792 DeleteObject(rgn1);
7793 DeleteObject(rgn2);
7794 DestroyWindow(parent);
7795 }
7796
7797 static void test_window_without_child_style(void)
7798 {
7799 HWND hwnd;
7800
7801 hwnd = CreateWindowExA(0, "edit", NULL, WS_VISIBLE|WS_CHILD,
7802 0, 0, 50, 50, hwndMain, NULL, 0, NULL);
7803 ok(hwnd != NULL, "CreateWindow failed\n");
7804
7805 ok(SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & (~WS_CHILD)),
7806 "can't remove WS_CHILD style\n");
7807
7808 SetActiveWindow(hwndMain);
7809 PostMessageW(hwnd, WM_LBUTTONUP, 0, 0);
7810 SendMessageW(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
7811 check_active_state(hwnd, hwnd, hwnd);
7812 flush_events(TRUE);
7813
7814 DestroyWindow(hwnd);
7815 }
7816
7817
7818 struct smresult_thread_data
7819 {
7820 HWND main_hwnd;
7821 HWND thread_hwnd;
7822 HANDLE thread_started;
7823 HANDLE thread_got_wm_app;
7824 HANDLE main_in_wm_app_1;
7825 HANDLE thread_replied;
7826 };
7827
7828
7829 static LRESULT WINAPI smresult_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
7830 {
7831 switch (msg)
7832 {
7833 case WM_APP:
7834 {
7835 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7836
7837 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
7838
7839 SendNotifyMessageA(data->main_hwnd, WM_APP+1, 0, lparam);
7840
7841 /* Don't return until the main thread is processing our sent message. */
7842 ok(WaitForSingleObject(data->main_in_wm_app_1, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7843
7844 /* Break the PeekMessage loop so we can notify the main thread after we return. */
7845 SetEvent(data->thread_got_wm_app);
7846
7847 return 0x240408ea;
7848 }
7849 case WM_APP+1:
7850 {
7851 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7852 LRESULT res;
7853
7854 ok(hwnd == data->main_hwnd, "unexpected hwnd %p\n", hwnd);
7855
7856 /* Ask the thread to reply to our WM_APP message. */
7857 SetEvent(data->main_in_wm_app_1);
7858
7859 /* Wait until the thread has sent a reply. */
7860 ok(WaitForSingleObject(data->thread_replied, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7861
7862 /* Send another message while we have a reply queued for the current one. */
7863 res = SendMessageA(data->thread_hwnd, WM_APP+2, 0, lparam);
7864 ok(res == 0x449b0190, "unexpected result %lx\n", res);
7865
7866 return 0;
7867 }
7868 case WM_APP+2:
7869 {
7870 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
7871
7872 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
7873
7874 /* Don't return until we know the main thread is processing sent messages. */
7875 SendMessageA(data->main_hwnd, WM_NULL, 0, 0);
7876
7877 return 0x449b0190;
7878 }
7879 case WM_CLOSE:
7880 PostQuitMessage(0);
7881 break;
7882 }
7883 return DefWindowProcA(hwnd, msg, wparam, lparam);
7884 }
7885
7886 static DWORD WINAPI smresult_thread_proc(void *param)
7887 {
7888 MSG msg;
7889 struct smresult_thread_data *data = param;
7890
7891 data->thread_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
7892 100, 100, 200, 200, 0, 0, 0, NULL);
7893 ok(data->thread_hwnd != 0, "Failed to create overlapped window\n");
7894
7895 SetEvent(data->thread_started);
7896
7897 /* Loop until we've processed WM_APP. */
7898 while (WaitForSingleObject(data->thread_got_wm_app, 0) != WAIT_OBJECT_0)
7899 {
7900 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
7901 {
7902 TranslateMessage(&msg);
7903 DispatchMessageA(&msg);
7904 }
7905 else
7906 {
7907 MsgWaitForMultipleObjects(1, &data->thread_got_wm_app, FALSE, INFINITE, QS_SENDMESSAGE);
7908 }
7909 }
7910
7911 /* Notify the main thread that we replied to its WM_APP message. */
7912 SetEvent(data->thread_replied);
7913
7914 while (GetMessageA(&msg, 0, 0, 0))
7915 {
7916 TranslateMessage(&msg);
7917 DispatchMessageA(&msg);
7918 }
7919
7920 return 0;
7921 }
7922
7923 static void test_smresult(void)
7924 {
7925 WNDCLASSA cls;
7926 HANDLE hThread;
7927 DWORD tid;
7928 struct smresult_thread_data data;
7929 BOOL ret;
7930 LRESULT res;
7931
7932 cls.style = CS_DBLCLKS;
7933 cls.lpfnWndProc = smresult_wndproc;
7934 cls.cbClsExtra = 0;
7935 cls.cbWndExtra = 0;
7936 cls.hInstance = GetModuleHandleA(0);
7937 cls.hIcon = 0;
7938 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7939 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7940 cls.lpszMenuName = NULL;
7941 cls.lpszClassName = "SmresultClass";
7942
7943 ret = RegisterClassA(&cls);
7944 ok(ret, "RegisterClassA failed\n");
7945
7946 data.thread_started = CreateEventA(NULL, TRUE, FALSE, NULL);
7947 ok(data.thread_started != NULL, "CreateEventA failed\n");
7948
7949 data.thread_got_wm_app = CreateEventA(NULL, TRUE, FALSE, NULL);
7950 ok(data.thread_got_wm_app != NULL, "CreateEventA failed\n");
7951
7952 data.main_in_wm_app_1 = CreateEventA(NULL, TRUE, FALSE, NULL);
7953 ok(data.main_in_wm_app_1 != NULL, "CreateEventA failed\n");
7954
7955 data.thread_replied = CreateEventA(NULL, TRUE, FALSE, NULL);
7956 ok(data.thread_replied != NULL, "CreateEventA failed\n");
7957
7958 data.main_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
7959 100, 100, 200, 200, 0, 0, 0, NULL);
7960
7961 hThread = CreateThread(NULL, 0, smresult_thread_proc, &data, 0, &tid);
7962 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
7963
7964 ok(WaitForSingleObject(data.thread_started, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7965
7966 res = SendMessageA(data.thread_hwnd, WM_APP, 0, (LPARAM)&data);
7967 ok(res == 0x240408ea, "unexpected result %lx\n", res);
7968
7969 SendMessageA(data.thread_hwnd, WM_CLOSE, 0, 0);
7970
7971 DestroyWindow(data.main_hwnd);
7972
7973 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
7974
7975 CloseHandle(data.thread_started);
7976 CloseHandle(data.thread_got_wm_app);
7977 CloseHandle(data.main_in_wm_app_1);
7978 CloseHandle(data.thread_replied);
7979 }
7980
7981 static void test_GetMessagePos(void)
7982 {
7983 HWND button;
7984 DWORD pos;
7985 MSG msg;
7986
7987 button = CreateWindowExA(0, "button", "button", WS_VISIBLE,
7988 100, 100, 100, 100, 0, 0, 0, NULL);
7989 ok(button != 0, "CreateWindowExA failed\n");
7990
7991 SetCursorPos(120, 140);
7992 flush_events(TRUE);
7993 pos = GetMessagePos();
7994 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
7995
7996 SetCursorPos(340, 320);
7997 pos = GetMessagePos();
7998 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
7999
8000 SendMessageW(button, WM_APP, 0, 0);
8001 pos = GetMessagePos();
8002 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8003
8004 PostMessageA(button, WM_APP, 0, 0);
8005 GetMessageA(&msg, button, 0, 0);
8006 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8007 pos = GetMessagePos();
8008 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8009
8010 PostMessageA(button, WM_APP, 0, 0);
8011 SetCursorPos(350, 330);
8012 GetMessageA(&msg, button, 0, 0);
8013 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8014 pos = GetMessagePos();
8015 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8016
8017 PostMessageA(button, WM_APP, 0, 0);
8018 SetCursorPos(320, 340);
8019 PostMessageA(button, WM_APP+1, 0, 0);
8020 pos = GetMessagePos();
8021 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8022 GetMessageA(&msg, button, 0, 0);
8023 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8024 pos = GetMessagePos();
8025 ok(pos == MAKELONG(350, 330), "pos = %08x\n", pos);
8026 GetMessageA(&msg, button, 0, 0);
8027 ok(msg.message == WM_APP+1, "msg.message = %x\n", msg.message);
8028 pos = GetMessagePos();
8029 ok(pos == MAKELONG(320, 340), "pos = %08x\n", pos);
8030
8031 SetTimer(button, 1, 250, NULL);
8032 SetCursorPos(330, 350);
8033 GetMessageA(&msg, button, 0, 0);
8034 while (msg.message == WM_PAINT)
8035 {
8036 UpdateWindow( button );
8037 GetMessageA(&msg, button, 0, 0);
8038 }
8039 ok(msg.message == WM_TIMER, "msg.message = %x\n", msg.message);
8040 pos = GetMessagePos();
8041 ok(pos == MAKELONG(330, 350), "pos = %08x\n", pos);
8042 KillTimer(button, 1);
8043
8044 DestroyWindow(button);
8045 }
8046
8047 START_TEST(win)
8048 {
8049 char **argv;
8050 int argc = winetest_get_mainargs( &argv );
8051 HMODULE user32 = GetModuleHandleA( "user32.dll" );
8052 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
8053 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
8054 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
8055 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
8056 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
8057 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
8058 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
8059 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
8060 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
8061 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
8062 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
8063 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
8064 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
8065 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
8066 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
8067 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
8068 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
8069 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
8070
8071 if (argc==4 && !strcmp(argv[2], "create_children"))
8072 {
8073 HWND hwnd;
8074
8075 sscanf(argv[3], "%p", &hwnd);
8076 window_from_point_proc(hwnd);
8077 return;
8078 }
8079
8080 if (!RegisterWindowClasses()) assert(0);
8081
8082 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
8083 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
8084 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
8085 100, 100, 200, 200,
8086 0, 0, GetModuleHandleA(NULL), NULL);
8087 assert( hwndMain );
8088
8089 if(!SetForegroundWindow(hwndMain)) {
8090 /* workaround for foreground lock timeout */
8091 simulate_click(101, 101);
8092 ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
8093 }
8094
8095 SetLastError(0xdeafbeef);
8096 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
8097 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
8098
8099 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
8100 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
8101
8102 /* make sure that these tests are executed first */
8103 test_FindWindowEx();
8104 test_SetParent();
8105
8106 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
8107 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
8108 WS_MAXIMIZEBOX | WS_POPUP,
8109 100, 100, 200, 200,
8110 0, 0, GetModuleHandleA(NULL), NULL);
8111 assert( hwndMain2 );
8112
8113 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
8114
8115 /* Add the tests below this line */
8116 test_child_window_from_point();
8117 test_window_from_point(argv[0]);
8118 test_thick_child_size(hwndMain);
8119 test_fullscreen();
8120 test_hwnd_message();
8121 test_nonclient_area(hwndMain);
8122 test_params();
8123 test_GetWindowModuleFileName();
8124 test_capture_1();
8125 test_capture_2();
8126 test_capture_3(hwndMain, hwndMain2);
8127 test_capture_4();
8128 test_rtl_layout();
8129 test_FlashWindowEx();
8130
8131 test_CreateWindow();
8132 test_parent_owner();
8133 test_enum_thread_windows();
8134
8135 test_mdi();
8136 test_icons();
8137 test_SetWindowPos(hwndMain, hwndMain2);
8138 test_SetMenu(hwndMain);
8139 test_SetFocus(hwndMain);
8140 test_SetActiveWindow(hwndMain);
8141 test_NCRedraw();
8142
8143 test_children_zorder(hwndMain);
8144 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
8145 test_popup_zorder(hwndMain2, hwndMain, 0);
8146 test_GetLastActivePopup();
8147 test_keyboard_input(hwndMain);
8148 test_mouse_input(hwndMain);
8149 test_validatergn(hwndMain);
8150 test_nccalcscroll( hwndMain);
8151 test_scrollwindow( hwndMain);
8152 test_scrollvalidate( hwndMain);
8153 test_scrolldc( hwndMain);
8154 test_scroll();
8155 test_IsWindowUnicode();
8156 test_vis_rgn(hwndMain);
8157
8158 test_AdjustWindowRect();
8159 test_window_styles();
8160 test_dialog_styles();
8161 test_redrawnow();
8162 test_csparentdc();
8163 test_SetWindowLong();
8164 test_ShowWindow();
8165 test_gettext();
8166 test_GetUpdateRect();
8167 test_Expose();
8168 test_layered_window();
8169
8170 test_SetForegroundWindow(hwndMain);
8171 test_shell_window();
8172 test_handles( hwndMain );
8173 test_winregion();
8174 test_map_points();
8175 test_update_region();
8176 test_window_without_child_style();
8177 test_smresult();
8178 test_GetMessagePos();
8179
8180 /* add the tests above this line */
8181 if (hhook) UnhookWindowsHookEx(hhook);
8182
8183 DestroyWindow(hwndMain2);
8184 DestroyWindow(hwndMain);
8185 }