7b34dc17c8feffc8ec63e04bf3fedfcb2fc1d7bc
[reactos.git] / modules / 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 #ifndef WM_SYSTIMER
43 #define WM_SYSTIMER 0x0118
44 #endif
45
46 #define LONG_PTR INT_PTR
47 #define ULONG_PTR UINT_PTR
48
49 void dump_region(HRGN hrgn);
50
51 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
52 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
53 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
54 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
55 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
56 static BOOL (WINAPI *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
57 static BOOL (WINAPI *pUpdateLayeredWindowIndirect)(HWND,const UPDATELAYEREDWINDOWINFO*);
58 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
59 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
60 static int (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
61 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
62 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
63 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
64 static BOOL (WINAPI *pFlashWindow)( HWND hwnd, BOOL bInvert );
65 static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
66 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
67 static DWORD (WINAPI *pGetLayout)(HDC hdc);
68 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
69
70 static BOOL test_lbuttondown_flag;
71 static DWORD num_gettext_msgs;
72 static DWORD num_settext_msgs;
73 static HWND hwndMessage;
74 static HWND hwndMain, hwndMain2;
75 static HHOOK hhook;
76 static BOOL app_activated, app_deactivated;
77
78 static const char* szAWRClass = "Winsize";
79 static HMENU hmenu;
80 static DWORD our_pid;
81
82 static BOOL is_win9x = FALSE;
83
84 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
85
86 static void dump_minmax_info( const MINMAXINFO *minmax )
87 {
88 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
89 minmax->ptReserved.x, minmax->ptReserved.y,
90 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
91 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
92 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
93 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
94 }
95
96 /* try to make sure pending X events have been processed before continuing */
97 static void flush_events( BOOL remove_messages )
98 {
99 MSG msg;
100 int diff = 200;
101 int min_timeout = 100;
102 DWORD time = GetTickCount() + diff;
103
104 while (diff > 0)
105 {
106 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
107 if (remove_messages)
108 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
109 diff = time - GetTickCount();
110 min_timeout = 50;
111 }
112 }
113
114 static BOOL wait_for_event(HANDLE event, int timeout)
115 {
116 DWORD end_time = GetTickCount() + timeout;
117 MSG msg;
118
119 do {
120 if(MsgWaitForMultipleObjects(1, &event, FALSE, timeout, QS_ALLINPUT) == WAIT_OBJECT_0)
121 return TRUE;
122 while(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
123 DispatchMessageA(&msg);
124 timeout = end_time - GetTickCount();
125 }while(timeout > 0);
126
127 return FALSE;
128 }
129
130 /* check the values returned by the various parent/owner functions on a given window */
131 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
132 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
133 {
134 HWND res;
135
136 if (pGetAncestor)
137 {
138 res = pGetAncestor( hwnd, GA_PARENT );
139 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
140 }
141 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
142 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
143 res = GetParent( hwnd );
144 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
145 res = GetWindow( hwnd, GW_OWNER );
146 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
147 if (pGetAncestor)
148 {
149 res = pGetAncestor( hwnd, GA_ROOT );
150 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
151 res = pGetAncestor( hwnd, GA_ROOTOWNER );
152 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
153 }
154 }
155
156 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
157 static void check_wnd_state_(const char *file, int line,
158 HWND active, HWND foreground, HWND focus, HWND capture)
159 {
160 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
161 /* only check foreground if it belongs to the current thread */
162 /* foreground can be moved to a different app pretty much at any time */
163 if (foreground && GetForegroundWindow() &&
164 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
165 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
166 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
167 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
168 }
169
170 /* same as above but without capture test */
171 #define check_active_state(a,b,c) check_active_state_(__FILE__,__LINE__,a,b,c)
172 static void check_active_state_(const char *file, int line,
173 HWND active, HWND foreground, HWND focus)
174 {
175 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
176 /* only check foreground if it belongs to the current thread */
177 /* foreground can be moved to a different app pretty much at any time */
178 if (foreground && GetForegroundWindow() &&
179 GetWindowThreadProcessId(GetForegroundWindow(), NULL) == GetCurrentThreadId())
180 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
181 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
182 }
183
184 static BOOL ignore_message( UINT message )
185 {
186 /* these are always ignored */
187 return (message >= 0xc000 ||
188 message == WM_GETICON ||
189 message == WM_GETOBJECT ||
190 message == WM_TIMER ||
191 message == WM_SYSTIMER ||
192 message == WM_TIMECHANGE ||
193 message == WM_DEVICECHANGE);
194 }
195
196 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
197 {
198 (*(LPINT)lParam)++;
199 trace("EnumChildProc on %p\n", hwndChild);
200 if (*(LPINT)lParam > 1) return FALSE;
201 return TRUE;
202 }
203
204 /* will search for the given window */
205 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
206 {
207 trace("EnumChildProc1 on %p\n", hwndChild);
208 if ((HWND)lParam == hwndChild) return FALSE;
209 return TRUE;
210 }
211
212 static HWND create_tool_window( LONG style, HWND parent )
213 {
214 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
215 0, 0, 100, 100, parent, 0, 0, NULL );
216 ok( ret != 0, "Creation failed\n" );
217 return ret;
218 }
219
220 /* test parent and owner values for various combinations */
221 static void test_parent_owner(void)
222 {
223 LONG style;
224 HWND test, owner, ret;
225 HWND desktop = GetDesktopWindow();
226 HWND child = create_tool_window( WS_CHILD, hwndMain );
227 INT numChildren;
228
229 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
230
231 /* child without parent, should fail */
232 SetLastError(0xdeadbeef);
233 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
234 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
235 ok( !test, "WS_CHILD without parent created\n" );
236 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
237 broken(GetLastError() == 0xdeadbeef), /* win9x */
238 "CreateWindowExA error %u\n", GetLastError() );
239
240 /* desktop window */
241 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
242 style = GetWindowLongA( desktop, GWL_STYLE );
243 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
244 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
245 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
246
247 /* normal child window */
248 test = create_tool_window( WS_CHILD, hwndMain );
249 trace( "created child %p\n", test );
250 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
251 SetWindowLongA( test, GWL_STYLE, 0 );
252 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
253 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
254 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
255 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
256 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
257 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
258 DestroyWindow( test );
259
260 /* normal child window with WS_MAXIMIZE */
261 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
262 DestroyWindow( test );
263
264 /* normal child window with WS_THICKFRAME */
265 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
266 DestroyWindow( test );
267
268 /* popup window with WS_THICKFRAME */
269 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
270 DestroyWindow( test );
271
272 /* child of desktop */
273 test = create_tool_window( WS_CHILD, desktop );
274 trace( "created child of desktop %p\n", test );
275 check_parents( test, desktop, 0, desktop, 0, test, desktop );
276 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
277 check_parents( test, desktop, 0, 0, 0, test, test );
278 SetWindowLongA( test, GWL_STYLE, 0 );
279 check_parents( test, desktop, 0, 0, 0, test, test );
280 DestroyWindow( test );
281
282 /* child of desktop with WS_MAXIMIZE */
283 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
284 DestroyWindow( test );
285
286 /* child of desktop with WS_MINIMIZE */
287 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
288 DestroyWindow( test );
289
290 /* child of child */
291 test = create_tool_window( WS_CHILD, child );
292 trace( "created child of child %p\n", test );
293 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
294 SetWindowLongA( test, GWL_STYLE, 0 );
295 check_parents( test, child, child, 0, 0, hwndMain, test );
296 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
297 check_parents( test, child, child, 0, 0, hwndMain, test );
298 DestroyWindow( test );
299
300 /* child of child with WS_MAXIMIZE */
301 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
302 DestroyWindow( test );
303
304 /* child of child with WS_MINIMIZE */
305 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
306 DestroyWindow( test );
307
308 /* not owned top-level window */
309 test = create_tool_window( 0, 0 );
310 trace( "created top-level %p\n", test );
311 check_parents( test, desktop, 0, 0, 0, test, test );
312 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
313 check_parents( test, desktop, 0, 0, 0, test, test );
314 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
315 check_parents( test, desktop, 0, desktop, 0, test, desktop );
316 DestroyWindow( test );
317
318 /* not owned top-level window with WS_MAXIMIZE */
319 test = create_tool_window( WS_MAXIMIZE, 0 );
320 DestroyWindow( test );
321
322 /* owned top-level window */
323 test = create_tool_window( 0, hwndMain );
324 trace( "created owned top-level %p\n", test );
325 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
326 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
327 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
328 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
329 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
330 DestroyWindow( test );
331
332 /* owned top-level window with WS_MAXIMIZE */
333 test = create_tool_window( WS_MAXIMIZE, hwndMain );
334 DestroyWindow( test );
335
336 /* not owned popup */
337 test = create_tool_window( WS_POPUP, 0 );
338 trace( "created popup %p\n", test );
339 check_parents( test, desktop, 0, 0, 0, test, test );
340 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
341 check_parents( test, desktop, 0, desktop, 0, test, desktop );
342 SetWindowLongA( test, GWL_STYLE, 0 );
343 check_parents( test, desktop, 0, 0, 0, test, test );
344 DestroyWindow( test );
345
346 /* not owned popup with WS_MAXIMIZE */
347 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
348 DestroyWindow( test );
349
350 /* owned popup */
351 test = create_tool_window( WS_POPUP, hwndMain );
352 trace( "created owned popup %p\n", test );
353 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
354 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
355 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
356 SetWindowLongA( test, GWL_STYLE, 0 );
357 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
358 DestroyWindow( test );
359
360 /* owned popup with WS_MAXIMIZE */
361 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
362 DestroyWindow( test );
363
364 /* top-level window owned by child (same as owned by top-level) */
365 test = create_tool_window( 0, child );
366 trace( "created top-level owned by child %p\n", test );
367 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
368 DestroyWindow( test );
369
370 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
371 test = create_tool_window( WS_MAXIMIZE, child );
372 DestroyWindow( test );
373
374 /* popup owned by desktop (same as not owned) */
375 test = create_tool_window( WS_POPUP, desktop );
376 trace( "created popup owned by desktop %p\n", test );
377 check_parents( test, desktop, 0, 0, 0, test, test );
378 DestroyWindow( test );
379
380 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
381 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
382 DestroyWindow( test );
383
384 /* popup owned by child (same as owned by top-level) */
385 test = create_tool_window( WS_POPUP, child );
386 trace( "created popup owned by child %p\n", test );
387 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
388 DestroyWindow( test );
389
390 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
391 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
392 DestroyWindow( test );
393
394 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
395 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
396 trace( "created WS_CHILD popup %p\n", test );
397 check_parents( test, desktop, 0, 0, 0, test, test );
398 DestroyWindow( test );
399
400 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
401 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
402 DestroyWindow( test );
403
404 /* owned popup with WS_CHILD (same as WS_POPUP only) */
405 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
406 trace( "created owned WS_CHILD popup %p\n", test );
407 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
408 DestroyWindow( test );
409
410 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
411 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
412 DestroyWindow( test );
413
414 /******************** parent changes *************************/
415 trace( "testing parent changes\n" );
416
417 /* desktop window */
418 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
419 if (0)
420 {
421 /* this test succeeds on NT but crashes on win9x systems */
422 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
423 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
424 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
425 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
426 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
427 }
428 /* normal child window */
429 test = create_tool_window( WS_CHILD, hwndMain );
430 trace( "created child %p\n", test );
431
432 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
433 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
434 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
435
436 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
437 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
438 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
439
440 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
441 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
442 check_parents( test, desktop, 0, desktop, 0, test, desktop );
443
444 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
445 if (!is_win9x)
446 {
447 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)test );
448 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
449 check_parents( test, desktop, 0, desktop, 0, test, desktop );
450 }
451 else
452 win_skip("Test creates circular window tree under Win9x/WinMe\n" );
453
454 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
455 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
456 check_parents( test, desktop, child, desktop, child, test, desktop );
457
458 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
459 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
460 check_parents( test, desktop, 0, desktop, 0, test, desktop );
461 DestroyWindow( test );
462
463 /* not owned top-level window */
464 test = create_tool_window( 0, 0 );
465 trace( "created top-level %p\n", test );
466
467 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
468 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
469 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
470
471 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
472 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
473 check_parents( test, desktop, child, 0, child, test, test );
474
475 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
476 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
477 check_parents( test, desktop, 0, 0, 0, test, test );
478 DestroyWindow( test );
479
480 /* not owned popup */
481 test = create_tool_window( WS_POPUP, 0 );
482 trace( "created popup %p\n", test );
483
484 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
485 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
486 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
487
488 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
489 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
490 check_parents( test, desktop, child, child, child, test, hwndMain );
491
492 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
493 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
494 check_parents( test, desktop, 0, 0, 0, test, test );
495 DestroyWindow( test );
496
497 /* normal child window */
498 test = create_tool_window( WS_CHILD, hwndMain );
499 trace( "created child %p\n", test );
500
501 ret = SetParent( test, desktop );
502 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
503 check_parents( test, desktop, 0, desktop, 0, test, desktop );
504
505 ret = SetParent( test, child );
506 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
507 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
508
509 ret = SetParent( test, hwndMain2 );
510 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
511 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
512 DestroyWindow( test );
513
514 /* not owned top-level window */
515 test = create_tool_window( 0, 0 );
516 trace( "created top-level %p\n", test );
517
518 ret = SetParent( test, child );
519 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
520 check_parents( test, child, child, 0, 0, hwndMain, test );
521
522 if (!is_win9x)
523 {
524 ShowWindow( test, SW_SHOW );
525 ret = SetParent( test, test );
526 ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL );
527 ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" );
528 check_parents( test, child, child, 0, 0, hwndMain, test );
529 }
530 else
531 win_skip( "Test crashes on Win9x/WinMe\n" );
532 DestroyWindow( test );
533
534 /* owned popup */
535 test = create_tool_window( WS_POPUP, hwndMain2 );
536 trace( "created owned popup %p\n", test );
537
538 ret = SetParent( test, child );
539 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
540 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
541
542 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
543 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
544 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
545 DestroyWindow( test );
546
547 /**************** test owner destruction *******************/
548
549 /* owned child popup */
550 owner = create_tool_window( 0, 0 );
551 test = create_tool_window( WS_POPUP, owner );
552 trace( "created owner %p and popup %p\n", owner, test );
553 ret = SetParent( test, child );
554 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
555 check_parents( test, child, child, owner, owner, hwndMain, owner );
556 /* window is now child of 'child' but owned by 'owner' */
557 DestroyWindow( owner );
558 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
559 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
560 * while Win95, Win2k, WinXP do.
561 */
562 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
563 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
564 DestroyWindow(test);
565
566 /* owned top-level popup */
567 owner = create_tool_window( 0, 0 );
568 test = create_tool_window( WS_POPUP, owner );
569 trace( "created owner %p and popup %p\n", owner, test );
570 check_parents( test, desktop, owner, owner, owner, test, owner );
571 DestroyWindow( owner );
572 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
573
574 /* top-level popup owned by child */
575 owner = create_tool_window( WS_CHILD, hwndMain2 );
576 test = create_tool_window( WS_POPUP, 0 );
577 trace( "created owner %p and popup %p\n", owner, test );
578 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
579 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
580 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
581 DestroyWindow( owner );
582 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
583 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
584 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
585 * while Win95, Win2k, WinXP do.
586 */
587 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
588 DestroyWindow(test);
589
590 /* final cleanup */
591 DestroyWindow(child);
592
593
594 owner = create_tool_window( WS_OVERLAPPED, 0 );
595 test = create_tool_window( WS_POPUP, desktop );
596
597 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
598 numChildren = 0;
599 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
600 "EnumChildWindows should have returned FALSE\n" );
601 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
602
603 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
604 ret = SetParent( test, owner );
605 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
606
607 numChildren = 0;
608 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
609 "EnumChildWindows should have returned TRUE\n" );
610 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
611
612 child = create_tool_window( WS_CHILD, owner );
613 numChildren = 0;
614 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
615 "EnumChildWindows should have returned FALSE\n" );
616 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
617 DestroyWindow( child );
618
619 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
620 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
621 numChildren = 0;
622 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
623 "EnumChildWindows should have returned TRUE\n" );
624 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
625
626 ret = SetParent( child, owner );
627 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
628 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
629 numChildren = 0;
630 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
631 "EnumChildWindows should have returned FALSE\n" );
632 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
633
634 ret = SetParent( child, NULL );
635 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
636 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
637 numChildren = 0;
638 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
639 "EnumChildWindows should have returned TRUE\n" );
640 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
641
642 /* even GW_OWNER == owner it's still a desktop's child */
643 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
644 "EnumChildWindows should have found %p and returned FALSE\n", child );
645
646 DestroyWindow( child );
647 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
648
649 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
650 "EnumChildWindows should have found %p and returned FALSE\n", child );
651
652 DestroyWindow( child );
653 DestroyWindow( test );
654 DestroyWindow( owner );
655
656 /* Test that owner window takes into account WS_CHILD flag even if parent is set by SetParent. */
657 owner = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, desktop );
658 SetParent(owner, hwndMain);
659 check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner );
660 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
661 check_parents( test, desktop, owner, NULL, owner, test, test );
662 DestroyWindow( owner );
663 DestroyWindow( test );
664
665 owner = create_tool_window( WS_VISIBLE | WS_CHILD, desktop );
666 SetParent(owner, hwndMain);
667 check_parents( owner, hwndMain, hwndMain, hwndMain, NULL, hwndMain, hwndMain );
668 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
669 check_parents( test, desktop, hwndMain, NULL, hwndMain, test, test );
670 DestroyWindow( owner );
671 DestroyWindow( test );
672
673 owner = create_tool_window( WS_VISIBLE | WS_POPUP | WS_CHILD, desktop );
674 SetParent(owner, hwndMain);
675 check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner );
676 test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
677 check_parents( test, desktop, owner, NULL, owner, test, test );
678 DestroyWindow( owner );
679 DestroyWindow( test );
680 }
681
682 static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
683 {
684 (*(LPINT)lParam)++;
685 if (*(LPINT)lParam > 2) return FALSE;
686 return TRUE;
687 }
688 static DWORD CALLBACK enum_thread( void *arg )
689 {
690 INT count;
691 HWND hwnd[3];
692 BOOL ret;
693 MSG msg;
694
695 if (pGetGUIThreadInfo)
696 {
697 GUITHREADINFO info;
698 info.cbSize = sizeof(info);
699 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
700 ok( ret || broken(!ret), /* win9x */
701 "GetGUIThreadInfo failed without message queue\n" );
702 SetLastError( 0xdeadbeef );
703 info.cbSize = sizeof(info) + 1;
704 ret = pGetGUIThreadInfo( GetCurrentThreadId(), &info );
705 ok( !ret, "GetGUIThreadInfo succeeded with wrong size\n" );
706 ok( GetLastError() == ERROR_INVALID_PARAMETER ||
707 broken(GetLastError() == 0xdeadbeef), /* win9x */
708 "wrong error %u\n", GetLastError() );
709 }
710
711 PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE ); /* make sure we have a message queue */
712
713 count = 0;
714 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
715 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
716 ok( count == 0, "count should be 0 got %d\n", count );
717
718 hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
719 0, 0, 100, 100, 0, 0, 0, NULL );
720 count = 0;
721 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
722 ok( ret, "EnumThreadWindows should have returned TRUE\n" );
723 if (count != 2) /* Vista gives us two windows for the price of one */
724 {
725 ok( count == 1, "count should be 1 got %d\n", count );
726 hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
727 0, 0, 100, 100, 0, 0, 0, NULL );
728 }
729 else hwnd[2] = 0;
730
731 hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
732 0, 0, 100, 100, 0, 0, 0, NULL );
733 count = 0;
734 ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
735 ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
736 ok( count == 3, "count should be 3 got %d\n", count );
737
738 if (hwnd[2]) DestroyWindow(hwnd[2]);
739 DestroyWindow(hwnd[1]);
740 DestroyWindow(hwnd[0]);
741 return 0;
742 }
743
744 /* test EnumThreadWindows in a separate thread */
745 static void test_enum_thread_windows(void)
746 {
747 DWORD id;
748 HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
749 ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
750 CloseHandle( handle );
751 }
752
753 static struct wm_gettext_override_data
754 {
755 BOOL enabled; /* when 1 bypasses default procedure */
756 char *buff; /* expected text buffer pointer */
757 WCHAR *buffW; /* same, for W test */
758 } g_wm_gettext_override;
759
760 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
761 {
762 switch (msg)
763 {
764 case WM_GETMINMAXINFO:
765 {
766 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
767 break;
768 }
769 case WM_WINDOWPOSCHANGING:
770 {
771 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
772 if (!(winpos->flags & SWP_NOMOVE))
773 {
774 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
775 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
776 }
777 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
778 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
779 {
780 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
781 winpos->cx == 32768, /* win7 doesn't truncate */
782 "bad winpos->cx %d\n", winpos->cx);
783 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
784 winpos->cy == 40000, /* win7 doesn't truncate */
785 "bad winpos->cy %d\n", winpos->cy);
786 }
787 break;
788 }
789 case WM_WINDOWPOSCHANGED:
790 {
791 RECT rc1, rc2;
792 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
793 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
794 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
795
796 ok((winpos->cx >= 0 && winpos->cx <= 32767) ||
797 winpos->cx == 32768, /* win7 doesn't truncate */
798 "bad winpos->cx %d\n", winpos->cx);
799 ok((winpos->cy >= 0 && winpos->cy <= 32767) ||
800 winpos->cy == 40000, /* win7 doesn't truncate */
801 "bad winpos->cy %d\n", winpos->cy);
802
803 GetWindowRect(hwnd, &rc1);
804 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
805 /* note: winpos coordinates are relative to parent */
806 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
807 if (0)
808 {
809 /* Uncomment this once the test succeeds in all cases */
810 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
811 wine_dbgstr_rect(&rc2));
812
813 GetClientRect(hwnd, &rc2);
814 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
815 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
816 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
817 wine_dbgstr_rect(&rc2));
818 }
819 break;
820 }
821 case WM_NCCREATE:
822 {
823 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
824 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
825
826 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
827 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
828 else
829 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
830 break;
831 }
832 case WM_COMMAND:
833 if (test_lbuttondown_flag)
834 {
835 ShowWindow((HWND)wparam, SW_SHOW);
836 flush_events( FALSE );
837 }
838 break;
839 case WM_GETTEXT:
840 num_gettext_msgs++;
841 if (g_wm_gettext_override.enabled)
842 {
843 char *text = (char*)lparam;
844 ok(g_wm_gettext_override.buff == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buff, text);
845 ok(*text == 0, "expected empty string buffer %x\n", *text);
846 return 0;
847 }
848 break;
849 case WM_SETTEXT:
850 num_settext_msgs++;
851 break;
852 case WM_ACTIVATEAPP:
853 if (wparam) app_activated = TRUE;
854 else app_deactivated = TRUE;
855 break;
856 }
857
858 return DefWindowProcA(hwnd, msg, wparam, lparam);
859 }
860
861 static LRESULT WINAPI main_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
862 {
863 switch (msg)
864 {
865 case WM_GETTEXT:
866 num_gettext_msgs++;
867 if (g_wm_gettext_override.enabled)
868 {
869 WCHAR *text = (WCHAR*)lparam;
870 ok(g_wm_gettext_override.buffW == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buffW, text);
871 ok(*text == 0, "expected empty string buffer %x\n", *text);
872 return 0;
873 }
874 break;
875 }
876
877 return DefWindowProcA(hwnd, msg, wparam, lparam);
878 }
879
880 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
881 {
882 switch (msg)
883 {
884 case WM_GETMINMAXINFO:
885 {
886 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
887 break;
888 }
889 case WM_NCCREATE:
890 {
891 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
892 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
893
894 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
895 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
896 else
897 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
898 break;
899 }
900 }
901
902 return DefWindowProcA(hwnd, msg, wparam, lparam);
903 }
904
905 static const WCHAR mainclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
906
907 static BOOL RegisterWindowClasses(void)
908 {
909 WNDCLASSW clsW;
910 WNDCLASSA cls;
911
912 cls.style = CS_DBLCLKS;
913 cls.lpfnWndProc = main_window_procA;
914 cls.cbClsExtra = 0;
915 cls.cbWndExtra = 0;
916 cls.hInstance = GetModuleHandleA(0);
917 cls.hIcon = 0;
918 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
919 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
920 cls.lpszMenuName = NULL;
921 cls.lpszClassName = "MainWindowClass";
922
923 if(!RegisterClassA(&cls)) return FALSE;
924
925 clsW.style = CS_DBLCLKS;
926 clsW.lpfnWndProc = main_window_procW;
927 clsW.cbClsExtra = 0;
928 clsW.cbWndExtra = 0;
929 clsW.hInstance = GetModuleHandleA(0);
930 clsW.hIcon = 0;
931 clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
932 clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
933 clsW.lpszMenuName = NULL;
934 clsW.lpszClassName = mainclassW;
935
936 if(!RegisterClassW(&clsW)) return FALSE;
937
938 cls.style = 0;
939 cls.lpfnWndProc = tool_window_procA;
940 cls.cbClsExtra = 0;
941 cls.cbWndExtra = 0;
942 cls.hInstance = GetModuleHandleA(0);
943 cls.hIcon = 0;
944 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
945 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
946 cls.lpszMenuName = NULL;
947 cls.lpszClassName = "ToolWindowClass";
948
949 if(!RegisterClassA(&cls)) return FALSE;
950
951 return TRUE;
952 }
953
954 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
955 {
956 RECT rcWindow, rcClient;
957 DWORD status;
958
959 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
960
961 GetWindowRect(hwnd, &rcWindow);
962 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
963
964 GetClientRect(hwnd, &rcClient);
965 /* translate to screen coordinates */
966 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
967 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
968
969 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
970 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
971 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
972 /* Windows reports some undocumented exstyles in WINDOWINFO, but
973 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
974 */
975 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
976 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
977 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
978 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
979 if (GetForegroundWindow())
980 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
981 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
982
983 /* win2k and XP return broken border info in GetWindowInfo most of
984 * the time, so there is no point in testing it.
985 */
986 if (0)
987 {
988 UINT border;
989 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
990 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
991 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
992 ok(info->cyWindowBorders == border,
993 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
994 }
995 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
996 hwnd, hook);
997 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
998 info->wCreatorVersion == 0x0500 /* Vista */,
999 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
1000 }
1001
1002 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
1003 {
1004 AdjustWindowRectEx(rc, style, menu, exstyle);
1005 /* AdjustWindowRectEx does not include scroll bars */
1006 if (style & WS_VSCROLL)
1007 {
1008 if(exstyle & WS_EX_LEFTSCROLLBAR)
1009 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
1010 else
1011 rc->right += GetSystemMetrics(SM_CXVSCROLL);
1012 }
1013 if (style & WS_HSCROLL)
1014 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
1015 }
1016
1017 /* reimplement it to check that the Wine algorithm gives the correct result */
1018 static void wine_AdjustWindowRectEx( RECT *rect, LONG style, BOOL menu, LONG exStyle )
1019 {
1020 int adjust;
1021
1022 if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) ==
1023 WS_EX_STATICEDGE)
1024 {
1025 adjust = 1; /* for the outer frame always present */
1026 }
1027 else
1028 {
1029 adjust = 0;
1030 if ((exStyle & WS_EX_DLGMODALFRAME) ||
1031 (style & (WS_THICKFRAME|WS_DLGFRAME))) adjust = 2; /* outer */
1032 }
1033 if (style & WS_THICKFRAME)
1034 adjust += GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME); /* The resize border */
1035 if ((style & (WS_BORDER|WS_DLGFRAME)) ||
1036 (exStyle & WS_EX_DLGMODALFRAME))
1037 adjust++; /* The other border */
1038
1039 InflateRect (rect, adjust, adjust);
1040
1041 if ((style & WS_CAPTION) == WS_CAPTION)
1042 {
1043 if (exStyle & WS_EX_TOOLWINDOW)
1044 rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
1045 else
1046 rect->top -= GetSystemMetrics(SM_CYCAPTION);
1047 }
1048 if (menu) rect->top -= GetSystemMetrics(SM_CYMENU);
1049
1050 if (exStyle & WS_EX_CLIENTEDGE)
1051 InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
1052
1053 if (style & WS_VSCROLL)
1054 {
1055 if((exStyle & WS_EX_LEFTSCROLLBAR) != 0)
1056 rect->left -= GetSystemMetrics(SM_CXVSCROLL);
1057 else
1058 rect->right += GetSystemMetrics(SM_CXVSCROLL);
1059 }
1060 if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
1061 }
1062
1063 static void test_nonclient_area(HWND hwnd)
1064 {
1065 DWORD style, exstyle;
1066 RECT rc_window, rc_client, rc;
1067 BOOL menu;
1068 LRESULT ret;
1069
1070 style = GetWindowLongA(hwnd, GWL_STYLE);
1071 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1072 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
1073
1074 GetWindowRect(hwnd, &rc_window);
1075 GetClientRect(hwnd, &rc_client);
1076
1077 /* avoid some cases when things go wrong */
1078 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
1079 rc_window.right > 32768 || rc_window.bottom > 32768) return;
1080
1081 rc = rc_client;
1082 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
1083 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
1084
1085 ok(EqualRect(&rc, &rc_window),
1086 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1087 style, exstyle, menu, wine_dbgstr_rect(&rc_window), wine_dbgstr_rect(&rc));
1088
1089 rc = rc_client;
1090 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
1091 wine_AdjustWindowRectEx(&rc, style, menu, exstyle);
1092 ok(EqualRect(&rc, &rc_window),
1093 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=%s, calc=%s\n",
1094 style, exstyle, menu, wine_dbgstr_rect(&rc_window), wine_dbgstr_rect(&rc));
1095
1096
1097 rc = rc_window;
1098 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1099 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1100 ok(EqualRect(&rc, &rc_client),
1101 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=%s, calc=%s\n",
1102 style, exstyle, menu, wine_dbgstr_rect(&rc_client), wine_dbgstr_rect(&rc));
1103
1104 /* NULL rectangle shouldn't crash */
1105 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
1106 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
1107
1108 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
1109 if (is_win9x)
1110 return;
1111
1112 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
1113 SetRect(&rc_client, 0, 0, 250, 150);
1114 rc_window = rc_client;
1115 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
1116 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
1117
1118 rc = rc_window;
1119 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
1120 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
1121 ok(EqualRect(&rc, &rc_client),
1122 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=%s, calc=%s\n",
1123 style, exstyle, menu, wine_dbgstr_rect(&rc_client), wine_dbgstr_rect(&rc));
1124 }
1125
1126 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
1127 {
1128 static const char *CBT_code_name[10] = {
1129 "HCBT_MOVESIZE",
1130 "HCBT_MINMAX",
1131 "HCBT_QS",
1132 "HCBT_CREATEWND",
1133 "HCBT_DESTROYWND",
1134 "HCBT_ACTIVATE",
1135 "HCBT_CLICKSKIPPED",
1136 "HCBT_KEYSKIPPED",
1137 "HCBT_SYSCOMMAND",
1138 "HCBT_SETFOCUS" };
1139 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
1140 HWND hwnd = (HWND)wParam;
1141
1142 switch (nCode)
1143 {
1144 case HCBT_CREATEWND:
1145 {
1146 static const RECT rc_null;
1147 RECT rc;
1148 LONG style;
1149 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
1150 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
1151
1152 if (pGetWindowInfo)
1153 {
1154 WINDOWINFO info;
1155 info.cbSize = sizeof(WINDOWINFO);
1156 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1157 verify_window_info(code_name, hwnd, &info);
1158 }
1159
1160 /* WS_VISIBLE should be turned off yet */
1161 style = createwnd->lpcs->style & ~WS_VISIBLE;
1162 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
1163 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
1164 GetWindowLongA(hwnd, GWL_STYLE), style);
1165
1166 if (0)
1167 {
1168 /* Uncomment this once the test succeeds in all cases */
1169 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1170 {
1171 ok(GetParent(hwnd) == hwndMessage,
1172 "wrong result from GetParent %p: message window %p\n",
1173 GetParent(hwnd), hwndMessage);
1174 }
1175 else
1176 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
1177
1178 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
1179 }
1180 if (0)
1181 {
1182 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
1183 * Win9x still has them set to 0.
1184 */
1185 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
1186 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
1187 }
1188 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
1189 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
1190
1191 if (0)
1192 {
1193 /* Uncomment this once the test succeeds in all cases */
1194 if (pGetAncestor)
1195 {
1196 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
1197 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
1198 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
1199
1200 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1201 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
1202 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
1203 else
1204 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
1205 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
1206 }
1207
1208 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
1209 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
1210 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
1211 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
1212 }
1213 break;
1214 }
1215 case HCBT_MOVESIZE:
1216 case HCBT_MINMAX:
1217 case HCBT_ACTIVATE:
1218 if (pGetWindowInfo && IsWindow(hwnd))
1219 {
1220 WINDOWINFO info;
1221
1222 /* Win98 actually does check the info.cbSize and doesn't allow
1223 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
1224 * WinXP do not check it at all.
1225 */
1226 info.cbSize = sizeof(WINDOWINFO);
1227 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
1228 verify_window_info(code_name, hwnd, &info);
1229 }
1230 break;
1231 /* window state is undefined */
1232 case HCBT_SETFOCUS:
1233 case HCBT_DESTROYWND:
1234 break;
1235 default:
1236 break;
1237 }
1238
1239 return CallNextHookEx(hhook, nCode, wParam, lParam);
1240 }
1241
1242 static void test_shell_window(void)
1243 {
1244 BOOL ret;
1245 DWORD error;
1246 HMODULE hinst, hUser32;
1247 BOOL (WINAPI*SetShellWindow)(HWND);
1248 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
1249 HWND shellWindow, nextWnd;
1250
1251 if (is_win9x)
1252 {
1253 win_skip("Skipping shell window test on Win9x\n");
1254 return;
1255 }
1256
1257 shellWindow = GetShellWindow();
1258 hinst = GetModuleHandleA(NULL);
1259 hUser32 = GetModuleHandleA("user32");
1260
1261 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
1262
1263 trace("previous shell window: %p\n", shellWindow);
1264
1265 if (shellWindow) {
1266 DWORD pid;
1267 HANDLE hProcess;
1268
1269 GetWindowThreadProcessId(shellWindow, &pid);
1270 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
1271 if (!hProcess)
1272 {
1273 skip( "cannot get access to shell process\n" );
1274 return;
1275 }
1276
1277 SetLastError(0xdeadbeef);
1278 ret = DestroyWindow(shellWindow);
1279 error = GetLastError();
1280
1281 ok(!ret, "DestroyWindow(shellWindow)\n");
1282 /* passes on Win XP, but not on Win98 */
1283 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1284 "got %u after DestroyWindow(shellWindow)\n", error);
1285
1286 /* close old shell instance */
1287 ret = TerminateProcess(hProcess, 0);
1288 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1289 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1290 CloseHandle(hProcess);
1291 }
1292
1293 hwnd1 = CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1294 trace("created window 1: %p\n", hwnd1);
1295
1296 ret = SetShellWindow(hwnd1);
1297 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1298 shellWindow = GetShellWindow();
1299 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1300
1301 ret = SetShellWindow(hwnd1);
1302 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1303
1304 ret = SetShellWindow(0);
1305 error = GetLastError();
1306 /* passes on Win XP, but not on Win98
1307 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1308 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1309
1310 ret = SetShellWindow(hwnd1);
1311 /* passes on Win XP, but not on Win98
1312 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1313
1314 SetWindowLongA(hwnd1, GWL_EXSTYLE, GetWindowLongA(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1315 ret = (GetWindowLongA(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
1316 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1317
1318 ret = DestroyWindow(hwnd1);
1319 ok(ret, "DestroyWindow(hwnd1)\n");
1320
1321 hwnd2 = CreateWindowExA(WS_EX_TOPMOST, "#32770", "TEST2", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1322 trace("created window 2: %p\n", hwnd2);
1323 ret = SetShellWindow(hwnd2);
1324 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1325
1326 hwnd3 = CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1327 trace("created window 3: %p\n", hwnd3);
1328
1329 hwnd4 = CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1330 trace("created window 4: %p\n", hwnd4);
1331
1332 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1333 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1334
1335 ret = SetShellWindow(hwnd4);
1336 ok(ret, "SetShellWindow(hwnd4)\n");
1337 shellWindow = GetShellWindow();
1338 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1339
1340 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1341 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1342
1343 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1344 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1345
1346 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1347 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1348
1349 ret = SetShellWindow(hwnd3);
1350 ok(!ret, "SetShellWindow(hwnd3)\n");
1351 shellWindow = GetShellWindow();
1352 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1353
1354 hwnd5 = CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1355 trace("created window 5: %p\n", hwnd5);
1356 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1357 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1358
1359 todo_wine
1360 {
1361 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1362 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1363 }
1364
1365 /* destroy test windows */
1366 DestroyWindow(hwnd2);
1367 DestroyWindow(hwnd3);
1368 DestroyWindow(hwnd4);
1369 DestroyWindow(hwnd5);
1370 }
1371
1372 /************** MDI test ****************/
1373
1374 static char mdi_lParam_test_message[] = "just a test string";
1375
1376 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1377 {
1378 MDICREATESTRUCTA mdi_cs;
1379 HWND mdi_child, hwnd, exp_hwnd;
1380 INT_PTR id;
1381 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1382 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1383 BOOL isWin9x = FALSE;
1384 HMENU frame_menu = GetMenu(parent);
1385
1386 ok(frame_menu != NULL, "Frame window didn't have a menu\n");
1387
1388 mdi_cs.szClass = "MDI_child_Class_1";
1389 mdi_cs.szTitle = "MDI child";
1390 mdi_cs.hOwner = GetModuleHandleA(NULL);
1391 mdi_cs.x = CW_USEDEFAULT;
1392 mdi_cs.y = CW_USEDEFAULT;
1393 mdi_cs.cx = CW_USEDEFAULT;
1394 mdi_cs.cy = CW_USEDEFAULT;
1395 mdi_cs.style = 0;
1396 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1397 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1398 ok(mdi_child != 0, "MDI child creation failed\n");
1399 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1400 ok(id == first_id, "wrong child id %ld\n", id);
1401 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1402 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1403 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1404 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1405 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1406
1407 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1408 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1409 ok(mdi_child != 0, "MDI child creation failed\n");
1410 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1411 ok(id == first_id, "wrong child id %ld\n", id);
1412 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1413 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1414 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1415 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1416
1417 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1418 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1419 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1420 {
1421 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1422 }
1423 else
1424 {
1425 ok(mdi_child != 0, "MDI child creation failed\n");
1426 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1427 ok(id == first_id, "wrong child id %ld\n", id);
1428 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1429 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1430 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1431 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1432 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1433 }
1434
1435 /* test MDICREATESTRUCT A<->W mapping */
1436 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1437 mdi_cs.style = 0;
1438 mdi_cs.szClass = (LPCSTR)classW;
1439 mdi_cs.szTitle = (LPCSTR)titleW;
1440 SetLastError(0xdeadbeef);
1441 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1442 if (!mdi_child)
1443 {
1444 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1445 isWin9x = TRUE;
1446 else
1447 ok(mdi_child != 0, "MDI child creation failed\n");
1448 }
1449 else
1450 {
1451 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1452 ok(id == first_id, "wrong child id %ld\n", id);
1453 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1454 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1455 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1456 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1457 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1458 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1459 }
1460
1461 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1462 0,
1463 CW_USEDEFAULT, CW_USEDEFAULT,
1464 CW_USEDEFAULT, CW_USEDEFAULT,
1465 mdi_client, GetModuleHandleA(NULL),
1466 (LPARAM)mdi_lParam_test_message);
1467 ok(mdi_child != 0, "MDI child creation failed\n");
1468 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1469 ok(id == first_id, "wrong child id %ld\n", id);
1470 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1471 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1472 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1473 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1474 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1475 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1476
1477 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1478 0x7fffffff, /* without WS_POPUP */
1479 CW_USEDEFAULT, CW_USEDEFAULT,
1480 CW_USEDEFAULT, CW_USEDEFAULT,
1481 mdi_client, GetModuleHandleA(NULL),
1482 (LPARAM)mdi_lParam_test_message);
1483 ok(mdi_child != 0, "MDI child creation failed\n");
1484 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1485 ok(id == first_id, "wrong child id %ld\n", id);
1486 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1487 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1488 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1489 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1490 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1491
1492 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1493 0xffffffff, /* with WS_POPUP */
1494 CW_USEDEFAULT, CW_USEDEFAULT,
1495 CW_USEDEFAULT, CW_USEDEFAULT,
1496 mdi_client, GetModuleHandleA(NULL),
1497 (LPARAM)mdi_lParam_test_message);
1498 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1499 {
1500 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1501 }
1502 else
1503 {
1504 ok(mdi_child != 0, "MDI child creation failed\n");
1505 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1506 ok(id == first_id, "wrong child id %ld\n", id);
1507 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1508 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1509 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1510 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1511 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1512 }
1513
1514 /* test MDICREATESTRUCT A<->W mapping */
1515 SetLastError(0xdeadbeef);
1516 mdi_child = CreateMDIWindowW(classW, titleW,
1517 0,
1518 CW_USEDEFAULT, CW_USEDEFAULT,
1519 CW_USEDEFAULT, CW_USEDEFAULT,
1520 mdi_client, GetModuleHandleA(NULL),
1521 (LPARAM)mdi_lParam_test_message);
1522 if (!mdi_child)
1523 {
1524 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1525 isWin9x = TRUE;
1526 else
1527 ok(mdi_child != 0, "MDI child creation failed\n");
1528 }
1529 else
1530 {
1531 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1532 ok(id == first_id, "wrong child id %ld\n", id);
1533 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1534 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1535 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1536 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1537 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1538 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1539 }
1540
1541 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1542 0,
1543 CW_USEDEFAULT, CW_USEDEFAULT,
1544 CW_USEDEFAULT, CW_USEDEFAULT,
1545 mdi_client, 0, GetModuleHandleA(NULL),
1546 mdi_lParam_test_message);
1547 ok(mdi_child != 0, "MDI child creation failed\n");
1548 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1549 ok(id == first_id, "wrong child id %ld\n", id);
1550 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1551 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1552 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1553 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1554 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1555 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1556
1557 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1558 WS_MAXIMIZE,
1559 CW_USEDEFAULT, CW_USEDEFAULT,
1560 CW_USEDEFAULT, CW_USEDEFAULT,
1561 mdi_client, 0, GetModuleHandleA(NULL),
1562 mdi_lParam_test_message);
1563 ok(mdi_child != 0, "MDI child creation failed\n");
1564 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1565 ok(id == first_id, "wrong child id %ld\n", id);
1566 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1567 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1568 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1569 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1570 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1571 else
1572 ok(GetMenuItemCount(frame_menu) == 4, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1573 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1574 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1575
1576 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1577 0x7fffffff, /* without WS_POPUP */
1578 CW_USEDEFAULT, CW_USEDEFAULT,
1579 CW_USEDEFAULT, CW_USEDEFAULT,
1580 mdi_client, 0, GetModuleHandleA(NULL),
1581 mdi_lParam_test_message);
1582 ok(mdi_child != 0, "MDI child creation failed\n");
1583 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1584 ok(id == first_id, "wrong child id %ld\n", id);
1585 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1586 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1587 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1588 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1589 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1590
1591 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1592 0xffffffff, /* with WS_POPUP */
1593 CW_USEDEFAULT, CW_USEDEFAULT,
1594 CW_USEDEFAULT, CW_USEDEFAULT,
1595 mdi_client, 0, GetModuleHandleA(NULL),
1596 mdi_lParam_test_message);
1597 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1598 {
1599 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1600 }
1601 else
1602 {
1603 ok(mdi_child != 0, "MDI child creation failed\n");
1604 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1605 ok(id == first_id, "wrong child id %ld\n", id);
1606 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1607 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1608 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1609 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1610 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1611 }
1612
1613 /* test MDICREATESTRUCT A<->W mapping */
1614 SetLastError(0xdeadbeef);
1615 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1616 0,
1617 CW_USEDEFAULT, CW_USEDEFAULT,
1618 CW_USEDEFAULT, CW_USEDEFAULT,
1619 mdi_client, 0, GetModuleHandleA(NULL),
1620 mdi_lParam_test_message);
1621 if (!mdi_child)
1622 {
1623 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1624 isWin9x = TRUE;
1625 else
1626 ok(mdi_child != 0, "MDI child creation failed\n");
1627 }
1628 else
1629 {
1630 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1631 ok(id == first_id, "wrong child id %ld\n", id);
1632 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1633 exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
1634 ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
1635 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1636 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1637 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1638 }
1639
1640 /* This test fails on Win9x */
1641 if (!isWin9x)
1642 {
1643 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1644 WS_CHILD,
1645 CW_USEDEFAULT, CW_USEDEFAULT,
1646 CW_USEDEFAULT, CW_USEDEFAULT,
1647 parent, 0, GetModuleHandleA(NULL),
1648 mdi_lParam_test_message);
1649 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1650 }
1651
1652 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1653 WS_CHILD, /* without WS_POPUP */
1654 CW_USEDEFAULT, CW_USEDEFAULT,
1655 CW_USEDEFAULT, CW_USEDEFAULT,
1656 mdi_client, 0, GetModuleHandleA(NULL),
1657 mdi_lParam_test_message);
1658 ok(mdi_child != 0, "MDI child creation failed\n");
1659 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1660 ok(id == 0, "wrong child id %ld\n", id);
1661 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1662 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1663 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1664 DestroyWindow(mdi_child);
1665
1666 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1667 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1668 CW_USEDEFAULT, CW_USEDEFAULT,
1669 CW_USEDEFAULT, CW_USEDEFAULT,
1670 mdi_client, 0, GetModuleHandleA(NULL),
1671 mdi_lParam_test_message);
1672 ok(mdi_child != 0, "MDI child creation failed\n");
1673 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1674 ok(id == 0, "wrong child id %ld\n", id);
1675 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1676 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1677 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1678 DestroyWindow(mdi_child);
1679
1680 /* maximized child */
1681 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1682 WS_CHILD | WS_MAXIMIZE,
1683 CW_USEDEFAULT, CW_USEDEFAULT,
1684 CW_USEDEFAULT, CW_USEDEFAULT,
1685 mdi_client, 0, GetModuleHandleA(NULL),
1686 mdi_lParam_test_message);
1687 ok(mdi_child != 0, "MDI child creation failed\n");
1688 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1689 ok(id == 0, "wrong child id %ld\n", id);
1690 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1691 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1692 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1693 DestroyWindow(mdi_child);
1694
1695 trace("Creating maximized child with a caption\n");
1696 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1697 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1698 CW_USEDEFAULT, CW_USEDEFAULT,
1699 CW_USEDEFAULT, CW_USEDEFAULT,
1700 mdi_client, 0, GetModuleHandleA(NULL),
1701 mdi_lParam_test_message);
1702 ok(mdi_child != 0, "MDI child creation failed\n");
1703 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1704 ok(id == 0, "wrong child id %ld\n", id);
1705 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1706 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1707 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1708 DestroyWindow(mdi_child);
1709
1710 trace("Creating maximized child with a caption and a thick frame\n");
1711 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1712 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1713 CW_USEDEFAULT, CW_USEDEFAULT,
1714 CW_USEDEFAULT, CW_USEDEFAULT,
1715 mdi_client, 0, GetModuleHandleA(NULL),
1716 mdi_lParam_test_message);
1717 ok(mdi_child != 0, "MDI child creation failed\n");
1718 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1719 ok(id == 0, "wrong child id %ld\n", id);
1720 hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1721 ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
1722 ok(GetMenuItemCount(frame_menu) == 0, "Got wrong frame menu item count: %u\n", GetMenuItemCount(frame_menu));
1723 DestroyWindow(mdi_child);
1724 }
1725
1726 static void test_MDI_child_stack(HWND mdi_client)
1727 {
1728 HWND child_1, child_2, child_3, child_4;
1729 HWND stack[4];
1730 MDICREATESTRUCTA cs;
1731
1732 cs.szClass = "MDI_child_Class_1";
1733 cs.szTitle = "MDI child";
1734 cs.hOwner = GetModuleHandleA(0);
1735 cs.x = CW_USEDEFAULT;
1736 cs.y = CW_USEDEFAULT;
1737 cs.cx = CW_USEDEFAULT;
1738 cs.cy = CW_USEDEFAULT;
1739 cs.style = 0;
1740 cs.lParam = (LPARAM)mdi_lParam_test_message;
1741
1742 child_1 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1743 ok(child_1 != 0, "expected child_1 to be non NULL\n");
1744 child_2 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1745 ok(child_2 != 0, "expected child_2 to be non NULL\n");
1746 child_3 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1747 ok(child_3 != 0, "expected child_3 to be non NULL\n");
1748 child_4 = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&cs);
1749 ok(child_4 != 0, "expected child_4 to be non NULL\n");
1750
1751 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1752 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1753 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1754 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1755 trace("Initial MDI child stack: %p->%p->%p->%p\n", stack[0], stack[1], stack[2], stack[3]);
1756 ok(stack[0] == child_4 && stack[1] == child_3 &&
1757 stack[2] == child_2 && stack[3] == child_1,
1758 "Unexpected initial order, should be: %p->%p->%p->%p\n",
1759 child_4, child_3, child_2, child_1);
1760
1761 trace("Activate child next to %p\n", child_3);
1762 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
1763
1764 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1765 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1766 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1767 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1768 ok(stack[0] == child_2 && stack[1] == child_4 &&
1769 stack[2] == child_1 && stack[3] == child_3,
1770 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1771 child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1772
1773 trace("Activate child previous to %p\n", child_1);
1774 SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
1775
1776 stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
1777 stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
1778 stack[2] = GetWindow(stack[1], GW_HWNDNEXT);
1779 stack[3] = GetWindow(stack[2], GW_HWNDNEXT);
1780 ok(stack[0] == child_4 && stack[1] == child_2 &&
1781 stack[2] == child_1 && stack[3] == child_3,
1782 "Broken MDI child stack:\nexpected: %p->%p->%p->%p, but got: %p->%p->%p->%p\n",
1783 child_4, child_2, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
1784
1785 DestroyWindow(child_1);
1786 DestroyWindow(child_2);
1787 DestroyWindow(child_3);
1788 DestroyWindow(child_4);
1789 }
1790
1791 /**********************************************************************
1792 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1793 *
1794 * Note: The rule here is that client rect of the maximized MDI child
1795 * is equal to the client rect of the MDI client window.
1796 */
1797 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1798 {
1799 RECT rect;
1800
1801 GetClientRect( client, &rect );
1802 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1803 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1804
1805 rect.right -= rect.left;
1806 rect.bottom -= rect.top;
1807 lpMinMax->ptMaxSize.x = rect.right;
1808 lpMinMax->ptMaxSize.y = rect.bottom;
1809
1810 lpMinMax->ptMaxPosition.x = rect.left;
1811 lpMinMax->ptMaxPosition.y = rect.top;
1812
1813 trace("max rect %s\n", wine_dbgstr_rect(&rect));
1814 }
1815
1816 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1817 {
1818 switch (msg)
1819 {
1820 case WM_NCCREATE:
1821 case WM_CREATE:
1822 {
1823 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1824 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1825
1826 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1827 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1828
1829 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1830 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1831 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1832 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1833 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1834
1835 /* MDICREATESTRUCT should have original values */
1836 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff || mdi_cs->style == WS_MAXIMIZE,
1837 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1838 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1839 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1840 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1841 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1842
1843 /* CREATESTRUCT should have fixed values */
1844 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1845 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1846
1847 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1848 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1849 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1850
1851 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1852
1853 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1854 {
1855 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1856 ok(cs->style == style,
1857 "cs->style does not match (%08x)\n", cs->style);
1858 }
1859 else
1860 {
1861 LONG style = mdi_cs->style;
1862 style &= ~WS_POPUP;
1863 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1864 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1865 ok(cs->style == style,
1866 "cs->style does not match (%08x)\n", cs->style);
1867 }
1868 break;
1869 }
1870
1871 case WM_GETMINMAXINFO:
1872 {
1873 HWND client = GetParent(hwnd);
1874 RECT rc;
1875 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1876 MINMAXINFO my_minmax;
1877 LONG style, exstyle;
1878
1879 style = GetWindowLongA(hwnd, GWL_STYLE);
1880 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1881
1882 GetClientRect(client, &rc);
1883
1884 GetClientRect(client, &rc);
1885 if ((style & WS_CAPTION) == WS_CAPTION)
1886 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1887 AdjustWindowRectEx(&rc, style, 0, exstyle);
1888 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1889 dump_minmax_info( minmax );
1890
1891 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1892 minmax->ptMaxSize.x, rc.right - rc.left);
1893 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1894 minmax->ptMaxSize.y, rc.bottom - rc.top);
1895
1896 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1897
1898 trace("DefMDIChildProc returned:\n");
1899 dump_minmax_info( minmax );
1900
1901 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1902 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1903 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1904 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1905 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1906
1907 return 1;
1908 }
1909
1910 case WM_MDIACTIVATE:
1911 {
1912 HWND active, client = GetParent(hwnd);
1913 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1914 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1915 if (hwnd == (HWND)lparam) /* if we are being activated */
1916 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1917 else
1918 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1919 break;
1920 }
1921 }
1922 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1923 }
1924
1925 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1926 {
1927 switch (msg)
1928 {
1929 case WM_NCCREATE:
1930 case WM_CREATE:
1931 {
1932 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1933
1934 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1935 cs->x, cs->y, cs->cx, cs->cy);
1936
1937 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1938 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1939
1940 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1941 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1942
1943 /* CREATESTRUCT should have fixed values */
1944 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1945 while NT does. */
1946 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1947 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1948
1949 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1950 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1951 while Win95, Win2k, WinXP do. */
1952 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1953 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1954 break;
1955 }
1956
1957 case WM_GETMINMAXINFO:
1958 {
1959 HWND parent = GetParent(hwnd);
1960 RECT rc;
1961 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1962 LONG style, exstyle;
1963
1964 style = GetWindowLongA(hwnd, GWL_STYLE);
1965 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1966
1967 GetClientRect(parent, &rc);
1968 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1969
1970 GetClientRect(parent, &rc);
1971 if ((style & WS_CAPTION) == WS_CAPTION)
1972 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1973 AdjustWindowRectEx(&rc, style, 0, exstyle);
1974 dump_minmax_info( minmax );
1975
1976 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1977 minmax->ptMaxSize.x, rc.right - rc.left);
1978 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1979 minmax->ptMaxSize.y, rc.bottom - rc.top);
1980 break;
1981 }
1982
1983 case WM_WINDOWPOSCHANGED:
1984 {
1985 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1986 RECT rc1, rc2;
1987
1988 GetWindowRect(hwnd, &rc1);
1989 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1990 /* note: winpos coordinates are relative to parent */
1991 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1992 ok(EqualRect(&rc1, &rc2), "rects do not match, window=%s pos=%s\n",
1993 wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
1994 GetWindowRect(hwnd, &rc1);
1995 GetClientRect(hwnd, &rc2);
1996 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1997 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1998 ok(EqualRect(&rc1, &rc2), "rects do not match, window=%s client=%s\n",
1999 wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2000 }
2001 /* fall through */
2002 case WM_WINDOWPOSCHANGING:
2003 {
2004 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2005 WINDOWPOS my_winpos = *winpos;
2006
2007 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2008 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
2009 winpos->hwnd, winpos->hwndInsertAfter,
2010 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2011
2012 DefWindowProcA(hwnd, msg, wparam, lparam);
2013
2014 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
2015 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2016 winpos->hwnd, winpos->hwndInsertAfter,
2017 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2018
2019 return 1;
2020 }
2021 }
2022 return DefWindowProcA(hwnd, msg, wparam, lparam);
2023 }
2024
2025 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2026 {
2027 static HWND mdi_client;
2028
2029 switch (msg)
2030 {
2031 case WM_CREATE:
2032 return 1;
2033
2034 case WM_WINDOWPOSCHANGED:
2035 {
2036 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2037 RECT rc1, rc2;
2038
2039 GetWindowRect(hwnd, &rc1);
2040 trace("window: %s\n", wine_dbgstr_rect(&rc1));
2041 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
2042 /* note: winpos coordinates are relative to parent */
2043 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
2044 trace("pos: %s\n", wine_dbgstr_rect(&rc2));
2045 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
2046
2047 GetWindowRect(hwnd, &rc1);
2048 GetClientRect(hwnd, &rc2);
2049 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
2050 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
2051 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
2052 }
2053 /* fall through */
2054 case WM_WINDOWPOSCHANGING:
2055 {
2056 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
2057 WINDOWPOS my_winpos = *winpos;
2058
2059 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
2060 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2061 winpos->hwnd, winpos->hwndInsertAfter,
2062 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2063
2064 DefWindowProcA(hwnd, msg, wparam, lparam);
2065
2066 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
2067 winpos->hwnd, winpos->hwndInsertAfter,
2068 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
2069
2070 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
2071 "DefWindowProc should not change WINDOWPOS values\n");
2072
2073 return 1;
2074 }
2075
2076 case WM_CLOSE:
2077 PostQuitMessage(0);
2078 break;
2079 }
2080 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
2081 }
2082
2083 static BOOL mdi_RegisterWindowClasses(void)
2084 {
2085 WNDCLASSA cls;
2086
2087 cls.style = 0;
2088 cls.lpfnWndProc = mdi_main_wnd_procA;
2089 cls.cbClsExtra = 0;
2090 cls.cbWndExtra = 0;
2091 cls.hInstance = GetModuleHandleA(0);
2092 cls.hIcon = 0;
2093 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
2094 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2095 cls.lpszMenuName = NULL;
2096 cls.lpszClassName = "MDI_parent_Class";
2097 if(!RegisterClassA(&cls)) return FALSE;
2098
2099 cls.lpfnWndProc = mdi_child_wnd_proc_1;
2100 cls.lpszClassName = "MDI_child_Class_1";
2101 if(!RegisterClassA(&cls)) return FALSE;
2102
2103 cls.lpfnWndProc = mdi_child_wnd_proc_2;
2104 cls.lpszClassName = "MDI_child_Class_2";
2105 if(!RegisterClassA(&cls)) return FALSE;
2106
2107 return TRUE;
2108 }
2109
2110 static void test_mdi(void)
2111 {
2112 static const DWORD style[] = { 0, WS_HSCROLL, WS_VSCROLL, WS_HSCROLL | WS_VSCROLL };
2113 HWND mdi_hwndMain, mdi_client, mdi_child;
2114 CLIENTCREATESTRUCT client_cs;
2115 RECT rc;
2116 DWORD i;
2117 MSG msg;
2118 HMENU frame_menu, child_menu;
2119
2120 if (!mdi_RegisterWindowClasses()) assert(0);
2121
2122 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
2123 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
2124 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
2125 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
2126 GetDesktopWindow(), 0,
2127 GetModuleHandleA(NULL), NULL);
2128 assert(mdi_hwndMain);
2129
2130 frame_menu = CreateMenu();
2131
2132 GetClientRect(mdi_hwndMain, &rc);
2133
2134 client_cs.hWindowMenu = 0;
2135 client_cs.idFirstChild = 1;
2136
2137 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
2138 {
2139 SCROLLINFO si;
2140 BOOL ret, gotit;
2141
2142 mdi_client = CreateWindowExA(0, "mdiclient", NULL,
2143 WS_CHILD | style[i],
2144 0, 0, rc.right, rc.bottom,
2145 mdi_hwndMain, 0, 0, &client_cs);
2146 ok(mdi_client != 0, "MDI client creation failed\n");
2147
2148 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
2149 0,
2150 CW_USEDEFAULT, CW_USEDEFAULT,
2151 CW_USEDEFAULT, CW_USEDEFAULT,
2152 mdi_client, 0, 0,
2153 mdi_lParam_test_message);
2154 ok(mdi_child != 0, "MDI child creation failed\n");
2155
2156 SendMessageW(mdi_child, WM_SIZE, SIZE_MAXIMIZED, 0);
2157 SetMenu(mdi_hwndMain, frame_menu);
2158
2159 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child maximize, but has %u\n",
2160 GetMenuItemCount(frame_menu));
2161
2162 child_menu = CreateMenu();
2163 SendMessageW(mdi_client, WM_MDISETMENU, 0, (LPARAM)child_menu);
2164
2165 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after WM_MDISETMENU, but has %u\n",
2166 GetMenuItemCount(frame_menu));
2167
2168 SendMessageW(mdi_child, WM_SIZE, SIZE_RESTORED, 0);
2169
2170 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2171 GetMenuItemCount(frame_menu));
2172
2173 SetMenu(mdi_hwndMain, NULL);
2174
2175 si.cbSize = sizeof(si);
2176 si.fMask = SIF_ALL;
2177 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2178 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2179 {
2180 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2181 ok(si.nPage == 0, "expected 0\n");
2182 ok(si.nPos == 0, "expected 0\n");
2183 ok(si.nTrackPos == 0, "expected 0\n");
2184 ok(si.nMin == 0, "expected 0\n");
2185 ok(si.nMax == 100, "expected 100\n");
2186 }
2187 else
2188 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2189
2190 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2191 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2192 {
2193 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2194 ok(si.nPage == 0, "expected 0\n");
2195 ok(si.nPos == 0, "expected 0\n");
2196 ok(si.nTrackPos == 0, "expected 0\n");
2197 ok(si.nMin == 0, "expected 0\n");
2198 ok(si.nMax == 100, "expected 100\n");
2199 }
2200 else
2201 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2202
2203 SetWindowPos(mdi_child, 0, -100, -100, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
2204
2205 si.cbSize = sizeof(si);
2206 si.fMask = SIF_ALL;
2207 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2208 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2209 {
2210 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2211 ok(si.nPage == 0, "expected 0\n");
2212 ok(si.nPos == 0, "expected 0\n");
2213 ok(si.nTrackPos == 0, "expected 0\n");
2214 ok(si.nMin == 0, "expected 0\n");
2215 ok(si.nMax == 100, "expected 100\n");
2216 }
2217 else
2218 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2219
2220 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2221 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2222 {
2223 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2224 ok(si.nPage == 0, "expected 0\n");
2225 ok(si.nPos == 0, "expected 0\n");
2226 ok(si.nTrackPos == 0, "expected 0\n");
2227 ok(si.nMin == 0, "expected 0\n");
2228 ok(si.nMax == 100, "expected 100\n");
2229 }
2230 else
2231 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2232
2233 gotit = FALSE;
2234 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2235 {
2236 if (msg.message == WM_MOUSEMOVE || msg.message == WM_PAINT)
2237 {
2238 DispatchMessageA(&msg);
2239 continue;
2240 }
2241
2242 if (msg.message == 0x003f) /* WM_MDICALCCHILDSCROLL ??? */
2243 {
2244 ok(msg.hwnd == mdi_client, "message 0x003f should be posted to mdiclient\n");
2245 gotit = TRUE;
2246 }
2247 else
2248 ok(msg.hwnd != mdi_client, "message %04x should not be posted to mdiclient\n", msg.message);
2249 DispatchMessageA(&msg);
2250 }
2251 ok(gotit, "message 0x003f should appear after SetWindowPos\n");
2252
2253 si.cbSize = sizeof(si);
2254 si.fMask = SIF_ALL;
2255 ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
2256 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2257 {
2258 ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
2259 todo_wine
2260 ok(si.nPage != 0, "expected !0\n");
2261 ok(si.nPos == 0, "expected 0\n");
2262 ok(si.nTrackPos == 0, "expected 0\n");
2263 ok(si.nMin != 0, "expected !0\n");
2264 ok(si.nMax != 100, "expected !100\n");
2265 }
2266 else
2267 ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
2268
2269 ret = GetScrollInfo(mdi_client, SB_VERT, &si);
2270 if (style[i] & (WS_HSCROLL | WS_VSCROLL))
2271 {
2272 ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
2273 todo_wine
2274 ok(si.nPage != 0, "expected !0\n");
2275 ok(si.nPos == 0, "expected 0\n");
2276 ok(si.nTrackPos == 0, "expected 0\n");
2277 ok(si.nMin != 0, "expected !0\n");
2278 ok(si.nMax != 100, "expected !100\n");
2279 }
2280 else
2281 ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
2282
2283 DestroyMenu(child_menu);
2284 DestroyWindow(mdi_child);
2285 DestroyWindow(mdi_client);
2286 }
2287
2288 SetMenu(mdi_hwndMain, frame_menu);
2289
2290 mdi_client = CreateWindowExA(0, "mdiclient", NULL,
2291 WS_CHILD,
2292 0, 0, rc.right, rc.bottom,
2293 mdi_hwndMain, 0, 0, &client_cs);
2294 ok(mdi_client != 0, "MDI client creation failed\n");
2295
2296 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
2297 0,
2298 CW_USEDEFAULT, CW_USEDEFAULT,
2299 CW_USEDEFAULT, CW_USEDEFAULT,
2300 mdi_client, 0, 0,
2301 mdi_lParam_test_message);
2302 ok(mdi_child != 0, "MDI child creation failed\n");
2303
2304 SendMessageW(mdi_child, WM_SIZE, SIZE_MAXIMIZED, 0);
2305 ok(GetMenuItemCount(frame_menu) == 4, "Frame menu should have 4 items after child maximize, but has %u\n",
2306 GetMenuItemCount(frame_menu));
2307
2308 child_menu = CreateMenu();
2309 SendMessageW(mdi_client, WM_MDISETMENU, 0, (LPARAM)child_menu);
2310
2311 ok(GetMenuItemCount(frame_menu) == 4, "Frame menu should have 4 items after WM_MDISETMENU, but has %u\n",
2312 GetMenuItemCount(frame_menu));
2313
2314 SendMessageW(mdi_child, WM_SIZE, SIZE_RESTORED, 0);
2315
2316 ok(GetMenuItemCount(frame_menu) == 0, "Frame menu should be empty after child restored, but has %u items\n",
2317 GetMenuItemCount(frame_menu));
2318
2319 DestroyMenu(child_menu);
2320 DestroyWindow(mdi_child);
2321 DestroyWindow(mdi_client);
2322
2323 /* MDIClient without MDIS_ALLCHILDSTYLES */
2324 mdi_client = CreateWindowExA(0, "mdiclient",
2325 NULL,
2326 WS_CHILD /*| WS_VISIBLE*/,
2327 /* tests depend on a not zero MDIClient size */
2328 0, 0, rc.right, rc.bottom,
2329 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2330 &client_cs);
2331 assert(mdi_client);
2332 test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
2333 DestroyWindow(mdi_client);
2334
2335 /* MDIClient with MDIS_ALLCHILDSTYLES */
2336 mdi_client = CreateWindowExA(0, "mdiclient",
2337 NULL,
2338 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
2339 /* tests depend on a not zero MDIClient size */
2340 0, 0, rc.right, rc.bottom,
2341 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2342 &client_cs);
2343 assert(mdi_client);
2344 test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
2345 DestroyWindow(mdi_client);
2346
2347 /* Test child window stack management */
2348 mdi_client = CreateWindowExA(0, "mdiclient",
2349 NULL,
2350 WS_CHILD,
2351 0, 0, rc.right, rc.bottom,
2352 mdi_hwndMain, 0, GetModuleHandleA(NULL),
2353 &client_cs);
2354 assert(mdi_client);
2355 test_MDI_child_stack(mdi_client);
2356 DestroyWindow(mdi_client);
2357 /*
2358 while(GetMessage(&msg, 0, 0, 0))
2359 {
2360 TranslateMessage(&msg);
2361 DispatchMessage(&msg);
2362 }
2363 */
2364 DestroyWindow(mdi_hwndMain);
2365 }
2366
2367 static void test_icons(void)
2368 {
2369 WNDCLASSEXA cls;
2370 HWND hwnd;
2371 HICON icon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
2372 HICON icon2 = LoadIconA(0, (LPCSTR)IDI_QUESTION);
2373 HICON small_icon = LoadImageA(0, (LPCSTR)IDI_APPLICATION, IMAGE_ICON,
2374 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
2375 HICON res;
2376
2377 cls.cbSize = sizeof(cls);
2378 cls.style = 0;
2379 cls.lpfnWndProc = DefWindowProcA;
2380 cls.cbClsExtra = 0;
2381 cls.cbWndExtra = 0;
2382 cls.hInstance = 0;
2383 cls.hIcon = LoadIconA(0, (LPCSTR)IDI_HAND);
2384 cls.hIconSm = small_icon;
2385 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
2386 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
2387 cls.lpszMenuName = NULL;
2388 cls.lpszClassName = "IconWindowClass";
2389
2390 RegisterClassExA(&cls);
2391
2392 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
2393 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
2394 assert( hwnd );
2395
2396 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2397 ok( res == 0, "wrong big icon %p/0\n", res );
2398 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
2399 ok( res == 0, "wrong previous big icon %p/0\n", res );
2400 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2401 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
2402 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
2403 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
2404 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2405 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2406
2407 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2408 ok( res == 0, "wrong small icon %p/0\n", res );
2409 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2410 ok( (res && res != small_icon && res != icon2) || broken(!res), "wrong small2 icon %p\n", res );
2411 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
2412 ok( res == 0, "wrong previous small icon %p/0\n", res );
2413 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2414 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
2415 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2416 ok( res == icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, icon );
2417 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
2418 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
2419 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
2420 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
2421 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
2422 ok( res == small_icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, small_icon );
2423
2424 /* make sure the big icon hasn't changed */
2425 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
2426 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
2427
2428 DestroyWindow( hwnd );
2429 }
2430
2431 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
2432 {
2433 if (msg == WM_NCCALCSIZE)
2434 {
2435 RECT *rect = (RECT *)lparam;
2436 /* first time around increase the rectangle, next time decrease it */
2437 if (rect->left == 100) InflateRect( rect, 10, 10 );
2438 else InflateRect( rect, -10, -10 );
2439 return 0;
2440 }
2441 return DefWindowProcA( hwnd, msg, wparam, lparam );
2442 }
2443
2444 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
2445 {
2446 RECT orig_win_rc, rect;
2447 LONG_PTR old_proc;
2448 HWND hwnd_grandchild, hwnd_child, hwnd_child2;
2449 HWND hwnd_desktop;
2450 RECT rc1, rc2;
2451 BOOL ret;
2452
2453 SetRect(&rect, 111, 222, 333, 444);
2454 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
2455 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2456 "wrong window rect %s\n", wine_dbgstr_rect(&rect));
2457
2458 SetRect(&rect, 111, 222, 333, 444);
2459 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
2460 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
2461 "wrong window rect %s\n", wine_dbgstr_rect(&rect));
2462
2463 GetWindowRect(hwnd, &orig_win_rc);
2464
2465 old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
2466 ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2467 ok(ret, "Got %d\n", ret);
2468 GetWindowRect( hwnd, &rect );
2469 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
2470 "invalid window rect %s\n", wine_dbgstr_rect(&rect));
2471 GetClientRect( hwnd, &rect );
2472 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2473 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
2474 "invalid client rect %s\n", wine_dbgstr_rect(&rect));
2475
2476 ret = SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
2477 ok(ret, "Got %d\n", ret);
2478 GetWindowRect( hwnd, &rect );
2479 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
2480 "invalid window rect %s\n", wine_dbgstr_rect(&rect));
2481 GetClientRect( hwnd, &rect );
2482 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
2483 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
2484 "invalid client rect %s\n", wine_dbgstr_rect(&rect));
2485
2486 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2487 orig_win_rc.right, orig_win_rc.bottom, 0);
2488 ok(ret, "Got %d\n", ret);
2489 SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
2490
2491 /* Win9x truncates coordinates to 16-bit irrespectively */
2492 if (!is_win9x)
2493 {
2494 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
2495 ok(ret, "Got %d\n", ret);
2496 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
2497 ok(ret, "Got %d\n", ret);
2498
2499 ret = SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
2500 ok(ret, "Got %d\n", ret);
2501 ret = SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
2502 ok(ret, "Got %d\n", ret);
2503 }
2504
2505 ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
2506 orig_win_rc.right, orig_win_rc.bottom, 0);
2507 ok(ret, "Got %d\n", ret);
2508
2509 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2510 ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2511 ok(ret, "Got %d\n", ret);
2512 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2513 ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2514 ok(ret, "Got %d\n", ret);
2515 ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
2516 ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
2517 ok(ret, "Got %d\n", ret);
2518 ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
2519
2520 hwnd_desktop = GetDesktopWindow();
2521 ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
2522 hwnd_child = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2523 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2524 hwnd_grandchild = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd_child);
2525 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2526 hwnd_child2 = create_tool_window(WS_VISIBLE|WS_CHILD, hwnd);
2527 ok(!!hwnd_child2, "Failed to create second child window (%d)\n", GetLastError());
2528
2529 ret = SetWindowPos(hwnd, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2530 ok(ret, "Got %d\n", ret);
2531 check_active_state(hwnd, hwnd, hwnd);
2532
2533 ret = SetWindowPos(hwnd2, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2534 ok(ret, "Got %d\n", ret);
2535 check_active_state(hwnd2, hwnd2, hwnd2);
2536
2537 /* Returns TRUE also for windows that are not siblings */
2538 ret = SetWindowPos(hwnd_child, hwnd2, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2539 ok(ret, "Got %d\n", ret);
2540 check_active_state(hwnd2, hwnd2, hwnd2);
2541
2542 ret = SetWindowPos(hwnd2, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2543 ok(ret, "Got %d\n", ret);
2544 check_active_state(hwnd2, hwnd2, hwnd2);
2545
2546 /* Does not seem to do anything even without passing flags, still returns TRUE */
2547 GetWindowRect(hwnd_child, &rc1);
2548 ret = SetWindowPos(hwnd_child, hwnd2 , 1, 2, 3, 4, 0);
2549 ok(ret, "Got %d\n", ret);
2550 GetWindowRect(hwnd_child, &rc2);
2551 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2552 check_active_state(hwnd2, hwnd2, hwnd2);
2553
2554 /* Same thing the other way around. */
2555 GetWindowRect(hwnd2, &rc1);
2556 ret = SetWindowPos(hwnd2, hwnd_child, 1, 2, 3, 4, 0);
2557 ok(ret, "Got %d\n", ret);
2558 GetWindowRect(hwnd2, &rc2);
2559 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2560 check_active_state(hwnd2, hwnd2, hwnd2);
2561
2562 /* .. and with these windows. */
2563 GetWindowRect(hwnd_grandchild, &rc1);
2564 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, 0);
2565 ok(ret, "Got %d\n", ret);
2566 GetWindowRect(hwnd_grandchild, &rc2);
2567 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2568 check_active_state(hwnd2, hwnd2, hwnd2);
2569
2570 /* Add SWP_NOZORDER and it will be properly resized. */
2571 GetWindowRect(hwnd_grandchild, &rc1);
2572 ret = SetWindowPos(hwnd_grandchild, hwnd_child2, 1, 2, 3, 4, SWP_NOZORDER);
2573 ok(ret, "Got %d\n", ret);
2574 GetWindowRect(hwnd_grandchild, &rc2);
2575 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2576 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2577 "(%d,%d)-(%d,%d) != %s\n", rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6,
2578 wine_dbgstr_rect(&rc2));
2579 check_active_state(hwnd2, hwnd2, hwnd2);
2580
2581 /* Given a sibling window, the window is properly resized. */
2582 GetWindowRect(hwnd_child, &rc1);
2583 ret = SetWindowPos(hwnd_child, hwnd_child2, 1, 2, 3, 4, 0);
2584 ok(ret, "Got %d\n", ret);
2585 GetWindowRect(hwnd_child, &rc2);
2586 ok((rc1.left+1) == rc2.left && (rc1.top+2) == rc2.top &&
2587 (rc1.left+4) == rc2.right && (rc1.top+6) == rc2.bottom,
2588 "(%d,%d)-(%d,%d) != %s\n", rc1.left+1, rc1.top+2, rc1.left+4, rc1.top+6,
2589 wine_dbgstr_rect(&rc2));
2590 check_active_state(hwnd2, hwnd2, hwnd2);
2591
2592 /* Involving the desktop window changes things. */
2593 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2594 ok(!ret, "Got %d\n", ret);
2595 check_active_state(hwnd2, hwnd2, hwnd2);
2596
2597 GetWindowRect(hwnd_child, &rc1);
2598 ret = SetWindowPos(hwnd_child, hwnd_desktop, 0, 0, 0, 0, 0);
2599 ok(!ret, "Got %d\n", ret);
2600 GetWindowRect(hwnd_child, &rc2);
2601 ok(EqualRect(&rc1, &rc2), "%s != %s\n", wine_dbgstr_rect(&rc1), wine_dbgstr_rect(&rc2));
2602 check_active_state(hwnd2, hwnd2, hwnd2);
2603
2604 ret = SetWindowPos(hwnd_desktop, hwnd_child, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2605 ok(!ret, "Got %d\n", ret);
2606 check_active_state(hwnd2, hwnd2, hwnd2);
2607
2608 ret = SetWindowPos(hwnd_desktop, hwnd, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2609 ok(!ret, "Got %d\n", ret);
2610 check_active_state(hwnd2, hwnd2, hwnd2);
2611
2612 ret = SetWindowPos(hwnd, hwnd_desktop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
2613 ok(!ret, "Got %d\n", ret);
2614 check_active_state(hwnd2, hwnd2, hwnd2);
2615
2616 DestroyWindow(hwnd_grandchild);
2617 DestroyWindow(hwnd_child);
2618 DestroyWindow(hwnd_child2);
2619
2620 hwnd_child = create_tool_window(WS_CHILD|WS_POPUP|WS_SYSMENU, hwnd2);
2621 ok(!!hwnd_child, "Failed to create child window (%d)\n", GetLastError());
2622 ret = SetWindowPos(hwnd_child, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2623 ok(ret, "Got %d\n", ret);
2624 flush_events( TRUE );
2625 todo_wine check_active_state(hwnd2, hwnd2, hwnd2);
2626 DestroyWindow(hwnd_child);
2627 }
2628
2629 static void test_SetMenu(HWND parent)
2630 {
2631 HWND child;
2632 HMENU hMenu, ret;
2633 BOOL retok;
2634 DWORD style;
2635
2636 hMenu = CreateMenu();
2637 assert(hMenu);
2638
2639 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2640 if (0)
2641 {
2642 /* fails on (at least) Wine, NT4, XP SP2 */
2643 test_nonclient_area(parent);
2644 }
2645 ret = GetMenu(parent);
2646 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2647 /* test whether we can destroy a menu assigned to a window */
2648 retok = DestroyMenu(hMenu);
2649 ok( retok, "DestroyMenu error %d\n", GetLastError());
2650 retok = IsMenu(hMenu);
2651 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
2652 ret = GetMenu(parent);
2653 /* This test fails on Win9x */
2654 if (!is_win9x)
2655 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2656 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2657 test_nonclient_area(parent);
2658
2659 hMenu = CreateMenu();
2660 assert(hMenu);
2661
2662 /* parent */
2663 ret = GetMenu(parent);
2664 ok(ret == 0, "unexpected menu id %p\n", ret);
2665
2666 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2667 test_nonclient_area(parent);
2668 ret = GetMenu(parent);
2669 ok(ret == 0, "unexpected menu id %p\n", ret);
2670
2671 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
2672 if (0)
2673 {
2674 /* fails on (at least) Wine, NT4, XP SP2 */
2675 test_nonclient_area(parent);
2676 }
2677 ret = GetMenu(parent);
2678 ok(ret == hMenu, "unexpected menu id %p\n", ret);
2679
2680 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
2681 test_nonclient_area(parent);
2682 ret = GetMenu(parent);
2683 ok(ret == 0, "unexpected menu id %p\n", ret);
2684
2685 /* child */
2686 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
2687 assert(child);
2688
2689 ret = GetMenu(child);
2690 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2691
2692 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
2693 test_nonclient_area(child);
2694 ret = GetMenu(child);
2695 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2696
2697 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
2698 test_nonclient_area(child);
2699 ret = GetMenu(child);
2700 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2701
2702 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
2703 test_nonclient_area(child);
2704 ret = GetMenu(child);
2705 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
2706
2707 style = GetWindowLongA(child, GWL_STYLE);
2708 SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
2709 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
2710 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
2711 SetWindowLongA(child, GWL_STYLE, style);
2712
2713 SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
2714 ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
2715 SetWindowLongA(child, GWL_STYLE, style);
2716
2717 DestroyWindow(child);
2718 DestroyMenu(hMenu);
2719 }
2720
2721 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
2722 {
2723 HWND child[5], hwnd;
2724 INT_PTR i;
2725
2726 assert(total <= 5);
2727
2728 hwnd = GetWindow(parent, GW_CHILD);
2729 ok(!hwnd, "have to start without children to perform the test\n");
2730
2731 for (i = 0; i < total; i++)
2732 {
2733 if (style[i] & DS_CONTROL)
2734 {
2735 child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2736 0,0,0,0, parent, (HMENU)i, 0, NULL);
2737 if (style[i] & WS_VISIBLE)
2738 ShowWindow(child[i], SW_SHOW);
2739
2740 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2741 }
2742 else
2743 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2744 parent, (HMENU)i, 0, NULL);
2745 trace("child[%ld] = %p\n", i, child[i]);
2746 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2747 }
2748
2749 hwnd = GetWindow(parent, GW_CHILD);
2750 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2751 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2752 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2753
2754 for (i = 0; i < total; i++)
2755 {
2756 trace("hwnd[%ld] = %p\n", i, hwnd);
2757 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2758
2759 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2760 }
2761
2762 for (i = 0; i < total; i++)
2763 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2764 }
2765
2766 static void test_children_zorder(HWND parent)
2767 {
2768 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2769 WS_CHILD };
2770 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2771
2772 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2773 WS_CHILD | WS_VISIBLE, WS_CHILD,
2774 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2775 const int complex_order_1[1] = { 0 };
2776 const int complex_order_2[2] = { 1, 0 };
2777 const int complex_order_3[3] = { 1, 0, 2 };
2778 const int complex_order_4[4] = { 1, 0, 2, 3 };
2779 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2780 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2781 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2782 WS_CHILD | WS_VISIBLE };
2783 const int complex_order_6[3] = { 0, 1, 2 };
2784
2785 /* simple WS_CHILD */
2786 test_window_tree(parent, simple_style, simple_order, 5);
2787
2788 /* complex children styles */
2789 test_window_tree(parent, complex_style, complex_order_1, 1);
2790 test_window_tree(parent, complex_style, complex_order_2, 2);
2791 test_window_tree(parent, complex_style, complex_order_3, 3);
2792 test_window_tree(parent, complex_style, complex_order_4, 4);
2793 test_window_tree(parent, complex_style, complex_order_5, 5);
2794
2795 /* another set of complex children styles */
2796 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2797 }
2798
2799 #define check_z_order(hwnd, next, prev, owner, topmost) \
2800 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2801 __FILE__, __LINE__)
2802
2803 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2804 BOOL topmost, const char *file, int line)
2805 {
2806 HWND test;
2807 DWORD ex_style;
2808
2809 test = GetWindow(hwnd, GW_HWNDNEXT);
2810 /* skip foreign windows */
2811 while (test && test != next &&
2812 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2813 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2814 GetWindow(test, GW_OWNER) == next))
2815 {
2816 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2817 test = GetWindow(test, GW_HWNDNEXT);
2818 }
2819 ok_(file, line)(next == test, "%p: expected next %p, got %p\n", hwnd, next, test);
2820
2821 test = GetWindow(hwnd, GW_HWNDPREV);
2822 /* skip foreign windows */
2823 while (test && test != prev &&
2824 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2825 UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
2826 GetWindow(test, GW_OWNER) == hwnd))
2827 {
2828 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2829 test = GetWindow(test, GW_HWNDPREV);
2830 }
2831 ok_(file, line)(prev == test, "%p: expected prev %p, got %p\n", hwnd, prev, test);
2832
2833 test = GetWindow(hwnd, GW_OWNER);
2834 ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
2835
2836 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
2837 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
2838 hwnd, topmost ? "" : "NOT ");
2839 }
2840
2841 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
2842 {
2843 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2844
2845 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2846
2847 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2848
2849 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2850 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2851
2852 hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
2853 WS_OVERLAPPED | WS_CAPTION,
2854 100, 100, 100, 100,
2855 0, 0, GetModuleHandleA(NULL), NULL);
2856 trace("hwnd_F %p\n", hwnd_F);
2857 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2858
2859 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2860 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2861 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2862 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2863
2864 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2865 style,
2866 100, 100, 100, 100,
2867 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2868 trace("hwnd_C %p\n", hwnd_C);
2869 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2870 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2871 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2872 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2873
2874 hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2875 style,
2876 100, 100, 100, 100,
2877 hwnd_F, 0, GetModuleHandleA(NULL), NULL);
2878 trace("hwnd_B %p\n", hwnd_B);
2879 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2880 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2881 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2882 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2883 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2884
2885 hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
2886 style,
2887 100, 100, 100, 100,
2888 0, 0, GetModuleHandleA(NULL), NULL);
2889 trace("hwnd_A %p\n", hwnd_A);
2890 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2891 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2892 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2893 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2894 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2895 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2896
2897 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);
2898
2899 /* move hwnd_F and its popups up */
2900 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2901 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2902 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2903 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2904 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2905 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2906 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2907
2908 /* move hwnd_F and its popups down */
2909 #if 0 /* enable once Wine is fixed to pass this test */
2910 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2911 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2912 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2913 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2914 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2915 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2916 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2917 #endif
2918
2919 /* make hwnd_C owned by a topmost window */
2920 DestroyWindow( hwnd_C );
2921 hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
2922 style,
2923 100, 100, 100, 100,
2924 hwnd_A, 0, GetModuleHandleA(NULL), NULL);
2925 trace("hwnd_C %p\n", hwnd_C);
2926 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2927 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2928 check_z_order(hwnd_F, hwnd_D, hwnd_B, 0, FALSE);
2929 check_z_order(hwnd_B, hwnd_F, hwnd_A, hwnd_F, TRUE);
2930 check_z_order(hwnd_A, hwnd_B, hwnd_C, 0, TRUE);
2931 check_z_order(hwnd_C, hwnd_A, 0, hwnd_A, TRUE);
2932
2933 DestroyWindow(hwnd_A);
2934 DestroyWindow(hwnd_B);
2935 DestroyWindow(hwnd_C);
2936 DestroyWindow(hwnd_F);
2937 }
2938
2939 static void test_vis_rgn( HWND hwnd )
2940 {
2941 RECT win_rect, rgn_rect;
2942 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2943 HDC hdc;
2944
2945 ShowWindow(hwnd,SW_SHOW);
2946 hdc = GetDC( hwnd );
2947 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2948 GetWindowRect( hwnd, &win_rect );
2949 GetRgnBox( hrgn, &rgn_rect );
2950 if (is_win9x)
2951 {
2952 trace("win9x, mapping to screen coords\n");
2953 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2954 }
2955 trace("win: %s\n", wine_dbgstr_rect(&win_rect));
2956 trace("rgn: %s\n", wine_dbgstr_rect(&rgn_rect));
2957 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2958 rgn_rect.left, win_rect.left );
2959 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2960 rgn_rect.top, win_rect.top );
2961 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2962 rgn_rect.right, win_rect.right );
2963 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2964 rgn_rect.bottom, win_rect.bottom );
2965 ReleaseDC( hwnd, hdc );
2966 }
2967
2968 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2969 {
2970 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2971 {
2972 HWND child = GetWindow(hwnd, GW_CHILD);
2973 ok(child != 0, "couldn't find child window\n");
2974 SetFocus(child);
2975 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2976 return 0;
2977 }
2978 return DefWindowProcA(hwnd, msg, wp, lp);
2979 }
2980
2981 static void test_SetFocus(HWND hwnd)
2982 {
2983 HWND child, child2, ret;
2984 WNDPROC old_wnd_proc;
2985
2986 /* check if we can set focus to non-visible windows */
2987
2988 ShowWindow(hwnd, SW_SHOW);
2989 SetFocus(0);
2990 SetFocus(hwnd);
2991 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2992 ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2993 ShowWindow(hwnd, SW_HIDE);
2994 SetFocus(0);
2995 SetFocus(hwnd);
2996 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2997 ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2998 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2999 assert(child);
3000 SetFocus(child);
3001 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
3002 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3003 ShowWindow(child, SW_SHOW);
3004 ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
3005 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
3006 ShowWindow(child, SW_HIDE);
3007 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3008 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
3009 ShowWindow(child, SW_SHOW);
3010 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
3011 assert(child2);
3012 ShowWindow(child2, SW_SHOW);
3013 SetFocus(child2);
3014 ShowWindow(child, SW_HIDE);
3015 ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
3016 ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
3017 ShowWindow(child, SW_SHOW);
3018 SetFocus(child);
3019 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3020 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
3021 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
3022
3023 ShowWindow(child, SW_HIDE);
3024 SetFocus(hwnd);
3025 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
3026 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
3027 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
3028 ShowWindow(child, SW_HIDE);
3029 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
3030
3031 ShowWindow(hwnd, SW_SHOW);
3032 ShowWindow(child, SW_SHOW);
3033 SetFocus(child);
3034 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3035 EnableWindow(hwnd, FALSE);
3036 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
3037 EnableWindow(hwnd, TRUE);
3038
3039 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3040 ShowWindow(hwnd, SW_SHOWMINIMIZED);
3041 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3042 todo_wine
3043 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
3044 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
3045 ShowWindow(hwnd, SW_RESTORE);
3046 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3047 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3048 ShowWindow(hwnd, SW_SHOWMINIMIZED);
3049 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3050 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
3051 todo_wine
3052 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
3053 old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
3054 ShowWindow(hwnd, SW_RESTORE);
3055 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3056 todo_wine
3057 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
3058 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
3059
3060 SetFocus( hwnd );
3061 SetParent( child, GetDesktopWindow());
3062 SetParent( child2, child );
3063 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3064 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3065 ret = SetFocus( child2 );
3066 ok( ret == 0, "SetFocus %p should fail\n", child2);
3067 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3068 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3069 ret = SetFocus( child );
3070 ok( ret == 0, "SetFocus %p should fail\n", child);
3071 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3072 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3073 SetWindowLongW( child, GWL_STYLE, WS_POPUP|WS_CHILD );
3074 SetFocus( child2 );
3075 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
3076 ok( GetFocus() == child2, "Focus should be on child2 %p\n", child2 );
3077 SetFocus( hwnd );
3078 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
3079 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
3080 SetFocus( child );
3081 ok( GetActiveWindow() == child, "child window %p should be active\n", child);
3082 ok( GetFocus() == child, "Focus should be on child %p\n", child );
3083
3084 DestroyWindow( child2 );
3085 DestroyWindow( child );
3086 }
3087
3088 static void test_SetActiveWindow(HWND hwnd)
3089 {
3090 HWND hwnd2;
3091
3092 flush_events( TRUE );
3093 ShowWindow(hwnd, SW_HIDE);
3094 SetFocus(0);
3095 SetActiveWindow(0);
3096 check_wnd_state(0, 0, 0, 0);
3097
3098 /*trace("testing SetActiveWindow %p\n", hwnd);*/
3099
3100 ShowWindow(hwnd, SW_SHOW);
3101 check_wnd_state(hwnd, hwnd, hwnd, 0);
3102
3103 hwnd2 = SetActiveWindow(0);
3104 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
3105 if (!GetActiveWindow()) /* doesn't always work on vista */
3106 {
3107 check_wnd_state(0, 0, 0, 0);
3108 hwnd2 = SetActiveWindow(hwnd);
3109 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
3110 }
3111 check_wnd_state(hwnd, hwnd, hwnd, 0);
3112
3113 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3114 check_wnd_state(hwnd, hwnd, hwnd, 0);
3115
3116 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
3117 check_wnd_state(hwnd, hwnd, hwnd, 0);
3118
3119 ShowWindow(hwnd, SW_HIDE);
3120 check_wnd_state(0, 0, 0, 0);
3121
3122 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
3123 SetActiveWindow(hwnd);
3124 check_wnd_state(hwnd, hwnd, hwnd, 0);
3125
3126 ShowWindow(hwnd, SW_SHOW);
3127 check_wnd_state(hwnd, hwnd, hwnd, 0);
3128
3129 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3130 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3131
3132 DestroyWindow(hwnd2);
3133 check_wnd_state(hwnd, hwnd, hwnd, 0);
3134
3135 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3136 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3137
3138 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3139 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3140
3141 DestroyWindow(hwnd2);
3142 check_wnd_state(hwnd, hwnd, hwnd, 0);
3143 }
3144
3145 struct create_window_thread_params
3146 {
3147 HWND window;
3148 HANDLE window_created;
3149 HANDLE test_finished;
3150 };
3151
3152 static DWORD WINAPI create_window_thread(void *param)
3153 {
3154 struct create_window_thread_params *p = param;
3155 DWORD res;
3156 BOOL ret;
3157
3158 p->window = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
3159
3160 ret = SetEvent(p->window_created);
3161 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
3162
3163 res = WaitForSingleObject(p->test_finished, INFINITE);
3164 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3165
3166 DestroyWindow(p->window);
3167 return 0;
3168 }
3169
3170 static void test_SetForegroundWindow(HWND hwnd)
3171 {
3172 struct create_window_thread_params thread_params;
3173 HANDLE thread;
3174 DWORD res, tid;
3175 BOOL ret;
3176 HWND hwnd2;
3177 MSG msg;
3178 LONG style;
3179
3180 flush_events( TRUE );
3181 ShowWindow(hwnd, SW_HIDE);
3182 SetFocus(0);
3183 SetActiveWindow(0);
3184 check_wnd_state(0, 0, 0, 0);
3185
3186 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
3187
3188 ShowWindow(hwnd, SW_SHOW);
3189 check_wnd_state(hwnd, hwnd, hwnd, 0);
3190
3191 hwnd2 = SetActiveWindow(0);
3192 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
3193 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
3194 check_wnd_state(hwnd, hwnd, hwnd, 0);
3195 else
3196 check_wnd_state(0, 0, 0, 0);
3197
3198 ret = SetForegroundWindow(hwnd);
3199 if (!ret)
3200 {
3201 skip( "SetForegroundWindow not working\n" );
3202 return;
3203 }
3204 check_wnd_state(hwnd, hwnd, hwnd, 0);
3205
3206 SetLastError(0xdeadbeef);
3207 ret = SetForegroundWindow(0);
3208 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
3209 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
3210 broken(GetLastError() == 0xdeadbeef), /* win9x */
3211 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
3212 check_wnd_state(hwnd, hwnd, hwnd, 0);
3213
3214 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3215 check_wnd_state(hwnd, hwnd, hwnd, 0);
3216
3217 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
3218 check_wnd_state(hwnd, hwnd, hwnd, 0);
3219
3220 hwnd2 = GetForegroundWindow();
3221 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
3222 ret = SetForegroundWindow( GetDesktopWindow() );
3223 ok(ret, "SetForegroundWindow(desktop) error: %d\n", GetLastError());
3224 hwnd2 = GetForegroundWindow();
3225 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
3226
3227 ShowWindow(hwnd, SW_HIDE);
3228 check_wnd_state(0, 0, 0, 0);
3229
3230 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
3231 ret = SetForegroundWindow(hwnd);
3232 ok(ret || broken(!ret), /* win98 */ "SetForegroundWindow returned FALSE instead of TRUE\n");
3233 check_wnd_state(hwnd, hwnd, hwnd, 0);
3234
3235 ShowWindow(hwnd, SW_SHOW);
3236 check_wnd_state(hwnd, hwnd, hwnd, 0);
3237
3238 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3239 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3240
3241 DestroyWindow(hwnd2);
3242 check_wnd_state(hwnd, hwnd, hwnd, 0);
3243
3244 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
3245 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3246
3247 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
3248 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3249
3250 DestroyWindow(hwnd2);
3251 check_wnd_state(hwnd, hwnd, hwnd, 0);
3252
3253 hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
3254 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3255
3256 thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
3257 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
3258 thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
3259 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
3260 thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
3261 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
3262 res = WaitForSingleObject(thread_params.window_created, INFINITE);
3263 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
3264 check_wnd_state(hwnd2, thread_params.window, hwnd2, 0);
3265
3266 SetForegroundWindow(hwnd2);
3267 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3268
3269 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
3270 if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3271 todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
3272 todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
3273
3274 SetForegroundWindow(hwnd);
3275 check_wnd_state(hwnd, hwnd, hwnd, 0);
3276 style = GetWindowLongA(hwnd2, GWL_STYLE) | WS_CHILD;
3277 ok(SetWindowLongA(hwnd2, GWL_STYLE, style), "SetWindowLong failed\n");
3278 ok(SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
3279 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
3280
3281 SetForegroundWindow(hwnd);
3282 check_wnd_state(hwnd, hwnd, hwnd, 0);
3283 ok(SetWindowLongA(hwnd2, GWL_STYLE, style & (~WS_POPUP)), "SetWindowLong failed\n");
3284 ok(!SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
3285 check_wnd_state(hwnd, hwnd, hwnd, 0);
3286
3287 SetEvent(thread_params.test_finished);
3288 WaitForSingleObject(thread, INFINITE);
3289 CloseHandle(thread_params.test_finished);
3290 CloseHandle(thread_params.window_created);
3291 CloseHandle(thread);
3292 DestroyWindow(hwnd2);
3293 }
3294
3295 static WNDPROC old_button_proc;
3296
3297 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
3298 {
3299 LRESULT ret;
3300 USHORT key_state;
3301
3302 key_state = GetKeyState(VK_LBUTTON);
3303 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
3304
3305 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
3306
3307 if (msg == WM_LBUTTONDOWN)
3308 {
3309 HWND hwnd, capture;
3310
3311 check_wnd_state(button, button, button, button);
3312
3313 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3314 assert(hwnd);
3315 trace("hwnd %p\n", hwnd);
3316
3317 check_wnd_state(button, button, button, button);
3318
3319 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3320
3321 check_wnd_state(button, button, button, button);
3322
3323 DestroyWindow(hwnd);
3324
3325 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3326 assert(hwnd);
3327 trace("hwnd %p\n", hwnd);
3328
3329 check_wnd_state(button, button, button, button);
3330
3331 /* button wnd proc should release capture on WM_KILLFOCUS if it does
3332 * match internal button state.
3333 */
3334 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3335 check_wnd_state(button, button, button, 0);
3336
3337 ShowWindow(hwnd, SW_SHOW);
3338 check_wnd_state(hwnd, hwnd, hwnd, 0);
3339
3340 capture = SetCapture(hwnd);
3341 ok(capture == 0, "SetCapture() = %p\n", capture);
3342
3343 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3344
3345 DestroyWindow(hwnd);
3346
3347 check_wnd_state(button, 0, button, 0);
3348 }
3349
3350 return ret;
3351 }
3352
3353 static void test_capture_1(void)
3354 {
3355 HWND button, capture;
3356
3357 capture = GetCapture();
3358 ok(capture == 0, "GetCapture() = %p\n", capture);
3359
3360 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3361 assert(button);
3362 trace("button %p\n", button);
3363
3364 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
3365
3366 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
3367
3368 capture = SetCapture(button);
3369 ok(capture == 0, "SetCapture() = %p\n", capture);
3370 check_wnd_state(button, 0, button, button);
3371
3372 DestroyWindow(button);
3373 /* old active window test depends on previously executed window
3374 * activation tests, and fails under NT4.
3375 check_wnd_state(oldActive, 0, oldFocus, 0);*/
3376 }
3377
3378 static void test_capture_2(void)
3379 {
3380 HWND button, hwnd, capture, oldFocus, oldActive;
3381
3382 oldFocus = GetFocus();
3383 oldActive = GetActiveWindow();
3384 check_wnd_state(oldActive, 0, oldFocus, 0);
3385
3386 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
3387 assert(button);
3388 trace("button %p\n", button);
3389
3390 check_wnd_state(button, button, button, 0);
3391
3392 capture = SetCapture(button);
3393 ok(capture == 0, "SetCapture() = %p\n", capture);
3394
3395 check_wnd_state(button, button, button, button);
3396
3397 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
3398 * internal button state.
3399 */
3400 SendMessageA(button, WM_KILLFOCUS, 0, 0);
3401 check_wnd_state(button, button, button, button);
3402
3403 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3404 assert(hwnd);
3405 trace("hwnd %p\n", hwnd);
3406
3407 check_wnd_state(button, button, button, button);
3408
3409 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
3410
3411 check_wnd_state(button, button, button, button);
3412
3413 DestroyWindow(hwnd);
3414
3415 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
3416 assert(hwnd);
3417 trace("hwnd %p\n", hwnd);
3418
3419 check_wnd_state(button, button, button, button);
3420
3421 ShowWindow(hwnd, SW_SHOW);
3422
3423 check_wnd_state(hwnd, hwnd, hwnd, button);
3424
3425 capture = SetCapture(hwnd);
3426 ok(capture == button, "SetCapture() = %p\n", capture);
3427
3428 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
3429
3430 DestroyWindow(hwnd);
3431 check_wnd_state(button, button, button, 0);
3432
3433 DestroyWindow(button);
3434 check_wnd_state(oldActive, 0, oldFocus, 0);
3435 }
3436
3437 static void test_capture_3(HWND hwnd1, HWND hwnd2)
3438 {
3439 BOOL ret;
3440
3441 ShowWindow(hwnd1, SW_HIDE);
3442 ShowWindow(hwnd2, SW_HIDE);
3443
3444 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
3445 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
3446
3447 SetCapture(hwnd1);
3448 check_wnd_state(0, 0, 0, hwnd1);
3449
3450 SetCapture(hwnd2);
3451 check_wnd_state(0, 0, 0, hwnd2);
3452
3453 ShowWindow(hwnd1, SW_SHOW);
3454 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
3455
3456 ret = ReleaseCapture();
3457 ok (ret, "releasecapture did not return TRUE.\n");
3458 ret = ReleaseCapture();
3459 ok (ret, "releasecapture did not return TRUE after second try.\n");
3460 }
3461
3462 static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
3463 {
3464 GUITHREADINFO gti;
3465 HWND cap_wnd, cap_wnd2, set_cap_wnd;
3466 BOOL status;
3467 switch (msg)
3468 {
3469 case WM_CAPTURECHANGED:
3470
3471 /* now try to release capture from menu. this should fail */
3472 if (pGetGUIThreadInfo)
3473 {
3474 memset(&gti, 0, sizeof(GUITHREADINFO));
3475 gti.cbSize = sizeof(GUITHREADINFO);
3476 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3477 ok(status, "GetGUIThreadInfo() failed!\n");
3478 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3479 }
3480 cap_wnd = GetCapture();
3481
3482 ok(cap_wnd == (HWND)lParam, "capture window %p does not match lparam %lx\n", cap_wnd, lParam);
3483 todo_wine ok(cap_wnd == hWnd, "capture window %p does not match hwnd %p\n", cap_wnd, hWnd);
3484
3485 /* check that re-setting the capture for the menu fails */
3486 set_cap_wnd = SetCapture(cap_wnd);
3487 ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
3488 "SetCapture should have failed!\n");
3489 if (set_cap_wnd)
3490 {
3491 DestroyWindow(hWnd);
3492 break;
3493 }
3494
3495 /* check that SetCapture fails for another window and that it does not touch the error code */
3496 set_cap_wnd = SetCapture(hWnd);
3497 ok(!set_cap_wnd, "SetCapture should have failed!\n");
3498
3499 /* check that ReleaseCapture fails and does not touch the error code */
3500 status = ReleaseCapture();
3501 ok(!status, "ReleaseCapture should have failed!\n");
3502
3503 /* check that thread info did not change */
3504 if (pGetGUIThreadInfo)
3505 {
3506 memset(&gti, 0, sizeof(GUITHREADINFO));
3507 gti.cbSize = sizeof(GUITHREADINFO);
3508 status = pGetGUIThreadInfo(GetCurrentThreadId(), &gti);
3509 ok(status, "GetGUIThreadInfo() failed!\n");
3510 ok(gti.flags & GUI_INMENUMODE, "Thread info incorrect (flags=%08X)!\n", gti.flags);
3511 }
3512
3513 /* verify that no capture change took place */
3514 cap_wnd2 = GetCapture();
3515 ok(cap_wnd2 == cap_wnd, "Capture changed!\n");
3516
3517 /* we are done. kill the window */
3518 DestroyWindow(hWnd);
3519 break;
3520
3521 default:
3522 return( DefWindowProcA( hWnd, msg, wParam, lParam ) );
3523 }
3524 return 0;
3525 }
3526
3527 /* Test that no-one can mess around with the current capture while a menu is open */
3528 static void test_capture_4(void)
3529 {
3530 BOOL ret;
3531 HMENU hmenu;
3532 HWND hwnd;
3533 WNDCLASSA wclass;
3534 HINSTANCE hInstance = GetModuleHandleA( NULL );
3535 ATOM aclass;
3536
3537 if (!pGetGUIThreadInfo)
3538 {
3539 win_skip("GetGUIThreadInfo is not available\n");
3540 return;
3541 }
3542 wclass.lpszClassName = "TestCapture4Class";
3543 wclass.style = CS_HREDRAW | CS_VREDRAW;
3544 wclass.lpfnWndProc = test_capture_4_proc;
3545 wclass.hInstance = hInstance;
3546 wclass.hIcon = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
3547 wclass.hCursor = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
3548 wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
3549 wclass.lpszMenuName = 0;
3550 wclass.cbClsExtra = 0;
3551 wclass.cbWndExtra = 0;
3552 aclass = RegisterClassA( &wclass );
3553 ok( aclass, "RegisterClassA failed with error %d\n", GetLastError());
3554 hwnd = CreateWindowA( wclass.lpszClassName, "MenuTest",
3555 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0,
3556 400, 200, NULL, NULL, hInstance, NULL);
3557 ok(hwnd != NULL, "CreateWindowEx failed with error %d\n", GetLastError());
3558 if (!hwnd) return;
3559 hmenu = CreatePopupMenu();
3560
3561 ret = AppendMenuA( hmenu, MF_STRING, 1, "winetest2");
3562 ok( ret, "AppendMenuA has failed!\n");
3563
3564 /* set main window to have initial capture */
3565 SetCapture(hwnd);
3566
3567 if (is_win9x)
3568 {
3569 win_skip("TrackPopupMenu test crashes on Win9x/WinMe\n");
3570 }
3571 else
3572 {
3573 /* create popup (it will self-destruct) */
3574 ret = TrackPopupMenu(hmenu, TPM_RETURNCMD, 100, 100, 0, hwnd, NULL);
3575 ok( ret == 0, "TrackPopupMenu returned %d expected zero\n", ret);
3576 }
3577
3578 /* clean up */
3579 DestroyMenu(hmenu);
3580 DestroyWindow(hwnd);
3581 }
3582
3583 /* PeekMessage wrapper that ignores the messages we don't care about */
3584 static BOOL peek_message( MSG *msg )
3585 {
3586 BOOL ret;
3587 do
3588 {
3589 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
3590 } while (ret && ignore_message(msg->message));
3591 return ret;
3592 }
3593
3594 static void test_keyboard_input(HWND hwnd)
3595 {
3596 MSG msg;
3597 BOOL ret;
3598
3599 flush_events( TRUE );
3600 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
3601 UpdateWindow(hwnd);
3602 flush_events( TRUE );
3603
3604 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
3605
3606 SetFocus(hwnd);
3607 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3608
3609 flush_events( TRUE );
3610
3611 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3612 ret = peek_message(&msg);
3613 ok( ret, "no message available\n");
3614 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3615 ret = peek_message(&msg);
3616 ok( !ret, "message %04x available\n", msg.message);
3617
3618 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3619
3620 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3621 ret = peek_message(&msg);
3622 ok(ret, "no message available\n");
3623 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3624 ret = peek_message(&msg);
3625 ok( !ret, "message %04x available\n", msg.message);
3626
3627 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
3628
3629 keybd_event(VK_SPACE, 0, 0, 0);
3630 if (!peek_message(&msg))
3631 {
3632 skip( "keybd_event didn't work, skipping keyboard test\n" );
3633 return;
3634 }
3635 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3636 ret = peek_message(&msg);
3637 ok( !ret, "message %04x available\n", msg.message);
3638
3639 SetFocus(0);
3640 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3641
3642 flush_events( TRUE );
3643
3644 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
3645 ret = peek_message(&msg);
3646 ok(ret, "no message available\n");
3647 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3648 ret = peek_message(&msg);
3649 ok( !ret, "message %04x available\n", msg.message);
3650
3651 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3652
3653 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
3654 ret = peek_message(&msg);
3655 ok(ret, "no message available\n");
3656 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3657 ret = peek_message(&msg);
3658 ok( !ret, "message %04x available\n", msg.message);
3659
3660 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
3661
3662 keybd_event(VK_SPACE, 0, 0, 0);
3663 ret = peek_message(&msg);
3664 ok(ret, "no message available\n");
3665 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3666 ret = peek_message(&msg);
3667 ok( !ret, "message %04x available\n", msg.message);
3668 }
3669
3670 static BOOL wait_for_message( MSG *msg )
3671 {
3672 BOOL ret;
3673
3674 for (;;)
3675 {
3676 ret = peek_message(msg);
3677 if (ret)
3678 {
3679 if (msg->message == WM_PAINT) DispatchMessageA(msg);
3680 else break;
3681 }
3682 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
3683 }
3684 if (!ret) msg->message = 0;
3685 return ret;
3686 }
3687
3688 static void test_mouse_input(HWND hwnd)
3689 {
3690 RECT rc;
3691 POINT pt;
3692 int x, y;
3693 HWND popup;
3694 MSG msg;
3695 BOOL ret;
3696 LRESULT res;
3697
3698 ShowWindow(hwnd, SW_SHOWNORMAL);
3699 UpdateWindow(hwnd);
3700 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3701
3702 GetWindowRect(hwnd, &rc);
3703 trace("main window %p: %s\n", hwnd, wine_dbgstr_rect(&rc));
3704
3705 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
3706 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
3707 hwnd, 0, 0, NULL);
3708 assert(popup != 0);
3709 ShowWindow(popup, SW_SHOW);
3710 UpdateWindow(popup);
3711 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3712
3713 GetWindowRect(popup, &rc);
3714 trace("popup window %p: %s\n", popup, wine_dbgstr_rect(&rc));
3715
3716 x = rc.left + (rc.right - rc.left) / 2;
3717 y = rc.top + (rc.bottom - rc.top) / 2;
3718 trace("setting cursor to (%d,%d)\n", x, y);
3719
3720 SetCursorPos(x, y);
3721 GetCursorPos(&pt);
3722 if (x != pt.x || y != pt.y)
3723 {
3724 skip( "failed to set mouse position, skipping mouse input tests\n" );
3725 goto done;
3726 }
3727
3728 flush_events( TRUE );
3729
3730 /* Check that setting the same position may generate WM_MOUSEMOVE */
3731 SetCursorPos(x, y);
3732 msg.message = 0;
3733 ret = peek_message(&msg);
3734 if (ret)
3735 {
3736 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
3737 msg.hwnd, msg.message);
3738 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
3739 x, y, msg.pt.x, msg.pt.y);
3740 }
3741
3742 /* force the system to update its internal queue mouse position,
3743 * otherwise it won't generate relative mouse movements below.
3744 */
3745 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3746 flush_events( TRUE );
3747
3748 msg.message = 0;
3749 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3750 flush_events( FALSE );
3751 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
3752 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
3753 {
3754 if (ignore_message(msg.message)) continue;
3755 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
3756 "hwnd %p message %04x\n", msg.hwnd, msg.message);
3757 DispatchMessageA(&msg);
3758 }
3759 ret = peek_message(&msg);
3760 ok( !ret, "message %04x available\n", msg.message);
3761
3762 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
3763 ShowWindow(popup, SW_HIDE);
3764 ret = wait_for_message( &msg );
3765 if (ret)
3766 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
3767 flush_events( TRUE );
3768
3769 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
3770 ShowWindow(hwnd, SW_HIDE);
3771 ret = wait_for_message( &msg );
3772 ok( !ret, "message %04x available\n", msg.message);
3773 flush_events( TRUE );
3774
3775 /* test mouse clicks */
3776
3777 ShowWindow(hwnd, SW_SHOW);
3778 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3779 flush_events( TRUE );
3780 ShowWindow(popup, SW_SHOW);
3781 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
3782 flush_events( TRUE );
3783
3784 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3785 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3786 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3787 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3788
3789 ret = wait_for_message( &msg );
3790 if (!ret)
3791 {
3792 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
3793 goto done;
3794 }
3795 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
3796 {
3797 ret = wait_for_message( &msg );
3798 ok(ret, "no message available\n");
3799 }
3800
3801 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3802 msg.hwnd, popup, msg.message);
3803
3804 ret = wait_for_message( &msg );
3805 ok(ret, "no message available\n");
3806 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3807 msg.hwnd, popup, msg.message);
3808
3809 ret = wait_for_message( &msg );
3810 ok(ret, "no message available\n");
3811 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
3812 msg.hwnd, popup, msg.message);
3813
3814 ret = wait_for_message( &msg );
3815 ok(ret, "no message available\n");
3816 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3817 msg.hwnd, popup, msg.message);
3818
3819 ret = peek_message(&msg);
3820 ok(!ret, "message %04x available\n", msg.message);
3821
3822 ShowWindow(popup, SW_HIDE);
3823 flush_events( TRUE );
3824
3825 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3826 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3827 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
3828 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
3829
3830 ret = wait_for_message( &msg );
3831 ok(ret, "no message available\n");
3832 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3833 msg.hwnd, hwnd, msg.message);
3834 ret = wait_for_message( &msg );
3835 ok(ret, "no message available\n");
3836 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3837 msg.hwnd, hwnd, msg.message);
3838
3839 test_lbuttondown_flag = TRUE;
3840 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
3841 test_lbuttondown_flag = FALSE;
3842
3843 ret = wait_for_message( &msg );
3844 ok(ret, "no message available\n");
3845 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
3846 msg.hwnd, popup, msg.message);
3847 ok(peek_message(&msg), "no message available\n");
3848 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
3849 msg.hwnd, popup, msg.message);
3850 ok(peek_message(&msg), "no message available\n");
3851
3852 /* Test WM_MOUSEACTIVATE */
3853 #define TEST_MOUSEACTIVATE(A,B) \
3854 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
3855 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
3856
3857 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
3858 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
3859 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
3860 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
3861 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
3862 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
3863 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
3864 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
3865 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
3866 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
3867 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
3868 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
3869 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
3870 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
3871 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
3872 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
3873 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
3874 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
3875 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
3876 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
3877 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
3878 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
3879 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
3880 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
3881
3882 done:
3883 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
3884 flush_events( TRUE );
3885
3886 DestroyWindow(popup);
3887 }
3888
3889 static void test_validatergn(HWND hwnd)
3890 {
3891 HWND child;
3892 RECT rc, rc2;
3893 HRGN rgn;
3894 int ret;
3895 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
3896 ShowWindow(hwnd, SW_SHOW);
3897 UpdateWindow( hwnd);
3898 /* test that ValidateRect validates children*/
3899 InvalidateRect( child, NULL, 1);
3900 GetWindowRect( child, &rc);
3901 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3902 ret = GetUpdateRect( child, &rc2, 0);
3903 ok( ret == 1, "Expected GetUpdateRect to return non-zero, got %d\n", ret);
3904 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
3905 "Update rectangle is empty!\n");
3906 ValidateRect( hwnd, &rc);
3907 ret = GetUpdateRect( child, &rc2, 0);
3908 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3909 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3910 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2));
3911
3912 /* now test ValidateRgn */
3913 InvalidateRect( child, NULL, 1);
3914 GetWindowRect( child, &rc);
3915 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
3916 rgn = CreateRectRgnIndirect( &rc);
3917 ValidateRgn( hwnd, rgn);
3918 ret = GetUpdateRect( child, &rc2, 0);
3919 ok( !ret, "Expected GetUpdateRect to return zero, got %d\n", ret);
3920 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
3921 "Update rectangle %s is not empty!\n", wine_dbgstr_rect(&rc2));
3922
3923 DeleteObject( rgn);
3924 DestroyWindow( child );
3925 }
3926
3927 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
3928 {
3929 RECT rc;
3930 MoveWindow( hwnd, 0, 0, x, y, 0);
3931 GetWindowRect( hwnd, prc);
3932 rc = *prc;
3933 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
3934 trace("window rect is %s, nccalc rect is %s\n", wine_dbgstr_rect(&rc), wine_dbgstr_rect(prc));
3935 }
3936
3937 static void test_nccalcscroll(HWND parent)
3938 {
3939 RECT rc1;
3940 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
3941 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
3942 HWND hwnd = CreateWindowExA(0, "static", NULL,
3943 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
3944 10, 10, 200, 200, parent, 0, 0, NULL);
3945 ShowWindow( parent, SW_SHOW);
3946 UpdateWindow( parent);
3947
3948 /* test window too low for a horizontal scroll bar */
3949 nccalchelper( hwnd, 100, sbheight, &rc1);
3950 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %s\n", sbheight,
3951 wine_dbgstr_rect(&rc1));
3952
3953 /* test window just high enough for a horizontal scroll bar */
3954 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
3955 ok( rc1.bottom - rc1.top == 1, "Height should be 1 size is %s\n", wine_dbgstr_rect(&rc1));
3956
3957 /* test window too narrow for a vertical scroll bar */
3958 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
3959 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %s\n", sbwidth - 1,
3960 wine_dbgstr_rect(&rc1));
3961
3962 /* test window just wide enough for a vertical scroll bar */
3963 nccalchelper( hwnd, sbwidth, 100, &rc1);
3964 ok( rc1.right - rc1.left == 0, "Width should be 0 size is %s\n", wine_dbgstr_rect(&rc1));
3965
3966 /* same test, but with client edge: not enough width */
3967 SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
3968 nccalchelper( hwnd, sbwidth, 100, &rc1);
3969 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3970 "Width should be %d size is %s\n", sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3971 wine_dbgstr_rect(&rc1));
3972
3973 DestroyWindow( hwnd);
3974 }
3975
3976 static void test_SetParent(void)
3977 {
3978 HWND desktop = GetDesktopWindow();
3979 HMENU hMenu;
3980 HWND ret, parent, child1, child2, child3, child4, sibling, popup;
3981 BOOL bret;
3982
3983 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3984 100, 100, 200, 200, 0, 0, 0, NULL);
3985 assert(parent != 0);
3986 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3987 0, 0, 50, 50, parent, 0, 0, NULL);
3988 assert(child1 != 0);
3989 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3990 0, 0, 50, 50, child1, 0, 0, NULL);
3991 assert(child2 != 0);
3992 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3993 0, 0, 50, 50, child2, 0, 0, NULL);
3994 assert(child3 != 0);
3995 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3996 0, 0, 50, 50, child3, 0, 0, NULL);
3997 assert(child4 != 0);
3998
3999 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
4000 parent, child1, child2, child3, child4);
4001
4002 check_parents(parent, desktop, 0, 0, 0, parent, parent);
4003 check_parents(child1, parent, parent, parent, 0, parent, parent);
4004 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4005 check_parents(child3, child2, child2, child2, 0, child2, parent);
4006 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4007
4008 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
4009 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
4010 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
4011 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
4012 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
4013
4014 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
4015 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
4016 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
4017 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
4018 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
4019 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
4020 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
4021 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4022 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
4023
4024 if (!is_win9x) /* Win9x doesn't survive this test */
4025 {
4026 ok(!SetParent(parent, child1), "SetParent should fail\n");
4027 ok(!SetParent(child2, child3), "SetParent should fail\n");
4028 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
4029 ret = SetParent(parent, child2);
4030 todo_wine ok( !ret || broken( ret != 0 ), "SetParent should fail\n");
4031 if (ret) /* nt4, win2k */
4032 {
4033 ret = SetParent(parent, child3);
4034 ok(ret != 0, "SetParent should not fail\n");
4035 ret = SetParent(child2, parent);
4036 ok(!ret, "SetParent should fail\n");
4037 ret = SetParent(parent, child4);
4038 ok(ret != 0, "SetParent should not fail\n");
4039 check_parents(parent, child4, child4, 0, 0, child4, parent);
4040 check_parents(child1, parent, parent, parent, 0, child4, parent);
4041 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4042 check_parents(child3, child2, child2, child2, 0, child2, parent);
4043 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4044 }
4045 else
4046 {
4047 ret = SetParent(parent, child3);
4048 ok(ret != 0, "SetParent should not fail\n");
4049 ret = SetParent(child2, parent);
4050 ok(!ret, "SetParent should fail\n");
4051 ret = SetParent(parent, child4);
4052 ok(!ret, "SetParent should fail\n");
4053 check_parents(parent, child3, child3, 0, 0, child2, parent);
4054 check_parents(child1, parent, parent, parent, 0, child2, parent);
4055 check_parents(child2, desktop, parent, parent, parent, child2, parent);
4056 check_parents(child3, child2, child2, child2, 0, child2, parent);
4057 check_parents(child4, desktop, child2, child2, child2, child4, parent);
4058 }
4059 }
4060 else
4061 skip("Win9x/WinMe crash\n");
4062
4063 hMenu = CreateMenu();
4064 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4065 100, 100, 200, 200, 0, hMenu, 0, NULL);
4066 assert(sibling != 0);
4067
4068 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
4069 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
4070
4071 ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
4072 ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
4073 ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
4074 ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
4075 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4076 SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
4077 ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
4078 ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
4079 ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
4080 SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
4081 ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
4082 ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
4083
4084 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
4085
4086 ok(!IsWindow(parent), "parent still exists\n");
4087 ok(!IsWindow(sibling), "sibling still exists\n");
4088 ok(!IsWindow(child1), "child1 still exists\n");
4089 ok(!IsWindow(child2), "child2 still exists\n");
4090 ok(!IsWindow(child3), "child3 still exists\n");
4091 ok(!IsWindow(child4), "child4 still exists\n");
4092
4093 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4094 100, 100, 200, 200, 0, 0, 0, NULL);
4095 assert(parent != 0);
4096 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
4097 0, 0, 50, 50, parent, 0, 0, NULL);
4098 assert(child1 != 0);
4099 popup = CreateWindowExA(0, "static", NULL, WS_POPUP,
4100 0, 0, 50, 50, 0, 0, 0, NULL);
4101 assert(popup != 0);
4102
4103 trace("parent %p, child %p, popup %p\n", parent, child1, popup);
4104
4105 check_parents(parent, desktop, 0, 0, 0, parent, parent);
4106 check_parents(child1, parent, parent, parent, 0, parent, parent);
4107 check_parents(popup, desktop, 0, 0, 0, popup, popup);
4108
4109 SetActiveWindow(parent);
4110 SetFocus(parent);
4111 check_active_state(parent, 0, parent);
4112
4113 ret = SetParent(popup, child1);
4114 ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
4115 check_parents(popup, child1, child1, 0, 0, parent, popup);
4116 check_active_state(popup, 0, popup);
4117
4118 SetActiveWindow(parent);
4119 SetFocus(popup);
4120 check_active_state(popup, 0, popup);
4121
4122 EnableWindow(child1, FALSE);
4123 check_active_state(popup, 0, popup);
4124 SetFocus(parent);
4125 check_active_state(parent, 0, parent);
4126 SetFocus(popup);
4127 check_active_state(popup, 0, popup);
4128 EnableWindow(child1, TRUE);
4129
4130 ShowWindow(child1, SW_MINIMIZE);
4131 SetFocus(parent);
4132 check_active_state(parent, 0, parent);
4133 SetFocus(popup);
4134 check_active_state(popup, 0, popup);
4135 ShowWindow(child1, SW_HIDE);
4136
4137 SetActiveWindow(parent);
4138 SetFocus(parent);
4139 check_active_state(parent, 0, parent);
4140
4141 bret = SetForegroundWindow(popup);
4142 ok(bret, "SetForegroundWindow() failed\n");
4143 check_active_state(popup, popup, popup);
4144
4145 ShowWindow(parent, SW_SHOW);
4146 SetActiveWindow(popup);
4147 ok(DestroyWindow(popup), "DestroyWindow() failed\n");
4148 check_active_state(parent, parent, parent);
4149
4150 ok(DestroyWindow(parent), "DestroyWindow() failed\n");
4151
4152 ok(!IsWindow(parent), "parent still exists\n");
4153 ok(!IsWindow(child1), "child1 still exists\n");
4154 ok(!IsWindow(popup), "popup still exists\n");
4155 }
4156
4157 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4158 {
4159 LPCREATESTRUCTA lpcs;
4160 LPSTYLESTRUCT lpss;
4161
4162 switch (msg)
4163 {
4164 case WM_NCCREATE:
4165 case WM_CREATE:
4166 lpcs = (LPCREATESTRUCTA)lparam;
4167 lpss = lpcs->lpCreateParams;
4168 if (lpss)
4169 {
4170 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
4171 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
4172 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
4173 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
4174 else
4175 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
4176
4177 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
4178 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4179 lpss->styleOld, lpcs->dwExStyle);
4180
4181 ok(lpss->styleNew == lpcs->style,
4182 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
4183 lpss->styleNew, lpcs->style);
4184 }
4185 break;
4186 }
4187 return DefWindowProcA(hwnd, msg, wparam, lparam);
4188 }
4189
4190 static ATOM atomStyleCheckClass;
4191
4192 static void register_style_check_class(void)
4193 {
4194 WNDCLASSA wc =
4195 {
4196 0,
4197 StyleCheckProc,
4198 0,
4199 0,
4200 GetModuleHandleA(NULL),
4201 NULL,
4202 LoadCursorA(0, (LPCSTR)IDC_ARROW),
4203 (HBRUSH)(COLOR_BTNFACE+1),
4204 NULL,
4205 "WineStyleCheck",
4206 };
4207
4208 atomStyleCheckClass = RegisterClassA(&wc);
4209 assert(atomStyleCheckClass);
4210 }
4211
4212 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
4213 {
4214 DWORD dwActualStyle;
4215 DWORD dwActualExStyle;
4216 STYLESTRUCT ss;
4217 HWND hwnd;
4218 HWND hwndParent = NULL;
4219
4220 ss.styleNew = dwStyleIn;
4221 ss.styleOld = dwExStyleIn;
4222
4223 if (dwStyleIn & WS_CHILD)
4224 {
4225 hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
4226 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4227 }
4228
4229 hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
4230 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
4231 assert(hwnd);
4232
4233 flush_events( TRUE );
4234
4235 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4236 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4237 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4238 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4239
4240 /* try setting the styles explicitly */
4241 SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
4242 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4243 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4244 /* WS_EX_WINDOWEDGE can't always be changed */
4245 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
4246 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4247 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
4248 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4249 else
4250 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
4251 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4252 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4253
4254 SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
4255 dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
4256 dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
4257 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4258 if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
4259 else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
4260 /* WS_EX_WINDOWEDGE can't always be changed */
4261 if (dwExStyleIn & WS_EX_DLGMODALFRAME)
4262 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4263 else if ((dwActualStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(dwExStyleIn & WS_EX_STATICEDGE))
4264 dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
4265 else
4266 dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
4267 ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
4268 /* FIXME: Remove the condition below once Wine is fixed */
4269 todo_wine_if (dwActualExStyle != dwExStyleOut)
4270 ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
4271
4272 DestroyWindow(hwnd);
4273 if (hwndParent) DestroyWindow(hwndParent);
4274 }
4275
4276 /* tests what window styles the window manager automatically adds */
4277 static void test_window_styles(void)
4278 {
4279 register_style_check_class();
4280
4281 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4282 check_window_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4283 check_window_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
4284 check_window_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
4285 check_window_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE);
4286 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
4287 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
4288 check_window_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4289 check_window_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4290 check_window_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4291 check_window_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4292 check_window_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4293 check_window_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4294 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4295 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4296 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4297 check_window_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4298 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4299 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4300 check_window_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4301 check_window_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4302 check_window_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4303 check_window_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4304 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4305 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
4306 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
4307 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
4308 check_window_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4309 check_window_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4310 check_window_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4311 check_window_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4312 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
4313 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
4314
4315 if (pGetLayeredWindowAttributes)
4316 {
4317 check_window_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE);
4318 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_WINDOWEDGE);
4319 check_window_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4320 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE);
4321 }
4322 }
4323
4324 static HWND root_dialog(HWND hwnd)
4325 {
4326 while ((GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
4327 (GetWindowLongA(hwnd, GWL_STYLE) & (WS_CHILD|WS_POPUP)) == WS_CHILD)
4328 {
4329 HWND parent = GetParent(hwnd);
4330
4331 /* simple detector for a window being a dialog */
4332 if (!DefDlgProcA(parent, DM_GETDEFID, 0, 0))
4333 break;
4334
4335 hwnd = parent;
4336
4337 if (!(GetWindowLongA(hwnd, GWL_STYLE) & DS_CONTROL))
4338 break;
4339 }
4340
4341 return hwnd;
4342 }
4343
4344 static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4345 {
4346 return 0;
4347 }
4348
4349 static LRESULT expected_id;
4350
4351 static INT_PTR WINAPI empty_dlg_proc3(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4352 {
4353 if (msg == WM_INITDIALOG)
4354 {
4355 HWND parent = GetParent(hwnd);
4356 LRESULT id, ret;
4357
4358 id = DefDlgProcA(parent, DM_GETDEFID, 0, 0);
4359 if (!id || root_dialog(hwnd) == hwnd)
4360 parent = 0;
4361
4362 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4363 if (!parent)
4364 ok(id == MAKELONG(IDOK,DC_HASDEFID), "expected (IDOK,DC_HASDEFID), got %08lx\n", id);
4365 else
4366 ok(id == expected_id, "expected %08lx, got %08lx\n", expected_id, id);
4367
4368 ret = DefDlgProcA(hwnd, DM_SETDEFID, 0x3333, 0);
4369 ok(ret, "DefDlgProc(DM_SETDEFID) failed\n");
4370 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4371 ok(id == MAKELONG(0x3333,DC_HASDEFID), "expected (0x3333,DC_HASDEFID), got %08lx\n", id);
4372
4373 if (parent)
4374 {
4375 id = DefDlgProcA(parent, DM_GETDEFID, 0, 0);
4376 ok(id == MAKELONG(0x3333,DC_HASDEFID), "expected (0x3333,DC_HASDEFID), got %08lx\n", id);
4377
4378 expected_id = MAKELONG(0x3333,DC_HASDEFID);
4379 }
4380
4381 EndDialog(hwnd, 0);
4382 }
4383
4384 return 0;
4385 }
4386
4387 struct dialog_param
4388 {
4389 HWND parent, grand_parent;
4390 DLGTEMPLATE *dlg_data;
4391 };
4392
4393 static INT_PTR WINAPI empty_dlg_proc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4394 {
4395 if (msg == WM_INITDIALOG)
4396 {
4397 DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
4398 struct dialog_param *param = (struct dialog_param *)lparam;
4399 BOOL parent_is_child;
4400 HWND disabled_hwnd;
4401 LRESULT id, ret;
4402
4403 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4404 ok(id == MAKELONG(IDOK,DC_HASDEFID), "expected (IDOK,DC_HASDEFID), got %08lx\n", id);
4405 ret = DefDlgProcA(hwnd, DM_SETDEFID, 0x2222, 0);
4406 ok(ret, "DefDlgProc(DM_SETDEFID) failed\n");
4407 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4408 ok(id == MAKELONG(0x2222,DC_HASDEFID), "expected (0x2222,DC_HASDEFID), got %08lx\n", id);
4409
4410 expected_id = MAKELONG(0x2222,DC_HASDEFID);
4411
4412 parent_is_child = (GetWindowLongA(param->parent, GWL_STYLE) & (WS_POPUP | WS_CHILD)) == WS_CHILD;
4413
4414 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4415 if (parent_is_child)
4416 {
4417 ok(IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
4418 disabled_hwnd = param->grand_parent;
4419 }
4420 else
4421 {
4422 ok(!IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
4423 disabled_hwnd = param->parent;
4424 }
4425
4426 if (param->grand_parent)
4427 {
4428 if (parent_is_child)
4429 ok(!IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
4430 else
4431 ok(IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
4432 }
4433
4434 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, disabled_hwnd, empty_dlg_proc3, 0);
4435 ok(IsWindowEnabled(disabled_hwnd), "wrong state for %08x\n", style);
4436
4437 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4438 ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
4439 if (param->grand_parent)
4440 ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
4441
4442 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4443 ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
4444 ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
4445 if (param->grand_parent)
4446 ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
4447
4448 param->dlg_data->style |= WS_CHILD;
4449 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4450 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4451
4452 param->dlg_data->style |= DS_CONTROL;
4453 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4454 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4455
4456 param->dlg_data->dwExtendedStyle |= WS_EX_CONTROLPARENT;
4457 SetWindowLongA(hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_CONTROLPARENT);
4458 SetWindowLongA(hwnd, GWL_STYLE, style & ~DS_CONTROL);
4459 param->dlg_data->style &= ~DS_CONTROL;
4460 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4461 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4462
4463 SetWindowLongA(hwnd, GWL_STYLE, style | DS_CONTROL);
4464 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4465 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4466
4467 param->dlg_data->style |= DS_CONTROL;
4468 DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
4469 ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
4470
4471 EndDialog(hwnd, 0);
4472 }
4473 return 0;
4474 }
4475
4476 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
4477 {
4478 struct
4479 {
4480 DLGTEMPLATE dt;
4481 WORD menu_name;
4482 WORD class_id;
4483 WORD class_atom;
4484 WCHAR caption[1];
4485 } dlg_data;
4486 DWORD style, ex_style;
4487 HWND hwnd, grand_parent = 0, parent = 0;
4488 struct dialog_param param;
4489 LRESULT id, ret;
4490
4491 if (style_in & WS_CHILD)
4492 {
4493 grand_parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
4494 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4495 ok(grand_parent != 0, "grand_parent creation failed\n");
4496 }
4497
4498 parent = CreateWindowExA(0, "static", NULL, style_in,
4499 0, 0, 0, 0, grand_parent, NULL, NULL, NULL);
4500 ok(parent != 0, "parent creation failed, style %#x\n", style_in);
4501
4502 dlg_data.dt.style = style_in;
4503 dlg_data.dt.dwExtendedStyle = ex_style_in;
4504 dlg_data.dt.cdit = 0;
4505 dlg_data.dt.x = 0;
4506 dlg_data.dt.y = 0;
4507 dlg_data.dt.cx = 100;
4508 dlg_data.dt.cy = 100;
4509 dlg_data.menu_name = 0;
4510 dlg_data.class_id = 0;
4511 dlg_data.class_atom = 0;
4512 dlg_data.caption[0] = 0;
4513
4514 hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
4515 ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
4516
4517 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4518 ok(id == MAKELONG(IDOK,DC_HASDEFID), "expected (IDOK,DC_HASDEFID), got %08lx\n", id);
4519 ret = DefDlgProcA(hwnd, DM_SETDEFID, 0x1111, 0);
4520 ok(ret, "DefDlgProc(DM_SETDEFID) failed\n");
4521 id = DefDlgProcA(hwnd, DM_GETDEFID, 0, 0);
4522 ok(id == MAKELONG(0x1111,DC_HASDEFID), "expected (0x1111,DC_HASDEFID), got %08lx\n", id);
4523
4524 flush_events( TRUE );
4525
4526 style = GetWindowLongA(hwnd, GWL_STYLE);
4527 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4528 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4529 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4530
4531 ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
4532
4533 /* try setting the styles explicitly */
4534 SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
4535 style = GetWindowLongA(hwnd, GWL_STYLE);
4536 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4537 ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
4538 /* WS_EX_WINDOWEDGE can't always be changed */
4539 if (ex_style_in & WS_EX_DLGMODALFRAME)
4540 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4541 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4542 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4543 else
4544 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4545 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4546
4547 SetWindowLongA(hwnd, GWL_STYLE, style_in);
4548 style = GetWindowLongA(hwnd, GWL_STYLE);
4549 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
4550 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
4551 if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
4552 else style_out = style_in | WS_CLIPSIBLINGS;
4553 ok(style == style_out, "expected style %#x, got %#x\n", style_out, style);
4554 /* WS_EX_WINDOWEDGE can't always be changed */
4555 if (ex_style_in & WS_EX_DLGMODALFRAME)
4556 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4557 else if ((style & (WS_DLGFRAME | WS_THICKFRAME)) && !(ex_style_in & WS_EX_STATICEDGE))
4558 ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
4559 else
4560 ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
4561 /* FIXME: Remove the condition below once Wine is fixed */
4562 todo_wine_if (ex_style != ex_style_out)
4563 ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
4564
4565 DestroyWindow(hwnd);
4566
4567 param.parent = parent;
4568 param.grand_parent = grand_parent;
4569 param.dlg_data = &dlg_data.dt;
4570 DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc2, (LPARAM)&param);
4571
4572 ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
4573 if (grand_parent)
4574 ok(IsWindowEnabled(grand_parent), "wrong grand parent state (dialog style %#x)\n", style_in);
4575
4576 DestroyWindow(parent);
4577 DestroyWindow(grand_parent);
4578 }
4579
4580 static void test_dialog_styles(void)
4581 {
4582 check_dialog_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4583 check_dialog_style(WS_DLGFRAME, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4584 check_dialog_style(WS_THICKFRAME, 0, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4585 check_dialog_style(WS_DLGFRAME, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4586 check_dialog_style(WS_THICKFRAME, WS_EX_STATICEDGE, WS_THICKFRAME|WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4587 check_dialog_style(DS_CONTROL, 0, WS_CLIPSIBLINGS|WS_CAPTION|DS_CONTROL, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4588 check_dialog_style(WS_CAPTION, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4589 check_dialog_style(WS_BORDER, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4590 check_dialog_style(WS_DLGFRAME, 0, WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4591 check_dialog_style(WS_BORDER|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4592 check_dialog_style(WS_DLGFRAME|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4593 check_dialog_style(WS_CAPTION|WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4594 check_dialog_style(WS_SYSMENU, 0, WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4595 check_dialog_style(WS_CAPTION|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4596 check_dialog_style(WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4597 check_dialog_style(WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CAPTION|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4598 check_dialog_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4599 check_dialog_style(WS_CHILD, 0, WS_CHILD, 0);
4600 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4601 check_dialog_style(WS_CHILD|WS_THICKFRAME, 0, WS_CHILD|WS_THICKFRAME, WS_EX_WINDOWEDGE);
4602 check_dialog_style(WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_DLGFRAME, WS_EX_STATICEDGE);
4603 check_dialog_style(WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_THICKFRAME, WS_EX_STATICEDGE);
4604 check_dialog_style(WS_CHILD|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4605 check_dialog_style(WS_CHILD|WS_CAPTION, 0, WS_CHILD|WS_CAPTION, WS_EX_WINDOWEDGE);
4606 check_dialog_style(WS_CHILD|WS_BORDER, 0, WS_CHILD|WS_BORDER, 0);
4607 check_dialog_style(WS_CHILD|WS_DLGFRAME, 0, WS_CHILD|WS_DLGFRAME, WS_EX_WINDOWEDGE);
4608 check_dialog_style(WS_CHILD|WS_BORDER|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4609 check_dialog_style(WS_CHILD|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4610 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU, 0, WS_CHILD|WS_CAPTION|WS_SYSMENU, WS_EX_WINDOWEDGE);
4611 check_dialog_style(WS_CHILD|WS_SYSMENU, 0, WS_CHILD|WS_SYSMENU, 0);
4612 check_dialog_style(WS_CHILD|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4613 check_dialog_style(WS_CHILD|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4614 check_dialog_style(WS_CHILD|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|DS_CONTROL, WS_EX_CONTROLPARENT);
4615 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4616 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4617 check_dialog_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
4618 check_dialog_style(WS_CHILD|WS_POPUP, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4619 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4620 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, 0, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4621 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4622 check_dialog_style(WS_CHILD|WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_CHILD|WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE);
4623 check_dialog_style(WS_CHILD|WS_POPUP|DS_CONTROL, 0, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4624 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION, 0, WS_CHILD|WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4625 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER, 0, WS_CHILD|WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, 0);
4626 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME, 0, WS_CHILD|WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
4627 check_dialog_style(WS_CHILD|WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4628 check_dialog_style(WS_CHILD|WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4629 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);
4630 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU, 0, WS_CHILD|WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, 0);
4631 check_dialog_style(WS_CHILD|WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4632 check_dialog_style(WS_CHILD|WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_CHILD|WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4633 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);
4634 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_APPWINDOW, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, WS_EX_APPWINDOW);
4635 check_dialog_style(WS_CHILD|WS_POPUP, WS_EX_WINDOWEDGE, WS_CHILD|WS_POPUP|WS_CLIPSIBLINGS, 0);
4636 check_dialog_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
4637 check_dialog_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW|WS_EX_CONTROLPARENT);
4638 check_dialog_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4639 check_dialog_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4640 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4641 check_dialog_style(WS_POPUP|WS_THICKFRAME, 0, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4642 check_dialog_style(WS_POPUP|WS_DLGFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4643 check_dialog_style(WS_POPUP|WS_THICKFRAME, WS_EX_STATICEDGE, WS_POPUP|WS_THICKFRAME|WS_CLIPSIBLINGS, WS_EX_STATICEDGE|WS_EX_CONTROLPARENT);
4644 check_dialog_style(WS_POPUP|DS_CONTROL, 0, WS_POPUP|WS_CLIPSIBLINGS|DS_CONTROL, WS_EX_CONTROLPARENT);
4645 check_dialog_style(WS_POPUP|WS_CAPTION, 0, WS_POPUP|WS_CAPTION|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4646 check_dialog_style(WS_POPUP|WS_BORDER, 0, WS_POPUP|WS_BORDER|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4647 check_dialog_style(WS_POPUP|WS_DLGFRAME, 0, WS_POPUP|WS_DLGFRAME|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4648 check_dialog_style(WS_POPUP|WS_BORDER|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4649 check_dialog_style(WS_POPUP|WS_DLGFRAME|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4650 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4651 check_dialog_style(WS_POPUP|WS_SYSMENU, 0, WS_POPUP|WS_SYSMENU|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4652 check_dialog_style(WS_POPUP|WS_CAPTION|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4653 check_dialog_style(WS_POPUP|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4654 check_dialog_style(WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_CONTROL, 0, WS_POPUP|DS_CONTROL|WS_CLIPSIBLINGS, WS_EX_CONTROLPARENT);
4655 check_dialog_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4656 check_dialog_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4657
4658 if (pGetLayeredWindowAttributes)
4659 {
4660 check_dialog_style(0, WS_EX_LAYERED, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_LAYERED|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4661 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);
4662 check_dialog_style(0, WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION,
4663 WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_CONTROLPARENT);
4664 }
4665 }
4666
4667 struct dlg_parent_param
4668 {
4669 HWND ga_parent;
4670 HWND gwl_parent;
4671 HWND get_parent;
4672 HWND owner;
4673 HWND root;
4674 HWND ga_root_owner;
4675 };
4676
4677 static INT_PTR WINAPI parent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4678 {
4679 if (msg == WM_INITDIALOG) {
4680 struct dlg_parent_param *param = (void*)lparam;
4681 check_parents(hwnd, param->ga_parent, param->gwl_parent, param->get_parent, param->owner,
4682 param->root ? param->root : hwnd, param->ga_root_owner ? param->ga_root_owner : hwnd);
4683
4684 ok(!IsWindowEnabled(param->gwl_parent), "parent is not disabled\n");
4685 EndDialog(hwnd, 2);
4686 ok(IsWindowEnabled(param->gwl_parent), "parent is not enabled\n");
4687 }
4688
4689 return 0;
4690 }
4691
4692 static INT_PTR WINAPI reparent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4693 {
4694 if (msg == WM_INITDIALOG) {
4695 ok(!IsWindowEnabled(GetParent(hwnd)), "parent is not disabled\n");
4696 SetParent(hwnd, (HWND)lparam);
4697 }
4698
4699 return 0;
4700 }
4701
4702 static INT_PTR WINAPI reparent_owned_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4703 {
4704 if (msg == WM_INITDIALOG) {
4705 HWND new_parent = (HWND)lparam;
4706 HWND owner = GetWindow(hwnd, GW_OWNER);
4707 ok(!IsWindowEnabled(owner), "owner is not disabled\n");
4708 SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_CHILD);
4709 SetParent(hwnd, new_parent);
4710 ok(GetParent(hwnd) == new_parent, "GetParent(hwnd) = %p, expected %p\n", GetParent(hwnd), new_parent);
4711 PostMessageA(hwnd, WM_QUIT, 0, 0);
4712 }
4713
4714 return 0;
4715 }
4716
4717 static LRESULT WINAPI reparent_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4718 {
4719 if (msg == WM_ENTERIDLE) {
4720 HWND dialog = (HWND)lparam;
4721 HWND owner = GetParent(dialog);
4722 /* EndDialog will enable owner */
4723 EnableWindow(owner, FALSE);
4724 EndDialog(dialog, 2);
4725 ok(IsWindowEnabled(owner), "owner is not enabled\n");
4726 /* ...but it won't be enabled on dialog exit */
4727 EnableWindow(owner, FALSE);
4728 }
4729 return DefWindowProcA( hwnd, msg, wparam, lparam );
4730 }
4731
4732 static LRESULT WINAPI post_quit_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4733 {
4734 if (msg == WM_ENTERIDLE) {
4735 HWND dialog = (HWND)lparam;
4736 PostMessageA(dialog, WM_QUIT, 0, 0);
4737 }
4738 return DefWindowProcA( hwnd, msg, wparam, lparam );
4739 }
4740
4741 static LRESULT WINAPI destroy_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
4742 {
4743 if (msg == WM_ENTERIDLE) {
4744 HWND dialog = (HWND)lparam;
4745 DestroyWindow(dialog);
4746 }
4747 return DefWindowProcA( hwnd, msg, wparam, lparam );
4748 }
4749
4750 static void test_dialog_parent(void)
4751 {
4752 HWND dialog, parent, child, child2, other, desktop = GetDesktopWindow();
4753 struct dlg_parent_param param;
4754 INT_PTR ret;
4755 struct
4756 {
4757 DLGTEMPLATE dt;
4758 WORD menu_name;
4759 WORD class_id;
4760 WORD class_atom;
4761 WCHAR caption[1];
4762 } dlg_data;
4763
4764 dlg_data.dt.dwExtendedStyle = 0;
4765 dlg_data.dt.cdit = 0;
4766 dlg_data.dt.x = 0;
4767 dlg_data.dt.y = 0;
4768 dlg_data.dt.cx = 100;
4769 dlg_data.dt.cy = 100;
4770 dlg_data.menu_name = 0;
4771 dlg_data.class_id = 0;
4772 dlg_data.class_atom = 0;
4773 dlg_data.caption[0] = 0;
4774
4775 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4776 /* Create a child without WS_CHILD flag. It's a valid owner window. */
4777 child = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4778 SetParent(child, parent);
4779 /* Regular child. If passed as an owner, its parent will be true owner window. */
4780 child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, NULL, NULL, NULL);
4781
4782 trace("parent %p child %p child2 %p desktop %p\n", parent, child, child2, desktop);
4783
4784 /* When dialog is created with WS_CHILD style, its parent depends on function used to create it. */
4785 dlg_data.dt.style = WS_CHILD;
4786
4787 /* CreateDialogIndirectParam uses passed parent as dialog parent. */
4788 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4789 ok(dialog != 0, "dialog creation failed\n");
4790 check_parents(dialog, child2, child2, child2, NULL, parent, child);
4791
4792 ok(IsWindowEnabled(child2), "child2 is disabled\n");
4793 EnableWindow(child2, FALSE);
4794 EndDialog(dialog, 0);
4795 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4796 DestroyWindow(dialog);
4797
4798 /* DialogBoxIndirectParam uses the first parent of passed owner that's not a child window as dialog
4799 * parent (like in case of dialog with owner). */
4800 param.ga_parent = param.gwl_parent = param.get_parent = child;
4801 param.owner = NULL;
4802 param.root = parent;
4803 param.ga_root_owner = child;
4804 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4805 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4806
4807 /* Dialogs without WS_CHILD behave as expected, they use passed owner just like CreateWindow does. */
4808 dlg_data.dt.style = WS_OVERLAPPEDWINDOW;
4809
4810 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4811 ok(dialog != 0, "dialog creation failed\n");
4812 check_parents(dialog, desktop, child, NULL, child, dialog, dialog);
4813
4814 ok(IsWindowEnabled(child), "child is disabled\n");
4815 EnableWindow(child, FALSE);
4816 EndDialog(dialog, 0);
4817 ok(IsWindowEnabled(child), "child is not enabled\n");
4818 DestroyWindow(dialog);
4819
4820 param.ga_parent = desktop;
4821 param.gwl_parent = child;
4822 param.get_parent = NULL;
4823 param.owner = child;
4824 param.root = param.ga_root_owner = NULL;
4825 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4826 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4827
4828 other = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
4829 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)reparent_dialog_owner_proc);
4830
4831 /* When dialog is created with WS_CHILD|WS_POPUP style, we have an owner. */
4832 dlg_data.dt.style = WS_CHILD|WS_POPUP;
4833
4834 dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
4835 ok(dialog != 0, "dialog creation failed\n");
4836 check_parents(dialog, desktop, child, child, child, dialog, child);
4837
4838 ok(IsWindowEnabled(child), "child is disabled\n");
4839 EnableWindow(child, FALSE);
4840 EndDialog(dialog, 0);
4841 ok(IsWindowEnabled(child), "child is not enabled\n");
4842 DestroyWindow(dialog);
4843
4844 param.ga_parent = desktop;
4845 param.gwl_parent = param.get_parent = child;
4846 param.owner = child;
4847 param.root = NULL;
4848 param.ga_root_owner = child;
4849 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
4850 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4851
4852 /* If we change parent in WM_INITDIALOG for WS_CHILD dialog WM_ENTERIDLE is still sent to the original
4853 * parent. EndDialog will enable the new parent. */
4854 EnableWindow(child, TRUE);
4855 EnableWindow(other, FALSE);
4856 dlg_data.dt.style = WS_CHILD;
4857 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_dlg_proc, (LPARAM)other);
4858 ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
4859 ok(!IsWindowEnabled(other), "other is not disabled\n");
4860 ok(!IsWindowEnabled(child), "child is not disabled\n");
4861 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4862 EnableWindow(child, TRUE);
4863
4864 /* If we change parent and style in WM_INITDIALOG for dialog with an owner to make it true child
4865 * (thus GetParent() will return the new parent instead of an owner), WM_ENTERIDLE is still sent
4866 * to the original parent. EndDialog will enable the new parent. */
4867 EnableWindow(other, FALSE);
4868 dlg_data.dt.style = WS_OVERLAPPED;
4869 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_owned_dlg_proc, (LPARAM)other);
4870 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4871 ok(!IsWindowEnabled(other), "other is not disabled\n");
4872 ok(!IsWindowEnabled(child), "child is not disabled\n");
4873 ok(IsWindowEnabled(child2), "child2 is not enabled\n");
4874 EnableWindow(child, TRUE);
4875 EnableWindow(other, TRUE);
4876
4877 /* Quit dialog message loop by sending WM_QUIT message. Dialog owner is not enabled. */
4878 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)post_quit_dialog_owner_proc);
4879 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
4880 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4881 ok(!IsWindowEnabled(other), "other is enabled\n");
4882 EnableWindow(other, TRUE);
4883
4884 /* Quit dialog message loop by destroying the window. Dialog owner is not enabled. */
4885 SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)destroy_dialog_owner_proc);
4886 ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
4887 ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
4888 ok(!IsWindowEnabled(other), "other is enabled\n");
4889 EnableWindow(other, TRUE);
4890
4891 DestroyWindow(parent);
4892 }
4893
4894 static void test_scrollwindow( HWND hwnd)
4895 {
4896 HDC hdc;
4897 RECT rc, rc2, rc3;
4898 COLORREF colr;
4899
4900 ShowWindow( hwnd, SW_SHOW);
4901 UpdateWindow( hwnd);
4902 flush_events( TRUE );
4903 GetClientRect( hwnd, &rc);
4904 hdc = GetDC( hwnd);
4905 /* test ScrollWindow(Ex) with no clip rectangle */
4906 /* paint the lower half of the window black */
4907 rc2 = rc;
4908 rc2.top = ( rc2.top + rc2.bottom) / 2;
4909 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4910 /* paint the upper half of the window white */
4911 rc2.bottom = rc2.top;
4912 rc2.top =0;
4913 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4914 /* scroll lower half up */
4915 rc2 = rc;
4916 rc2.top = ( rc2.top + rc2.bottom) / 2;
4917 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
4918 flush_events(FALSE);
4919 /* expected: black should have scrolled to the upper half */
4920 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4921 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4922 /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
4923 /* paint the lower half of the window black */
4924 rc2 = rc;
4925 rc2.top = ( rc2.top + rc2.bottom) / 2;
4926 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
4927 /* paint the upper half of the window white */
4928 rc2.bottom = rc2.top;
4929 rc2.top =0;
4930 FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
4931 /* scroll lower half up */
4932 rc2 = rc;
4933 rc2.top = ( rc2.top + rc2.bottom) / 2;
4934 rc3 = rc;
4935 rc3.left = rc3.right / 4;
4936 rc3.right -= rc3.right / 4;
4937 ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
4938 flush_events(FALSE);
4939 /* expected: black should have scrolled to the upper half */
4940 colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2, rc2.bottom / 4 );
4941 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
4942
4943 /* clean up */
4944 ReleaseDC( hwnd, hdc);
4945 }
4946
4947 static void test_scrollvalidate( HWND parent)
4948 {
4949 HDC hdc;
4950 HRGN hrgn=CreateRectRgn(0,0,0,0);
4951 HRGN exprgn, tmprgn, clipping;
4952 RECT rc, rcu, cliprc;
4953 /* create two overlapping child windows. The visual region
4954 * of hwnd1 is clipped by the overlapping part of
4955 * hwnd2 because of the WS_CLIPSIBLING style */
4956 HWND hwnd1, hwnd2;
4957
4958 clipping = CreateRectRgn(0,0,0,0);
4959 tmprgn = CreateRectRgn(0,0,0,0);
4960 exprgn = CreateRectRgn(0,0,0,0);
4961 hwnd2 = CreateWindowExA(0, "static", NULL,
4962 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4963 75, 30, 100, 100, parent, 0, 0, NULL);
4964 hwnd1 = CreateWindowExA(0, "static", NULL,
4965 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
4966 25, 50, 100, 100, parent, 0, 0, NULL);
4967 ShowWindow( parent, SW_SHOW);
4968 UpdateWindow( parent);
4969 GetClientRect( hwnd1, &rc);
4970 cliprc=rc;
4971 SetRectRgn( clipping, 10, 10, 90, 90);
4972 hdc = GetDC( hwnd1);
4973 /* for a visual touch */
4974 TextOutA( hdc, 0,10, "0123456789", 10);
4975 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4976 if (winetest_debug > 0) dump_region(hrgn);
4977 /* create a region with what is expected */
4978 SetRectRgn( exprgn, 39,0,49,74);
4979 SetRectRgn( tmprgn, 88,79,98,93);
4980 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4981 SetRectRgn( tmprgn, 0,93,98,98);
4982 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4983 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4984 trace("update rect is %s\n", wine_dbgstr_rect(&rcu));
4985 /* now with clipping region */
4986 SelectClipRgn( hdc, clipping);
4987 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
4988 if (winetest_debug > 0) dump_region(hrgn);
4989 /* create a region with what is expected */
4990 SetRectRgn( exprgn, 39,10,49,74);
4991 SetRectRgn( tmprgn, 80,79,90,85);
4992 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4993 SetRectRgn( tmprgn, 10,85,90,90);
4994 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
4995 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
4996 trace("update rect is %s\n", wine_dbgstr_rect(&rcu));
4997 ReleaseDC( hwnd1, hdc);
4998
4999 /* test scrolling a rect by more than its size */
5000 DestroyWindow( hwnd2);
5001 ValidateRect( hwnd1, NULL);
5002 SetRect( &rc, 40,40, 50,50);
5003 InvalidateRect( hwnd1, &rc, 1);
5004 ScrollWindowEx( hwnd1, -20, 0, &rc, NULL, hrgn, &rcu,
5005 SW_SCROLLCHILDREN | SW_INVALIDATE);
5006 if (winetest_debug > 0) dump_region(hrgn);
5007 SetRectRgn( exprgn, 20, 40, 30, 50);
5008 SetRectRgn( tmprgn, 40, 40, 50, 50);
5009 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5010 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5011 ok( rcu.left == 20 && rcu.top == 40 && rcu.right == 50 && rcu.bottom == 50,
5012 "unexpected update rect: %s\n", wine_dbgstr_rect(&rcu));
5013
5014 /* test scrolling a window with an update region */
5015 ValidateRect( hwnd1, NULL);
5016 SetRect( &rc, 40,40, 50,50);
5017 InvalidateRect( hwnd1, &rc, 1);
5018 GetClientRect( hwnd1, &rc);
5019 cliprc=rc;
5020 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
5021 SW_SCROLLCHILDREN | SW_INVALIDATE);
5022 if (winetest_debug > 0) dump_region(hrgn);
5023 SetRectRgn( exprgn, 88,0,98,98);
5024 SetRectRgn( tmprgn, 30, 40, 50, 50);
5025 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5026 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5027
5028 /* clear an update region */
5029 UpdateWindow( hwnd1 );
5030
5031 SetRect( &rc, 0,40, 100,60);
5032 SetRect( &cliprc, 0,0, 100,100);
5033 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5034 if (winetest_debug > 0) dump_region( hrgn );
5035 SetRectRgn( exprgn, 0, 40, 98, 60 );
5036 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
5037
5038 /* now test ScrollWindowEx with a combination of
5039 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
5040 /* make hwnd2 the child of hwnd1 */
5041 hwnd2 = CreateWindowExA(0, "static", NULL,
5042 WS_CHILD| WS_VISIBLE | WS_BORDER ,
5043 50, 50, 100, 100, hwnd1, 0, 0, NULL);
5044 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
5045 GetClientRect( hwnd1, &rc);
5046 cliprc=rc;
5047
5048 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
5049 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
5050 ValidateRect( hwnd1, NULL);
5051 ValidateRect( hwnd2, NULL);
5052 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
5053 SW_SCROLLCHILDREN | SW_INVALIDATE);
5054 if (winetest_debug > 0) dump_region(hrgn);
5055 SetRectRgn( exprgn, 88,0,98,88);
5056 SetRectRgn( tmprgn, 0,88,98,98);
5057 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5058 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5059
5060 /* SW_SCROLLCHILDREN */
5061 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
5062 ValidateRect( hwnd1, NULL);
5063 ValidateRect( hwnd2, NULL);
5064 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
5065 if (winetest_debug > 0) dump_region(hrgn);
5066 /* expected region is the same as in previous test */
5067 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5068
5069 /* no SW_SCROLLCHILDREN */
5070 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
5071 ValidateRect( hwnd1, NULL);
5072 ValidateRect( hwnd2, NULL);
5073 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5074 if (winetest_debug > 0) dump_region(hrgn);
5075 /* expected region is the same as in previous test */
5076 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5077
5078 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
5079 SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
5080 ValidateRect( hwnd1, NULL);
5081 ValidateRect( hwnd2, NULL);
5082 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
5083 if (winetest_debug > 0) dump_region(hrgn);
5084 SetRectRgn( exprgn, 88,0,98,20);
5085 SetRectRgn( tmprgn, 20,20,98,30);
5086 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5087 SetRectRgn( tmprgn, 20,30,30,88);
5088 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5089 SetRectRgn( tmprgn, 0,88,30,98);
5090 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
5091 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
5092
5093 /* clean up */
5094 DeleteObject( hrgn);
5095 DeleteObject( exprgn);
5096 DeleteObject( tmprgn);
5097 DestroyWindow( hwnd1);
5098 DestroyWindow( hwnd2);
5099 }
5100
5101 /* couple of tests of return values of scrollbar functions
5102 * called on a scrollbarless window */
5103 static void test_scroll(void)
5104 {
5105 BOOL ret;
5106 INT min, max;
5107 SCROLLINFO si;
5108 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
5109 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
5110 100, 100, 200, 200, 0, 0, 0, NULL);
5111 /* horizontal */
5112 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
5113 if (!ret) /* win9x */
5114 {
5115 win_skip( "GetScrollRange doesn't work\n" );
5116 DestroyWindow( hwnd);
5117 return;
5118 }
5119 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
5120 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
5121 si.cbSize = sizeof( si);
5122 si.fMask = SIF_PAGE;
5123 si.nPage = 0xdeadbeef;
5124 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
5125 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
5126 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
5127 /* vertical */
5128 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
5129 ok( ret, "GetScrollRange returns FALSE\n");
5130 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
5131 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
5132 si.cbSize = sizeof( si);
5133 si.fMask = SIF_PAGE;
5134 si.nPage = 0xdeadbeef;
5135 ret = GetScrollInfo( hwnd, SB_VERT, &si);
5136 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
5137 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
5138 /* clean up */
5139 DestroyWindow( hwnd);
5140 }
5141
5142 static void test_scrolldc( HWND parent)
5143 {
5144 HDC hdc;
5145 HRGN exprgn, tmprgn, hrgn;
5146 RECT rc, rc2, rcu, cliprc;
5147 HWND hwnd1;
5148 COLORREF colr;
5149
5150 hrgn = CreateRectRgn(0,0,0,0);
5151 tmprgn = CreateRectRgn(0,0,0,0);
5152 exprgn = CreateRectRgn(0,0,0,0);
5153
5154 hwnd1 = CreateWindowExA(0, "static", NULL,
5155 WS_CHILD| WS_VISIBLE,
5156 25, 50, 100, 100, parent, 0, 0, NULL);
5157 ShowWindow( parent, SW_SHOW);
5158 UpdateWindow( parent);
5159 flush_events( TRUE );
5160 GetClientRect( hwnd1, &rc);
5161 hdc = GetDC( hwnd1);
5162 /* paint the upper half of the window black */
5163 rc2 = rc;
5164 rc2.bottom = ( rc.top + rc.bottom) /2;
5165 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
5166 /* clip region is the lower half */
5167 cliprc=rc;
5168 cliprc.top = (rc.top + rc.bottom) /2;
5169 /* test whether scrolled pixels are properly clipped */
5170 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
5171 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
5172 /* this scroll should not cause any visible changes */
5173 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
5174 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
5175 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
5176 /* test with NULL clip rect */
5177 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
5178 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
5179 trace("update rect: %s\n", wine_dbgstr_rect(&rcu));
5180 if (winetest_debug > 0) dump_region(hrgn);
5181 SetRect(&rc2, 0, 0, 100, 100);
5182 ok(EqualRect(&rcu, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rcu),
5183 wine_dbgstr_rect(&rc2));
5184
5185 SetRectRgn( exprgn, 0, 0, 20, 80);
5186 SetRectRgn( tmprgn, 0, 80, 100, 100);
5187 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
5188 if (winetest_debug > 0) dump_region(exprgn);
5189 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
5190 /* test clip rect > scroll rect */
5191 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
5192 rc2=rc;
5193 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
5194 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
5195 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
5196 SetRectRgn( exprgn, 25, 25, 75, 35);
5197 SetRectRgn( tmprgn, 25, 35, 35, 75);
5198 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
5199 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
5200 trace("update rect: %s\n", wine_dbgstr_rect(&rcu));
5201 if (winetest_debug > 0) dump_region(hrgn);
5202
5203 /* clean up */
5204 DeleteObject(hrgn);
5205 DeleteObject(exprgn);
5206 DeleteObject(tmprgn);
5207 DestroyWindow(hwnd1);
5208 }
5209
5210 static void test_params(void)
5211 {
5212 HWND hwnd;
5213 INT rc;
5214
5215 ok(!IsWindow(0), "IsWindow(0)\n");
5216 ok(!IsWindow(HWND_BROADCAST), "IsWindow(HWND_BROADCAST)\n");
5217 ok(!IsWindow(HWND_TOPMOST), "IsWindow(HWND_TOPMOST)\n");
5218
5219 /* Just a param check */
5220 if (pGetMonitorInfoA)
5221 {
5222 SetLastError(0xdeadbeef);
5223 rc = GetWindowTextA(hwndMain2, NULL, 1024);
5224 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
5225 }
5226 else
5227 {
5228 /* Skips actually on Win95 and NT4 */
5229 win_skip("Test would crash on Win95\n");
5230 }
5231
5232 SetLastError(0xdeadbeef);
5233 hwnd=CreateWindowA("LISTBOX", "TestList",
5234 (LBS_STANDARD & ~LBS_SORT),
5235 0, 0, 100, 100,
5236 NULL, (HMENU)1, NULL, 0);
5237
5238 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
5239 "CreateWindow with invalid menu handle should fail\n");
5240 if (!hwnd)
5241 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
5242 GetLastError() == 0xdeadbeef, /* Win9x */
5243 "wrong last error value %d\n", GetLastError());
5244 }
5245
5246 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
5247 {
5248 HWND hwnd = 0;
5249
5250 hwnd = CreateWindowExA(exStyle, class, class, style,
5251 110, 100,
5252 225, 200,
5253 0,
5254 menu ? hmenu : 0,
5255 0, 0);
5256 if (!hwnd) {
5257 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
5258 return;
5259 }
5260 ShowWindow(hwnd, SW_SHOW);
5261
5262 test_nonclient_area(hwnd);
5263
5264 SetMenu(hwnd, 0);
5265 DestroyWindow(hwnd);
5266 }
5267
5268 static BOOL AWR_init(void)
5269 {
5270 WNDCLASSA class;
5271
5272 class.style = CS_HREDRAW | CS_VREDRAW;
5273 class.lpfnWndProc = DefWindowProcA;
5274 class.cbClsExtra = 0;
5275 class.cbWndExtra = 0;
5276 class.hInstance = 0;
5277 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
5278 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5279 class.hbrBackground = 0;
5280 class.lpszMenuName = 0;
5281 class.lpszClassName = szAWRClass;
5282
5283 if (!RegisterClassA(&class)) {
5284 ok(FALSE, "RegisterClass failed\n");
5285 return FALSE;
5286 }
5287
5288 hmenu = CreateMenu();
5289 if (!hmenu)
5290 return FALSE;
5291 ok(hmenu != 0, "Failed to create menu\n");
5292 ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
5293
5294 return TRUE;
5295 }
5296
5297
5298 static void test_AWR_window_size(BOOL menu)
5299 {
5300 static const DWORD styles[] = {
5301 WS_POPUP, WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME, WS_CAPTION, WS_SYSMENU,
5302 WS_THICKFRAME, WS_MINIMIZEBOX, WS_MAXIMIZEBOX, WS_HSCROLL, WS_VSCROLL
5303 };
5304 static const DWORD exStyles[] = {
5305 WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE, WS_EX_APPWINDOW,
5306 WS_EX_DLGMODALFRAME, WS_EX_DLGMODALFRAME | WS_EX_STATICEDGE
5307 };
5308
5309 unsigned int i;
5310
5311 /* A exhaustive check of all the styles takes too long
5312 * so just do a (hopefully representative) sample
5313 */
5314 for (i = 0; i < COUNTOF(styles); ++i)
5315 test_AWRwindow(szAWRClass, styles[i], 0, menu);
5316 for (i = 0; i < COUNTOF(exStyles); ++i) {
5317 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
5318 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
5319 }
5320 }
5321
5322 static void test_AWR_flags(void)
5323 {
5324 static const DWORD styles[] = { WS_POPUP, WS_BORDER, WS_DLGFRAME, WS_THICKFRAME };
5325 static const DWORD exStyles[] = { WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
5326 WS_EX_APPWINDOW, WS_EX_DLGMODALFRAME, WS_EX_STATICEDGE };
5327
5328 DWORD i, j, k, style, exstyle;
5329 RECT rect, rect2;
5330
5331 for (i = 0; i < (1 << COUNTOF(styles)); i++)
5332 {
5333 for (k = style = 0; k < COUNTOF(styles); k++) if (i & (1 << k)) style |= styles[k];
5334
5335 for (j = 0; j < (1 << COUNTOF(exStyles)); j++)
5336 {
5337 for (k = exstyle = 0; k < COUNTOF(exStyles); k++) if (j & (1 << k)) exstyle |= exStyles[k];
5338 SetRect( &rect, 100, 100, 200, 200 );
5339 rect2 = rect;
5340 AdjustWindowRectEx( &rect, style, FALSE, exstyle );
5341 wine_AdjustWindowRectEx( &rect2, style, FALSE, exstyle );
5342 ok( EqualRect( &rect, &rect2 ), "rects do not match: win %s wine %s\n",
5343 wine_dbgstr_rect( &rect ), wine_dbgstr_rect( &rect2 ));
5344 }
5345 }
5346 }
5347 #undef COUNTOF
5348
5349 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
5350
5351 static void test_AdjustWindowRect(void)
5352 {
5353 if (!AWR_init())
5354 return;
5355
5356 SHOWSYSMETRIC(SM_CYCAPTION);
5357 SHOWSYSMETRIC(SM_CYSMCAPTION);
5358 SHOWSYSMETRIC(SM_CYMENU);
5359 SHOWSYSMETRIC(SM_CXEDGE);
5360 SHOWSYSMETRIC(SM_CYEDGE);
5361 SHOWSYSMETRIC(SM_CXVSCROLL);
5362 SHOWSYSMETRIC(SM_CYHSCROLL);
5363 SHOWSYSMETRIC(SM_CXFRAME);
5364 SHOWSYSMETRIC(SM_CYFRAME);
5365 SHOWSYSMETRIC(SM_CXDLGFRAME);
5366 SHOWSYSMETRIC(SM_CYDLGFRAME);
5367 SHOWSYSMETRIC(SM_CXBORDER);
5368 SHOWSYSMETRIC(SM_CYBORDER);
5369
5370 test_AWR_window_size(FALSE);
5371 test_AWR_window_size(TRUE);
5372 test_AWR_flags();
5373
5374 DestroyMenu(hmenu);
5375 }
5376 #undef SHOWSYSMETRIC
5377
5378
5379 /* Global variables to trigger exit from loop */
5380 static int redrawComplete, WMPAINT_count;
5381
5382 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5383 {
5384 switch (msg)
5385 {
5386 case WM_PAINT:
5387 trace("doing WM_PAINT %d\n", WMPAINT_count);
5388 WMPAINT_count++;
5389 if (WMPAINT_count > 10 && redrawComplete == 0) {
5390 PAINTSTRUCT ps;
5391 BeginPaint(hwnd, &ps);
5392 EndPaint(hwnd, &ps);
5393 return 1;
5394 }
5395 return 0;
5396 }
5397 return DefWindowProcA(hwnd, msg, wparam, lparam);
5398 }
5399
5400 /* Ensure we exit from RedrawNow regardless of invalidated area */
5401 static void test_redrawnow(void)
5402 {
5403 WNDCLASSA cls;
5404 HWND hwndMain;
5405
5406 cls.style = CS_DBLCLKS;
5407 cls.lpfnWndProc = redraw_window_procA;
5408 cls.cbClsExtra = 0;
5409 cls.cbWndExtra = 0;
5410 cls.hInstance = GetModuleHandleA(0);
5411 cls.hIcon = 0;
5412 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5413 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5414 cls.lpszMenuName = NULL;
5415 cls.lpszClassName = "RedrawWindowClass";
5416
5417 if(!RegisterClassA(&cls)) {
5418 trace("Register failed %d\n", GetLastError());
5419 return;
5420 }
5421
5422 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
5423 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
5424
5425 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5426 ShowWindow(hwndMain, SW_SHOW);
5427 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5428 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
5429 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
5430 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
5431 redrawComplete = TRUE;
5432 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
5433
5434 /* clean up */
5435 DestroyWindow( hwndMain);
5436 }
5437
5438 struct parentdc_stat {
5439 RECT client;
5440 RECT clip;
5441 RECT paint;
5442 };
5443
5444 struct parentdc_test {
5445 struct parentdc_stat main, main_todo;
5446 struct parentdc_stat child1, child1_todo;
5447 struct parentdc_stat child2, child2_todo;
5448 };
5449
5450 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5451 {
5452 RECT rc;
5453 PAINTSTRUCT ps;
5454
5455 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
5456
5457 switch (msg)
5458 {
5459 case WM_PAINT:
5460 GetClientRect(hwnd, &rc);
5461 t->client = rc;
5462 GetWindowRect(hwnd, &rc);
5463 trace("WM_PAINT: hwnd %p, client rect %s, window rect %s\n", hwnd,
5464 wine_dbgstr_rect(&t->client), wine_dbgstr_rect(&rc));
5465 BeginPaint(hwnd, &ps);
5466 t->paint = ps.rcPaint;
5467 GetClipBox(ps.hdc, &rc);
5468 t->clip = rc;
5469 trace("clip rect %s, paint rect %s\n", wine_dbgstr_rect(&rc),
5470 wine_dbgstr_rect(&ps.rcPaint));
5471 EndPaint(hwnd, &ps);
5472 return 0;
5473 }
5474 return DefWindowProcA(hwnd, msg, wparam, lparam);
5475 }
5476
5477 static void zero_parentdc_stat(struct parentdc_stat *t)
5478 {
5479 SetRectEmpty(&t->client);
5480 SetRectEmpty(&t->clip);
5481 SetRectEmpty(&t->paint);
5482 }
5483
5484 static void zero_parentdc_test(struct parentdc_test *t)
5485 {
5486 zero_parentdc_stat(&t->main);
5487 zero_parentdc_stat(&t->child1);
5488 zero_parentdc_stat(&t->child2);
5489 }
5490
5491 #define parentdc_field_ok(t, w, r, f, got) \
5492 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
5493 ": expected %d, got %d\n", \
5494 t.w.r.f, got.w.r.f)
5495
5496 #define parentdc_todo_field_ok(t, w, r, f, got) \
5497 todo_wine_if (t.w##_todo.r.f) \
5498 parentdc_field_ok(t, w, r, f, got);
5499
5500 #define parentdc_rect_ok(t, w, r, got) \
5501 parentdc_todo_field_ok(t, w, r, left, got); \
5502 parentdc_todo_field_ok(t, w, r, top, got); \
5503 parentdc_todo_field_ok(t, w, r, right, got); \
5504 parentdc_todo_field_ok(t, w, r, bottom, got);
5505
5506 #define parentdc_win_ok(t, w, got) \
5507 parentdc_rect_ok(t, w, client, got); \
5508 parentdc_rect_ok(t, w, clip, got); \
5509 parentdc_rect_ok(t, w, paint, got);
5510
5511 #define parentdc_ok(t, got) \
5512 parentdc_win_ok(t, main, got); \
5513 parentdc_win_ok(t, child1, got); \
5514 parentdc_win_ok(t, child2, got);
5515
5516 static void test_csparentdc(void)
5517 {
5518 WNDCLASSA clsMain, cls;
5519 HWND hwndMain, hwnd1, hwnd2;
5520 RECT rc;
5521
5522 struct parentdc_test test_answer;
5523
5524 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
5525 const struct parentdc_test test1 =
5526 {
5527 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
5528 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5529 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5530 };
5531
5532 const struct parentdc_test test2 =
5533 {
5534 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
5535 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5536 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5537 };
5538
5539 const struct parentdc_test test3 =
5540 {
5541 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5542 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5543 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5544 };
5545
5546 const struct parentdc_test test4 =
5547 {
5548 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
5549 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
5550 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5551 };
5552
5553 const struct parentdc_test test5 =
5554 {
5555 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
5556 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5557 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
5558 };
5559
5560 const struct parentdc_test test6 =
5561 {
5562 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5563 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
5564 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5565 };
5566
5567 const struct parentdc_test test7 =
5568 {
5569 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5570 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
5571 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
5572 };
5573 #undef nothing_todo
5574
5575 clsMain.style = CS_DBLCLKS;
5576 clsMain.lpfnWndProc = parentdc_window_procA;
5577 clsMain.cbClsExtra = 0;
5578 clsMain.cbWndExtra = 0;
5579 clsMain.hInstance = GetModuleHandleA(0);
5580 clsMain.hIcon = 0;
5581 clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5582 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
5583 clsMain.lpszMenuName = NULL;
5584 clsMain.lpszClassName = "ParentDcMainWindowClass";
5585
5586 if(!RegisterClassA(&clsMain)) {
5587 trace("Register failed %d\n", GetLastError());
5588 return;
5589 }
5590
5591 cls.style = CS_DBLCLKS | CS_PARENTDC;
5592 cls.lpfnWndProc = parentdc_window_procA;
5593 cls.cbClsExtra = 0;
5594 cls.cbWndExtra = 0;
5595 cls.hInstance = GetModuleHandleA(0);
5596 cls.hIcon = 0;
5597 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
5598 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5599 cls.lpszMenuName = NULL;
5600 cls.lpszClassName = "ParentDcWindowClass";
5601
5602 if(!RegisterClassA(&cls)) {
5603 trace("Register failed %d\n", GetLastError());
5604 return;
5605 }
5606
5607 SetRect(&rc, 0, 0, 150, 150);
5608 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
5609 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
5610 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
5611 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
5612 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
5613 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
5614 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
5615 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
5616 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
5617 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
5618 ShowWindow(hwndMain, SW_SHOW);
5619 ShowWindow(hwnd1, SW_SHOW);
5620 ShowWindow(hwnd2, SW_SHOW);
5621 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
5622 flush_events( TRUE );
5623
5624 zero_parentdc_test(&test_answer);
5625 InvalidateRect(hwndMain, NULL, TRUE);
5626 flush_events( TRUE );
5627 parentdc_ok(test1, test_answer);
5628
5629 zero_parentdc_test(&test_answer);
5630 SetRect(&rc, 0, 0, 50, 50);
5631 InvalidateRect(hwndMain, &rc, TRUE);
5632 flush_events( TRUE );
5633 parentdc_ok(test2, test_answer);
5634
5635 zero_parentdc_test(&test_answer);
5636 SetRect(&rc, 0, 0, 10, 10);
5637 InvalidateRect(hwndMain, &rc, TRUE);
5638 flush_events( TRUE );
5639 parentdc_ok(test3, test_answer);
5640
5641 zero_parentdc_test(&test_answer);
5642 SetRect(&rc, 40, 40, 50, 50);
5643 InvalidateRect(hwndMain, &rc, TRUE);
5644 flush_events( TRUE );
5645 parentdc_ok(test4, test_answer);
5646
5647 zero_parentdc_test(&test_answer);
5648 SetRect(&rc, 20, 20, 60, 60);
5649 InvalidateRect(hwndMain, &rc, TRUE);
5650 flush_events( TRUE );
5651 parentdc_ok(test5, test_answer);
5652
5653 zero_parentdc_test(&test_answer);
5654 SetRect(&rc, 0, 0, 10, 10);
5655 InvalidateRect(hwnd1, &rc, TRUE);
5656 flush_events( TRUE );
5657 parentdc_ok(test6, test_answer);
5658
5659 zero_parentdc_test(&test_answer);
5660 SetRect(&rc, -5, -5, 65, 65);
5661 InvalidateRect(hwnd1, &rc, TRUE);
5662 flush_events( TRUE );
5663 parentdc_ok(test7, test_answer);
5664
5665 DestroyWindow(hwndMain);
5666 DestroyWindow(hwnd1);
5667 DestroyWindow(hwnd2);
5668 }
5669
5670 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5671 {
5672 return DefWindowProcA(hwnd, msg, wparam, lparam);
5673 }
5674
5675 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5676 {
5677 return DefWindowProcW(hwnd, msg, wparam, lparam);
5678 }
5679
5680 static void test_IsWindowUnicode(void)
5681 {
5682 static const char ansi_class_nameA[] = "ansi class name";
5683 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
5684 static const char unicode_class_nameA[] = "unicode class name";
5685 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
5686 WNDCLASSA classA;
5687 WNDCLASSW classW;
5688 HWND hwnd;
5689 ATOM atom;
5690
5691 memset(&classW, 0, sizeof(classW));
5692 classW.hInstance = GetModuleHandleA(0);
5693 classW.lpfnWndProc = def_window_procW;
5694 classW.lpszClassName = unicode_class_nameW;
5695 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
5696
5697 memset(&classA, 0, sizeof(classA));
5698 classA.hInstance = GetModuleHandleA(0);
5699 classA.lpfnWndProc = def_window_procA;
5700 classA.lpszClassName = ansi_class_nameA;
5701 atom = RegisterClassA(&classA);
5702 assert(atom);
5703
5704 /* unicode class: window proc */
5705 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
5706 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5707 assert(hwnd);
5708
5709 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5710 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5711 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5712 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5713 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5714
5715 DestroyWindow(hwnd);
5716
5717 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
5718 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5719 assert(hwnd);
5720
5721 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5722 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5723 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5724 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5725 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5726
5727 DestroyWindow(hwnd);
5728
5729 /* ansi class: window proc */
5730 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
5731 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5732 assert(hwnd);
5733
5734 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5735 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5736 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5737 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5738 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5739
5740 DestroyWindow(hwnd);
5741
5742 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
5743 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5744 assert(hwnd);
5745
5746 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5747 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
5748 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5749 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
5750 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5751
5752 DestroyWindow(hwnd);
5753
5754 /* unicode class: class proc */
5755 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
5756 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5757 assert(hwnd);
5758
5759 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5760 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5761 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5762 /* do not restore class window proc back to unicode */
5763
5764 DestroyWindow(hwnd);
5765
5766 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
5767 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5768 assert(hwnd);
5769
5770 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5771 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5772 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5773
5774 DestroyWindow(hwnd);
5775
5776 /* ansi class: class proc */
5777 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
5778 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5779 assert(hwnd);
5780
5781 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5782 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
5783 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
5784 /* do not restore class window proc back to ansi */
5785
5786 DestroyWindow(hwnd);
5787
5788 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
5789 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
5790 assert(hwnd);
5791
5792 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5793 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
5794 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
5795
5796 DestroyWindow(hwnd);
5797 }
5798
5799 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5800 {
5801 MINMAXINFO *minmax;
5802
5803 if (msg != WM_GETMINMAXINFO)
5804 return DefWindowProcA(hwnd, msg, wp, lp);
5805
5806 minmax = (MINMAXINFO *)lp;
5807
5808 if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
5809 {
5810 minmax->ptReserved.x = 0;
5811 minmax->ptReserved.y = 0;
5812 minmax->ptMaxSize.x = 400;
5813 minmax->ptMaxSize.y = 400;
5814 minmax->ptMaxPosition.x = 300;
5815 minmax->ptMaxPosition.y = 300;
5816 minmax->ptMaxTrackSize.x = 200;
5817 minmax->ptMaxTrackSize.y = 200;
5818 minmax->ptMinTrackSize.x = 100;
5819 minmax->ptMinTrackSize.y = 100;
5820 }
5821 else
5822 DefWindowProcA(hwnd, msg, wp, lp);
5823 return 1;
5824 }
5825
5826 static int expected_cx, expected_cy;
5827 static RECT expected_rect, broken_rect;
5828
5829 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5830 {
5831 switch(msg)
5832 {
5833 case WM_GETMINMAXINFO:
5834 {
5835 RECT rect;
5836 GetWindowRect( hwnd, &rect );
5837 ok( !rect.left && !rect.top && !rect.right && !rect.bottom, "wrong rect %s\n",
5838 wine_dbgstr_rect( &rect ));
5839 return DefWindowProcA(hwnd, msg, wp, lp);
5840 }
5841 case WM_NCCREATE:
5842 case WM_CREATE:
5843 {
5844 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5845 RECT rect;
5846 GetWindowRect( hwnd, &rect );
5847 trace( "hwnd %p msg %x size %dx%d rect %s\n", hwnd, msg, cs->cx, cs->cy,
5848 wine_dbgstr_rect( &rect ));
5849 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
5850 "wrong x size %d/%d\n", cs->cx, expected_cx );
5851 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
5852 "wrong y size %d/%d\n", cs->cy, expected_cy );
5853 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
5854 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
5855 (rect.right - rect.left == min( 65535, expected_rect.right - expected_rect.left ) &&
5856 rect.bottom - rect.top == min( 65535, expected_rect.bottom - expected_rect.top )) ||
5857 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
5858 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
5859 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
5860 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
5861 "wrong rect %s / %s\n", wine_dbgstr_rect( &rect ), wine_dbgstr_rect( &expected_rect ));
5862 return DefWindowProcA(hwnd, msg, wp, lp);
5863 }
5864 case WM_NCCALCSIZE:
5865 {
5866 RECT rect, *r = (RECT *)lp;
5867 GetWindowRect( hwnd, &rect );
5868 ok( EqualRect( &rect, r ), "passed rect %s doesn't match window rect %s\n",
5869 wine_dbgstr_rect( r ), wine_dbgstr_rect( &rect ));
5870 return DefWindowProcA(hwnd, msg, wp, lp);
5871 }
5872 default:
5873 return DefWindowProcA(hwnd, msg, wp, lp);
5874 }
5875 }
5876
5877 static void test_CreateWindow(void)
5878 {
5879 WNDCLASSA cls;
5880 HWND hwnd, parent;
5881 HMENU hmenu;
5882 RECT rc, rc_minmax;
5883 MINMAXINFO minmax;
5884 BOOL res;
5885
5886 #define expect_menu(window, menu) \
5887 SetLastError(0xdeadbeef); \
5888 res = (GetMenu(window) == (HMENU)menu); \
5889 ok(res, "GetMenu error %d\n", GetLastError())
5890
5891 #define expect_style(window, style)\
5892 ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
5893
5894 #define expect_ex_style(window, ex_style)\
5895 ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
5896
5897 #define expect_gle_broken_9x(gle)\
5898 ok(GetLastError() == gle ||\
5899 broken(GetLastError() == 0xdeadbeef),\
5900 "IsMenu set error %d\n", GetLastError())
5901
5902 hmenu = CreateMenu();
5903 assert(hmenu != 0);
5904 parent = GetDesktopWindow();
5905 assert(parent != 0);
5906
5907 SetLastError(0xdeadbeef);
5908 res = IsMenu(hmenu);
5909 ok(res, "IsMenu error %d\n", GetLastError());
5910
5911 /* WS_CHILD */
5912 SetLastError(0xdeadbeef);
5913 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
5914 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5915 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5916 expect_menu(hwnd, 1);
5917 expect_style(hwnd, WS_CHILD);
5918 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5919 DestroyWindow(hwnd);
5920
5921 SetLastError(0xdeadbeef);
5922 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
5923 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5924 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5925 expect_menu(hwnd, 1);
5926 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5927 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5928 DestroyWindow(hwnd);
5929
5930 SetLastError(0xdeadbeef);
5931 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
5932 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5933 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5934 expect_menu(hwnd, 1);
5935 expect_style(hwnd, WS_CHILD);
5936 expect_ex_style(hwnd, 0);
5937 DestroyWindow(hwnd);
5938
5939 SetLastError(0xdeadbeef);
5940 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
5941 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
5942 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5943 expect_menu(hwnd, 1);
5944 expect_style(hwnd, WS_CHILD | WS_CAPTION);
5945 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5946 DestroyWindow(hwnd);
5947
5948 /* WS_POPUP */
5949 SetLastError(0xdeadbeef);
5950 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
5951 0, 0, 100, 100, parent, hmenu, 0, NULL);
5952 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5953 expect_menu(hwnd, hmenu);
5954 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5955 expect_ex_style(hwnd, WS_EX_APPWINDOW);
5956 DestroyWindow(hwnd);
5957 SetLastError(0xdeadbeef);
5958 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5959 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5960
5961 hmenu = CreateMenu();
5962 assert(hmenu != 0);
5963 SetLastError(0xdeadbeef);
5964 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
5965 0, 0, 100, 100, parent, hmenu, 0, NULL);
5966 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5967 expect_menu(hwnd, hmenu);
5968 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5969 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
5970 DestroyWindow(hwnd);
5971 SetLastError(0xdeadbeef);
5972 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5973 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5974
5975 hmenu = CreateMenu();
5976 assert(hmenu != 0);
5977 SetLastError(0xdeadbeef);
5978 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
5979 0, 0, 100, 100, parent, hmenu, 0, NULL);
5980 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5981 expect_menu(hwnd, hmenu);
5982 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
5983 expect_ex_style(hwnd, 0);
5984 DestroyWindow(hwnd);
5985 SetLastError(0xdeadbeef);
5986 ok(!IsMenu(hmenu), "IsMenu should fail\n");
5987 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
5988
5989 hmenu = CreateMenu();
5990 assert(hmenu != 0);
5991 SetLastError(0xdeadbeef);
5992 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
5993 0, 0, 100, 100, parent, hmenu, 0, NULL);
5994 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
5995 expect_menu(hwnd, hmenu);
5996 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
5997 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
5998 DestroyWindow(hwnd);
5999 SetLastError(0xdeadbeef);
6000 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6001 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6002
6003 /* WS_CHILD | WS_POPUP */
6004 SetLastError(0xdeadbeef);
6005 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
6006 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6007 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6008 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6009 if (hwnd)
6010 DestroyWindow(hwnd);
6011
6012 hmenu = CreateMenu();
6013 assert(hmenu != 0);
6014 SetLastError(0xdeadbeef);
6015 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
6016 0, 0, 100, 100, parent, hmenu, 0, NULL);
6017 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6018 expect_menu(hwnd, hmenu);
6019 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
6020 expect_ex_style(hwnd, WS_EX_APPWINDOW);
6021 DestroyWindow(hwnd);
6022 SetLastError(0xdeadbeef);
6023 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6024 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6025
6026 SetLastError(0xdeadbeef);
6027 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6028 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6029 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6030 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6031 if (hwnd)
6032 DestroyWindow(hwnd);
6033
6034 hmenu = CreateMenu();
6035 assert(hmenu != 0);
6036 SetLastError(0xdeadbeef);
6037 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6038 0, 0, 100, 100, parent, hmenu, 0, NULL);
6039 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6040 expect_menu(hwnd, hmenu);
6041 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6042 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
6043 DestroyWindow(hwnd);
6044 SetLastError(0xdeadbeef);
6045 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6046 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6047
6048 SetLastError(0xdeadbeef);
6049 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
6050 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6051 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6052 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6053 if (hwnd)
6054 DestroyWindow(hwnd);
6055
6056 hmenu = CreateMenu();
6057 assert(hmenu != 0);
6058 SetLastError(0xdeadbeef);
6059 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
6060 0, 0, 100, 100, parent, hmenu, 0, NULL);
6061 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6062 expect_menu(hwnd, hmenu);
6063 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
6064 expect_ex_style(hwnd, 0);
6065 DestroyWindow(hwnd);
6066 SetLastError(0xdeadbeef);
6067 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6068 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6069
6070 SetLastError(0xdeadbeef);
6071 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6072 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
6073 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
6074 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6075 if (hwnd)
6076 DestroyWindow(hwnd);
6077
6078 hmenu = CreateMenu();
6079 assert(hmenu != 0);
6080 SetLastError(0xdeadbeef);
6081 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
6082 0, 0, 100, 100, parent, hmenu, 0, NULL);
6083 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6084 expect_menu(hwnd, hmenu);
6085 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
6086 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6087 DestroyWindow(hwnd);
6088 SetLastError(0xdeadbeef);
6089 ok(!IsMenu(hmenu), "IsMenu should fail\n");
6090 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
6091
6092 /* test child window sizing */
6093 cls.style = 0;
6094 cls.lpfnWndProc = minmax_wnd_proc;
6095 cls.cbClsExtra = 0;
6096 cls.cbWndExtra = 0;
6097 cls.hInstance = GetModuleHandleA(NULL);
6098 cls.hIcon = 0;
6099 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6100 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6101 cls.lpszMenuName = NULL;
6102 cls.lpszClassName = "MinMax_WndClass";
6103 RegisterClassA(&cls);
6104
6105 SetLastError(0xdeadbeef);
6106 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
6107 0, 0, 100, 100, 0, 0, 0, NULL);
6108 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
6109 expect_menu(parent, 0);
6110 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
6111 expect_ex_style(parent, WS_EX_WINDOWEDGE);
6112
6113 memset(&minmax, 0, sizeof(minmax));
6114 SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
6115 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
6116 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
6117 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
6118 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
6119
6120 GetWindowRect(parent, &rc);
6121 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
6122 GetClientRect(parent, &rc);
6123 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
6124
6125 InflateRect(&rc, 200, 200);
6126 trace("creating child with rect %s\n", wine_dbgstr_rect(&rc));
6127
6128 SetLastError(0xdeadbeef);
6129 hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
6130 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
6131 parent, (HMENU)1, 0, NULL);
6132 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
6133 expect_menu(hwnd, 1);
6134 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
6135 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
6136
6137 memset(&minmax, 0, sizeof(minmax));
6138 SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
6139 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
6140
6141 GetWindowRect(hwnd, &rc);
6142 OffsetRect(&rc, -rc.left, -rc.top);
6143 ok(EqualRect(&rc, &rc_minmax), "rects don't match: %s and %s\n", wine_dbgstr_rect(&rc),
6144 wine_dbgstr_rect(&rc_minmax));
6145 DestroyWindow(hwnd);
6146
6147 cls.lpfnWndProc = winsizes_wnd_proc;
6148 cls.lpszClassName = "Sizes_WndClass";
6149 RegisterClassA(&cls);
6150
6151 expected_cx = expected_cy = 200000;
6152 SetRect( &expected_rect, 0, 0, 200000, 200000 );
6153 broken_rect = expected_rect;
6154 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
6155 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6156 GetClientRect( hwnd, &rc );
6157 ok( rc.right == 200000 || rc.right == 65535 || broken(rc.right == (short)200000),
6158 "invalid rect right %u\n", rc.right );
6159 ok( rc.bottom == 200000 || rc.bottom == 65535 || broken(rc.bottom == (short)200000),
6160 "invalid rect bottom %u\n", rc.bottom );
6161 DestroyWindow(hwnd);
6162
6163 expected_cx = expected_cy = -10;
6164 SetRectEmpty(&expected_rect);
6165 SetRect( &broken_rect, 0, 0, -10, -10 );
6166 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
6167 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6168 GetClientRect( hwnd, &rc );
6169 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
6170 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
6171 DestroyWindow(hwnd);
6172
6173 expected_cx = expected_cy = -200000;
6174 SetRectEmpty(&expected_rect);
6175 SetRect( &broken_rect, 0, 0, -200000, -200000 );
6176 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
6177 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6178 GetClientRect( hwnd, &rc );
6179 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
6180 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
6181 DestroyWindow(hwnd);
6182
6183 /* we need a parent at 0,0 so that child coordinates match */
6184 DestroyWindow(parent);
6185 parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
6186 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
6187
6188 expected_cx = 100;
6189 expected_cy = 0x7fffffff;
6190 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
6191 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
6192 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
6193 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6194 GetClientRect( hwnd, &rc );
6195 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
6196 ok( rc.bottom == 0x7fffffff - 10 || rc.bottom ==65535 || broken(rc.bottom == 0),
6197 "invalid rect bottom %u\n", rc.bottom );
6198 DestroyWindow(hwnd);
6199
6200 expected_cx = 0x7fffffff;
6201 expected_cy = 0x7fffffff;
6202 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
6203 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
6204 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
6205 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6206 GetClientRect( hwnd, &rc );
6207 ok( rc.right == 0x7fffffff - 20 || rc.right == 65535 || broken(rc.right == 0),
6208 "invalid rect right %u\n", rc.right );
6209 ok( rc.bottom == 0x7fffffff - 10 || rc.right == 65535 || broken(rc.bottom == 0),
6210 "invalid rect bottom %u\n", rc.bottom );
6211 DestroyWindow(hwnd);
6212
6213 /* top level window */
6214 expected_cx = expected_cy = 200000;
6215 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
6216 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
6217 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6218 GetClientRect( hwnd, &rc );
6219 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
6220 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
6221 DestroyWindow(hwnd);
6222
6223 if (pGetLayout && pSetLayout)
6224 {
6225 HDC hdc = GetDC( parent );
6226 pSetLayout( hdc, LAYOUT_RTL );
6227 if (pGetLayout( hdc ))
6228 {
6229 ReleaseDC( parent, hdc );
6230 DestroyWindow( parent );
6231 SetLastError( 0xdeadbeef );
6232 parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
6233 0, 0, 100, 100, 0, 0, 0, NULL);
6234 ok( parent != 0, "creation failed err %u\n", GetLastError());
6235 expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
6236 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
6237 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6238 expect_ex_style( hwnd, WS_EX_LAYOUTRTL );
6239 DestroyWindow( hwnd );
6240 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 20, 20, parent, 0, 0, NULL);
6241 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6242 expect_ex_style( hwnd, 0 );
6243 DestroyWindow( hwnd );
6244 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT );
6245 hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 20, 20, parent, 0, 0, NULL);
6246 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6247 expect_ex_style( hwnd, 0 );
6248 DestroyWindow( hwnd );
6249
6250 if (pGetProcessDefaultLayout && pSetProcessDefaultLayout)
6251 {
6252 DWORD layout;
6253
6254 SetLastError( 0xdeadbeef );
6255 ok( !pGetProcessDefaultLayout( NULL ), "GetProcessDefaultLayout succeeded\n" );
6256 ok( GetLastError() == ERROR_NOACCESS, "wrong error %u\n", GetLastError() );
6257 SetLastError( 0xdeadbeef );
6258 res = pGetProcessDefaultLayout( &layout );
6259 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6260 ok( layout == 0, "GetProcessDefaultLayout wrong layout %x\n", layout );
6261 SetLastError( 0xdeadbeef );
6262 res = pSetProcessDefaultLayout( 7 );
6263 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6264 res = pGetProcessDefaultLayout( &layout );
6265 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6266 ok( layout == 7, "GetProcessDefaultLayout wrong layout %x\n", layout );
6267 SetLastError( 0xdeadbeef );
6268 res = pSetProcessDefaultLayout( LAYOUT_RTL );
6269 ok( res, "SetProcessDefaultLayout failed err %u\n", GetLastError ());
6270 res = pGetProcessDefaultLayout( &layout );
6271 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
6272 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
6273 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
6274 0, 0, 100, 100, 0, 0, 0, NULL);
6275 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6276 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
6277 DestroyWindow( hwnd );
6278 hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
6279 0, 0, 100, 100, parent, 0, 0, NULL);
6280 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
6281 expect_ex_style( hwnd, WS_EX_APPWINDOW );
6282 DestroyWindow( hwnd );
6283 pSetProcessDefaultLayout( 0 );
6284 }
6285 else win_skip( "SetProcessDefaultLayout not supported\n" );
6286 }
6287 else win_skip( "SetLayout not supported\n" );
6288 }
6289 else win_skip( "SetLayout not available\n" );
6290
6291 DestroyWindow(parent);
6292
6293 UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
6294 UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
6295
6296 #undef expect_gle_broken_9x
6297 #undef expect_menu
6298 #undef expect_style
6299 #undef expect_ex_style
6300 }
6301
6302 /* function that remembers whether the system the test is running on sets the
6303 * last error for user32 functions to make the tests stricter */
6304 static int check_error(DWORD actual, DWORD expected)
6305 {
6306 static int sets_last_error = -1;
6307 if (sets_last_error == -1)
6308 sets_last_error = (actual != 0xdeadbeef);
6309 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
6310 }
6311
6312 static void test_SetWindowLong(void)
6313 {
6314 LONG_PTR retval;
6315 WNDPROC old_window_procW;
6316
6317 SetLastError(0xdeadbeef);
6318 retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
6319 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
6320 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
6321 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
6322
6323 SetLastError(0xdeadbeef);
6324 retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
6325 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
6326 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
6327 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
6328
6329 SetLastError(0xdeadbeef);
6330 retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
6331 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
6332 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
6333 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6334 retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
6335 ok((WNDPROC)retval == main_window_procA,
6336 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
6337 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
6338
6339 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
6340 SetLastError(0xdeadbeef);
6341 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
6342 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
6343 {
6344 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
6345 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
6346 ok((WNDPROC)retval == old_window_procW,
6347 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
6348 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
6349
6350 /* set it back to ANSI */
6351 SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
6352 }
6353 }
6354
6355 static LRESULT WINAPI check_style_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
6356 {
6357 const STYLESTRUCT *expected = (STYLESTRUCT *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
6358 const STYLESTRUCT *got = (STYLESTRUCT *)lParam;
6359
6360 if (message == WM_STYLECHANGING && wParam == GWL_STYLE)
6361 {
6362 ok(got->styleOld == expected[0].styleOld, "expected old style %#x, got %#x\n",
6363 expected[0].styleOld, got->styleOld);
6364 ok(got->styleNew == expected[0].styleNew, "expected new style %#x, got %#x\n",
6365 expected[0].styleNew, got->styleNew);
6366 }
6367 else if (message == WM_STYLECHANGED && wParam == GWL_STYLE)
6368 {
6369 ok(got->styleOld == expected[1].styleOld, "expected old style %#x, got %#x\n",
6370 expected[1].styleOld, got->styleOld);
6371 ok(got->styleNew == expected[1].styleNew, "expected new style %#x, got %#x\n",
6372 expected[1].styleNew, got->styleNew);
6373 }
6374
6375 return DefWindowProcA(hwnd, message, wParam, lParam);
6376 }
6377
6378 static void test_set_window_style(void)
6379 {
6380 LONG expected_style, new_style, old_style;
6381 STYLESTRUCT expected_stylestruct[2];
6382 unsigned int i;
6383 WNDCLASSA cls;
6384 HWND hwnd;
6385
6386 static const struct
6387 {
6388 LONG creation_style;
6389 LONG style;
6390 }
6391 tests[] =
6392 {
6393 { WS_MINIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6394 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6395 { WS_MINIMIZE | WS_CLIPSIBLINGS | WS_CAPTION,
6396 WS_CLIPSIBLINGS | WS_CAPTION },
6397 { WS_MAXIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6398 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6399 { WS_MAXIMIZE | WS_CLIPSIBLINGS | WS_CAPTION,
6400 WS_CLIPSIBLINGS | WS_CAPTION },
6401 { WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6402 WS_MINIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6403 { WS_CLIPSIBLINGS | WS_CAPTION,
6404 WS_MINIMIZE | WS_CLIPSIBLINGS | WS_CAPTION },
6405 { WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
6406 WS_MAXIMIZE | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX },
6407 { WS_CLIPSIBLINGS | WS_CAPTION,
6408 WS_MAXIMIZE | WS_CLIPSIBLINGS | WS_CAPTION },
6409 };
6410
6411 memset(&cls, 0, sizeof(cls));
6412 cls.lpfnWndProc = check_style_wnd_proc;
6413 cls.hInstance = GetModuleHandleA(0);
6414 cls.lpszClassName = "TestSetWindowStylesClass";
6415 ok(RegisterClassA(&cls), "RegisterClass failed\n");
6416
6417 for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
6418 {
6419 expected_style = tests[i].style;
6420 if (tests[i].creation_style & WS_MINIMIZE)
6421 expected_style |= WS_MINIMIZE;
6422
6423 expected_stylestruct[0].styleOld = tests[i].creation_style;
6424 expected_stylestruct[0].styleNew = tests[i].style;
6425 expected_stylestruct[1].styleOld = tests[i].creation_style;
6426 expected_stylestruct[1].styleNew = expected_style;
6427
6428 hwnd = CreateWindowA(cls.lpszClassName, "Test set styles",
6429 tests[i].creation_style, 100, 100, 200, 200, 0, 0, 0, NULL);
6430 ok(hwnd != 0, "CreateWindow failed\n");
6431 SetWindowLongPtrA(hwnd, GWLP_USERDATA, (LONG_PTR)&expected_stylestruct);
6432
6433 old_style = SetWindowLongA(hwnd, GWL_STYLE, tests[i].style);
6434 ok(old_style == tests[i].creation_style, "expected old style %#x, got %#x\n",
6435 tests[i].creation_style, old_style);
6436 new_style = GetWindowLongA(hwnd, GWL_STYLE);
6437 ok(new_style == expected_style, "expected new style %#x, got %#x\n",
6438 expected_style, new_style);
6439
6440 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0);
6441 DestroyWindow(hwnd);
6442 }
6443
6444 UnregisterClassA(cls.lpszClassName, cls.hInstance);
6445 }
6446
6447 static void test_ShowWindow(void)
6448 {
6449 HWND hwnd;
6450 DWORD style;
6451 RECT rcMain, rc, rcMinimized;
6452 LPARAM ret;
6453
6454 SetRect(&rcMain, 120, 120, 210, 210);
6455
6456 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
6457 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
6458 WS_MAXIMIZEBOX | WS_POPUP,
6459 rcMain.left, rcMain.top,
6460 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
6461 0, 0, 0, NULL);
6462 assert(hwnd);
6463
6464 style = GetWindowLongA(hwnd, GWL_STYLE);
6465 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6466 ok(!(style & WS_VISIBLE), "window should not be visible\n");
6467 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6468 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6469 GetWindowRect(hwnd, &rc);
6470 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6471 wine_dbgstr_rect(&rc));
6472
6473 ret = ShowWindow(hwnd, SW_SHOW);
6474 ok(!ret, "not expected ret: %lu\n", ret);
6475 style = GetWindowLongA(hwnd, GWL_STYLE);
6476 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6477 ok(style & WS_VISIBLE, "window should be visible\n");
6478 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6479 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6480 GetWindowRect(hwnd, &rc);
6481 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6482 wine_dbgstr_rect(&rc));
6483
6484 ret = ShowWindow(hwnd, SW_MINIMIZE);
6485 ok(ret, "not expected ret: %lu\n", ret);
6486 style = GetWindowLongA(hwnd, GWL_STYLE);
6487 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6488 ok(style & WS_VISIBLE, "window should be visible\n");
6489 ok(style & WS_MINIMIZE, "window should be minimized\n");
6490 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6491 GetWindowRect(hwnd, &rcMinimized);
6492 ok(!EqualRect(&rcMain, &rcMinimized), "rects shouldn't match\n");
6493 /* shouldn't be able to resize minimized windows */
6494 ret = SetWindowPos(hwnd, 0, 0, 0,
6495 (rcMinimized.right - rcMinimized.left) * 2,
6496 (rcMinimized.bottom - rcMinimized.top) * 2,
6497 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
6498 ok(ret, "not expected ret: %lu\n", ret);
6499 GetWindowRect(hwnd, &rc);
6500 ok(EqualRect(&rc, &rcMinimized), "rects should match\n");
6501
6502 ShowWindow(hwnd, SW_RESTORE);
6503 ok(ret, "not expected ret: %lu\n", ret);
6504 style = GetWindowLongA(hwnd, GWL_STYLE);
6505 ok(!(style & WS_DISABLED), "window should not be disabled\n");
6506 ok(style & WS_VISIBLE, "window should be visible\n");
6507 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6508 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6509 GetWindowRect(hwnd, &rc);
6510 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6511 wine_dbgstr_rect(&rc));
6512
6513 ret = EnableWindow(hwnd, FALSE);
6514 ok(!ret, "not expected ret: %lu\n", ret);
6515 style = GetWindowLongA(hwnd, GWL_STYLE);
6516 ok(style & WS_DISABLED, "window should be disabled\n");
6517
6518 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
6519 ok(!ret, "not expected ret: %lu\n", ret);
6520 style = GetWindowLongA(hwnd, GWL_STYLE);
6521 ok(style & WS_DISABLED, "window should be disabled\n");
6522 ok(style & WS_VISIBLE, "window should be visible\n");
6523 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6524 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6525 GetWindowRect(hwnd, &rc);
6526 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6527 wine_dbgstr_rect(&rc));
6528
6529 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
6530 ok(!ret, "not expected ret: %lu\n", ret);
6531 style = GetWindowLongA(hwnd, GWL_STYLE);
6532 ok(style & WS_DISABLED, "window should be disabled\n");
6533 ok(style & WS_VISIBLE, "window should be visible\n");
6534 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6535 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6536 GetWindowRect(hwnd, &rc);
6537 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6538 wine_dbgstr_rect(&rc));
6539
6540 ret = ShowWindow(hwnd, SW_MINIMIZE);
6541 ok(ret, "not expected ret: %lu\n", ret);
6542 style = GetWindowLongA(hwnd, GWL_STYLE);
6543 ok(style & WS_DISABLED, "window should be disabled\n");
6544 ok(style & WS_VISIBLE, "window should be visible\n");
6545 ok(style & WS_MINIMIZE, "window should be minimized\n");
6546 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6547 GetWindowRect(hwnd, &rc);
6548 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
6549
6550 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
6551 ok(!ret, "not expected ret: %lu\n", ret);
6552 style = GetWindowLongA(hwnd, GWL_STYLE);
6553 ok(style & WS_DISABLED, "window should be disabled\n");
6554 ok(style & WS_VISIBLE, "window should be visible\n");
6555 ok(style & WS_MINIMIZE, "window should be minimized\n");
6556 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6557 GetWindowRect(hwnd, &rc);
6558 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
6559
6560 ret = ShowWindow(hwnd, SW_RESTORE);
6561 ok(ret, "not expected ret: %lu\n", ret);
6562 style = GetWindowLongA(hwnd, GWL_STYLE);
6563 ok(style & WS_DISABLED, "window should be disabled\n");
6564 ok(style & WS_VISIBLE, "window should be visible\n");
6565 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
6566 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
6567 GetWindowRect(hwnd, &rc);
6568 ok(EqualRect(&rcMain, &rc), "expected %s, got %s\n", wine_dbgstr_rect(&rcMain),
6569 wine_dbgstr_rect(&rc));
6570
6571 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
6572 ok(!ret, "not expected ret: %lu\n", ret);
6573 ok(IsWindow(hwnd), "window should exist\n");
6574
6575 ret = EnableWindow(hwnd, TRUE);
6576 ok(ret, "not expected ret: %lu\n", ret);
6577
6578 ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
6579 ok(!ret, "not expected ret: %lu\n", ret);
6580 ok(!IsWindow(hwnd), "window should not exist\n");
6581 }
6582
6583 static DWORD CALLBACK gettext_msg_thread( LPVOID arg )
6584 {
6585 HWND hwnd = arg;
6586 char buf[32];
6587 INT buf_len;
6588
6589 /* test GetWindowTextA */
6590 num_gettext_msgs = 0;
6591 memset( buf, 0, sizeof(buf) );
6592 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6593 ok( buf_len != 0, "expected a nonempty window text\n" );
6594 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
6595 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6596
6597 return 0;
6598 }
6599
6600 static DWORD CALLBACK settext_msg_thread( LPVOID arg )
6601 {
6602 HWND hwnd = arg;
6603 BOOL success;
6604
6605 /* test SetWindowTextA */
6606 num_settext_msgs = 0;
6607 success = SetWindowTextA( hwnd, "thread_caption" );
6608 ok( success, "SetWindowTextA failed\n" );
6609 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
6610
6611 return 0;
6612 }
6613
6614 static void test_gettext(void)
6615 {
6616 DWORD tid, num_msgs;
6617 WCHAR bufW[32];
6618 HANDLE thread;
6619 BOOL success;
6620 char buf[32];
6621 INT buf_len;
6622 HWND hwnd, hwnd2;
6623 LRESULT r;
6624 MSG msg;
6625
6626 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
6627 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
6628
6629 /* test GetWindowTextA */
6630 num_gettext_msgs = 0;
6631 memset( buf, 0, sizeof(buf) );
6632 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6633 ok( buf_len != 0, "expected a nonempty window text\n" );
6634 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
6635 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6636
6637 /* other process window */
6638 strcpy( buf, "a" );
6639 buf_len = GetWindowTextA( GetDesktopWindow(), buf, sizeof(buf) );
6640 ok( buf_len == 0, "expected a nonempty window text\n" );
6641 ok( *buf == 0, "got wrong window text '%s'\n", buf );
6642
6643 strcpy( buf, "blah" );
6644 buf_len = GetWindowTextA( GetDesktopWindow(), buf, 0 );
6645 ok( buf_len == 0, "expected a nonempty window text\n" );
6646 ok( !strcmp(buf, "blah"), "got wrong window text '%s'\n", buf );
6647
6648 bufW[0] = 0xcc;
6649 buf_len = GetWindowTextW( GetDesktopWindow(), bufW, 0 );
6650 ok( buf_len == 0, "expected a nonempty window text\n" );
6651 ok( bufW[0] == 0xcc, "got %x\n", bufW[0] );
6652
6653 g_wm_gettext_override.enabled = TRUE;
6654
6655 num_gettext_msgs = 0;
6656 memset( buf, 0xcc, sizeof(buf) );
6657 g_wm_gettext_override.buff = buf;
6658 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6659 ok( buf_len == 0, "got %d\n", buf_len );
6660 ok( *buf == 0, "got %x\n", *buf );
6661 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6662
6663 num_gettext_msgs = 0;
6664 strcpy( buf, "blah" );
6665 g_wm_gettext_override.buff = buf;
6666 buf_len = GetWindowTextA( hwnd, buf, 0 );
6667 ok( buf_len == 0, "got %d\n", buf_len );
6668 ok( !strcmp(buf, "blah"), "got %s\n", buf );
6669 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6670
6671 g_wm_gettext_override.enabled = FALSE;
6672
6673 /* same for W window */
6674 hwnd2 = CreateWindowExW( 0, mainclassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
6675 ok( hwnd2 != 0, "CreateWindowExA error %d\n", GetLastError() );
6676
6677 g_wm_gettext_override.enabled = TRUE;
6678
6679 num_gettext_msgs = 0;
6680 memset( bufW, 0xcc, sizeof(bufW) );
6681 g_wm_gettext_override.buffW = bufW;
6682 buf_len = GetWindowTextW( hwnd2, bufW, sizeof(bufW)/sizeof(WCHAR) );
6683 ok( buf_len == 0, "got %d\n", buf_len );
6684 ok( *bufW == 0, "got %x\n", *bufW );
6685 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6686
6687 num_gettext_msgs = 0;
6688 memset( bufW, 0xcc, sizeof(bufW) );
6689 g_wm_gettext_override.buffW = bufW;
6690 buf_len = GetWindowTextW( hwnd2, bufW, 0 );
6691 ok( buf_len == 0, "got %d\n", buf_len );
6692 ok( *bufW == 0xcccc, "got %x\n", *bufW );
6693 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6694
6695 g_wm_gettext_override.enabled = FALSE;
6696
6697 DestroyWindow( hwnd2 );
6698
6699 /* test WM_GETTEXT */
6700 num_gettext_msgs = 0;
6701 memset( buf, 0, sizeof(buf) );
6702 r = SendMessageA( hwnd, WM_GETTEXT, sizeof(buf), (LONG_PTR)buf );
6703 ok( r != 0, "expected a nonempty window text\n" );
6704 ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
6705 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6706
6707 /* test SetWindowTextA */
6708 num_settext_msgs = 0;
6709 success = SetWindowTextA( hwnd, "new_caption" );
6710 ok( success, "SetWindowTextA failed\n" );
6711 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
6712
6713 num_gettext_msgs = 0;
6714 memset( buf, 0, sizeof(buf) );
6715 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6716 ok( buf_len != 0, "expected a nonempty window text\n" );
6717 ok( !strcmp(buf, "new_caption"), "got wrong window text '%s'\n", buf );
6718 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6719
6720 /* test WM_SETTEXT */
6721 num_settext_msgs = 0;
6722 r = SendMessageA( hwnd, WM_SETTEXT, 0, (ULONG_PTR)"another_caption" );
6723 ok( r != 0, "WM_SETTEXT failed\n" );
6724 ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
6725
6726 num_gettext_msgs = 0;
6727 memset( buf, 0, sizeof(buf) );
6728 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6729 ok( buf_len != 0, "expected a nonempty window text\n" );
6730 ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
6731 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6732
6733 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
6734 DispatchMessageA( &msg );
6735
6736 /* test interthread GetWindowTextA */
6737 num_msgs = 0;
6738 thread = CreateThread( NULL, 0, gettext_msg_thread, hwnd, 0, &tid );
6739 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
6740 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
6741 {
6742 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
6743 DispatchMessageA( &msg );
6744 num_msgs++;
6745 }
6746 CloseHandle( thread );
6747 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
6748
6749 /* test interthread SetWindowText */
6750 num_msgs = 0;
6751 thread = CreateThread( NULL, 0, settext_msg_thread, hwnd, 0, &tid );
6752 ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
6753 while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
6754 {
6755 while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
6756 DispatchMessageA( &msg );
6757 num_msgs++;
6758 }
6759 CloseHandle( thread );
6760 ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
6761
6762 num_gettext_msgs = 0;
6763 memset( buf, 0, sizeof(buf) );
6764 buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
6765 ok( buf_len != 0, "expected a nonempty window text\n" );
6766 ok( !strcmp(buf, "thread_caption"), "got wrong window text '%s'\n", buf );
6767 ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
6768
6769 /* seems to crash on every modern Windows version */
6770 if (0)
6771 {
6772 r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
6773 ok( r == 0, "settext should return zero\n");
6774
6775 r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
6776 ok( r == 0, "settext should return zero (%ld)\n", r);
6777
6778 r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
6779 ok( r == 0, "settext should return zero (%ld)\n", r);
6780
6781 r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
6782 ok( r == 0, "settext should return zero (%ld)\n", r);
6783 }
6784
6785 DestroyWindow(hwnd);
6786 }
6787
6788
6789 static void test_GetUpdateRect(void)
6790 {
6791 MSG msg;
6792 BOOL ret, parent_wm_paint, grandparent_wm_paint;
6793 RECT rc1, rc2;
6794 HWND hgrandparent, hparent, hchild;
6795 WNDCLASSA cls;
6796 static const char classNameA[] = "GetUpdateRectClass";
6797
6798 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
6799 0, 0, 100, 100, NULL, NULL, 0, NULL);
6800
6801 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
6802 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
6803
6804 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
6805 10, 10, 30, 30, hparent, NULL, 0, NULL);
6806
6807 ShowWindow(hgrandparent, SW_SHOW);
6808 UpdateWindow(hgrandparent);
6809 flush_events( TRUE );
6810
6811 ShowWindow(hchild, SW_HIDE);
6812 SetRectEmpty(&rc2);
6813 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
6814 ok(!ret, "GetUpdateRect returned not empty region\n");
6815 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
6816 wine_dbgstr_rect(&rc2));
6817
6818 SetRect(&rc2, 10, 10, 40, 40);
6819 ret = GetUpdateRect(hparent, &rc1, FALSE);
6820 ok(ret, "GetUpdateRect returned empty region\n");
6821 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
6822 wine_dbgstr_rect(&rc2));
6823
6824 parent_wm_paint = FALSE;
6825 grandparent_wm_paint = FALSE;
6826 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6827 {
6828 if (msg.message == WM_PAINT)
6829 {
6830 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
6831 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
6832 }
6833 DispatchMessageA(&msg);
6834 }
6835 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
6836 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
6837
6838 DestroyWindow(hgrandparent);
6839
6840 cls.style = 0;
6841 cls.lpfnWndProc = DefWindowProcA;
6842 cls.cbClsExtra = 0;
6843 cls.cbWndExtra = 0;
6844 cls.hInstance = GetModuleHandleA(0);
6845 cls.hIcon = 0;
6846 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6847 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6848 cls.lpszMenuName = NULL;
6849 cls.lpszClassName = classNameA;
6850
6851 if(!RegisterClassA(&cls)) {
6852 trace("Register failed %d\n", GetLastError());
6853 return;
6854 }
6855
6856 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
6857 0, 0, 100, 100, NULL, NULL, 0, NULL);
6858
6859 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
6860 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
6861
6862 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
6863 10, 10, 30, 30, hparent, NULL, 0, NULL);
6864
6865 ShowWindow(hgrandparent, SW_SHOW);
6866 UpdateWindow(hgrandparent);
6867 flush_events( TRUE );
6868
6869 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
6870 ok(!ret, "GetUpdateRect returned not empty region\n");
6871
6872 ShowWindow(hchild, SW_HIDE);
6873
6874 SetRectEmpty(&rc2);
6875 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
6876 ok(!ret, "GetUpdateRect returned not empty region\n");
6877 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
6878 wine_dbgstr_rect(&rc2));
6879
6880 SetRect(&rc2, 10, 10, 40, 40);
6881 ret = GetUpdateRect(hparent, &rc1, FALSE);
6882 ok(ret, "GetUpdateRect returned empty region\n");
6883 ok(EqualRect(&rc1, &rc2), "rects do not match %s / %s\n", wine_dbgstr_rect(&rc1),
6884 wine_dbgstr_rect(&rc2));
6885
6886 parent_wm_paint = FALSE;
6887 grandparent_wm_paint = FALSE;
6888 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
6889 {
6890 if (msg.message == WM_PAINT)
6891 {
6892 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
6893 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
6894 }
6895 DispatchMessageA(&msg);
6896 }
6897 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
6898 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
6899
6900 DestroyWindow(hgrandparent);
6901 }
6902
6903
6904 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6905 {
6906 if(msg == WM_PAINT)
6907 {
6908 PAINTSTRUCT ps;
6909 RECT updateRect;
6910 DWORD waitResult;
6911 HWND win;
6912 const int waitTime = 2000;
6913
6914 BeginPaint(hwnd, &ps);
6915
6916 /* create and destroy window to create an exposed region on this window */
6917 win = CreateWindowA("static", "win", WS_VISIBLE,
6918 10,10,50,50, NULL, NULL, 0, NULL);
6919 DestroyWindow(win);
6920
6921 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
6922
6923 ValidateRect(hwnd, NULL);
6924 EndPaint(hwnd, &ps);
6925
6926 if(waitResult != WAIT_TIMEOUT)
6927 {
6928 GetUpdateRect(hwnd, &updateRect, FALSE);
6929 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
6930 }
6931
6932 return 1;
6933 }
6934 return DefWindowProcA(hwnd, msg, wParam, lParam);
6935 }
6936
6937 static void test_Expose(void)
6938 {
6939 WNDCLASSA cls;
6940 HWND mw;
6941
6942 memset(&cls, 0, sizeof(WNDCLASSA));
6943 cls.lpfnWndProc = TestExposedRegion_WndProc;
6944 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
6945 cls.lpszClassName = "TestExposeClass";
6946 RegisterClassA(&cls);
6947
6948 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
6949 0, 0, 200, 100, NULL, NULL, 0, NULL);
6950
6951 UpdateWindow(mw);
6952 DestroyWindow(mw);
6953 }
6954
6955 static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
6956 {
6957 static UINT ncredrawflags;
6958 PAINTSTRUCT ps;
6959
6960 switch(msg)
6961 {
6962 case WM_CREATE:
6963 ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
6964 return 0;
6965 case WM_NCPAINT:
6966 RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
6967 break;
6968 case WM_PAINT:
6969 BeginPaint(hwnd, &ps);
6970 EndPaint(hwnd, &ps);
6971 return 0;
6972 }
6973 return DefWindowProcA(hwnd, msg, wParam, lParam);
6974 }
6975
6976 static void run_NCRedrawLoop(UINT flags)
6977 {
6978 HWND hwnd;
6979 MSG msg;
6980
6981 UINT loopcount = 0;
6982
6983 hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
6984 WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
6985 NULL, NULL, 0, &flags);
6986 ShowWindow(hwnd, SW_SHOW);
6987 UpdateWindow(hwnd);
6988 flush_events( FALSE );
6989 while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
6990 {
6991 if (msg.message == WM_PAINT) loopcount++;
6992 if (loopcount >= 100) break;
6993 TranslateMessage(&msg);
6994 DispatchMessageA(&msg);
6995 MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
6996 }
6997 todo_wine_if (flags == (RDW_INVALIDATE | RDW_FRAME))
6998 ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
6999 DestroyWindow(hwnd);
7000 }
7001
7002 static void test_NCRedraw(void)
7003 {
7004 WNDCLASSA wndclass;
7005
7006 wndclass.lpszClassName = "TestNCRedrawClass";
7007 wndclass.style = CS_HREDRAW | CS_VREDRAW;
7008 wndclass.lpfnWndProc = TestNCRedraw_WndProc;
7009 wndclass.cbClsExtra = 0;
7010 wndclass.cbWndExtra = 0;
7011 wndclass.hInstance = 0;
7012 wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
7013 wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7014 wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
7015 wndclass.lpszMenuName = NULL;
7016
7017 RegisterClassA(&wndclass);
7018
7019 run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
7020 run_NCRedrawLoop(RDW_INVALIDATE);
7021 }
7022
7023 static void test_GetWindowModuleFileName(void)
7024 {
7025 HWND hwnd;
7026 HINSTANCE hinst;
7027 UINT ret1, ret2;
7028 char buf1[MAX_PATH], buf2[MAX_PATH];
7029
7030 if (!pGetWindowModuleFileNameA)
7031 {
7032 win_skip("GetWindowModuleFileNameA is not available\n");
7033 return;
7034 }
7035
7036 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
7037 assert(hwnd);
7038
7039 hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
7040 ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
7041
7042 buf1[0] = 0;
7043 SetLastError(0xdeadbeef);
7044 ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
7045 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
7046
7047 buf2[0] = 0;
7048 SetLastError(0xdeadbeef);
7049 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
7050 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
7051 "GetWindowModuleFileNameA error %u\n", GetLastError());
7052
7053 if (ret2)
7054 {
7055 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
7056 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
7057 }
7058 hinst = GetModuleHandleA(NULL);
7059
7060 SetLastError(0xdeadbeef);
7061 ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
7062 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
7063 "expected %u, got %u\n", ret1 - 2, ret2);
7064 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7065 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7066 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7067
7068 SetLastError(0xdeadbeef);
7069 ret2 = GetModuleFileNameA(hinst, buf2, 0);
7070 ok(!ret2, "GetModuleFileName should return 0\n");
7071 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7072 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7073 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7074
7075 SetLastError(0xdeadbeef);
7076 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
7077 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
7078 "expected %u, got %u\n", ret1 - 2, ret2);
7079 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7080 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7081 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7082
7083 SetLastError(0xdeadbeef);
7084 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
7085 ok(!ret2, "expected 0, got %u\n", ret2);
7086 ok(GetLastError() == 0xdeadbeef /* XP */ ||
7087 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
7088 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
7089
7090 DestroyWindow(hwnd);
7091
7092 buf2[0] = 0;
7093 hwnd = (HWND)0xdeadbeef;
7094 SetLastError(0xdeadbeef);
7095 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
7096 ok(!ret1, "expected 0, got %u\n", ret1);
7097 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
7098 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
7099
7100 hwnd = FindWindowA("Shell_TrayWnd", NULL);
7101 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
7102 SetLastError(0xdeadbeef);
7103 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
7104 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
7105
7106 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
7107 {
7108 ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
7109 hwnd = GetDesktopWindow();
7110 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
7111 SetLastError(0xdeadbeef);
7112 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
7113 ok(!ret2 ||
7114 ret1 == ret2 || /* vista */
7115 broken(ret2), /* some win98 return user.exe as file name */
7116 "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
7117 }
7118 }
7119
7120 static void test_hwnd_message(void)
7121 {
7122 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
7123 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
7124
7125 HWND parent = 0, hwnd, found;
7126 RECT rect;
7127
7128 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
7129 on CreateWindowExA and crash later in the test.
7130 Use UNICODE here to fail on win9x */
7131 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
7132 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
7133 if (!hwnd)
7134 {
7135 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
7136 return;
7137 }
7138
7139 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
7140 if (pGetAncestor)
7141 {
7142 char buffer[100];
7143 HWND root, desktop = GetDesktopWindow();
7144
7145 parent = pGetAncestor(hwnd, GA_PARENT);
7146 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
7147 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
7148 root = pGetAncestor(hwnd, GA_ROOT);
7149 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
7150 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
7151 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
7152 trace("parent %p root %p desktop %p\n", parent, root, desktop);
7153 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
7154 ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
7155 GetWindowRect( parent, &rect );
7156 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
7157 "wrong parent rect %s\n", wine_dbgstr_rect( &rect ));
7158 }
7159 GetWindowRect( hwnd, &rect );
7160 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
7161 "wrong window rect %s\n", wine_dbgstr_rect( &rect ));
7162
7163 /* test FindWindow behavior */
7164
7165 found = FindWindowExA( 0, 0, 0, "message window" );
7166 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
7167 SetLastError(0xdeadbeef);
7168 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
7169 ok( found == 0, "found message window %p/%p\n", found, hwnd );
7170 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
7171 if (parent)
7172 {
7173 found = FindWindowExA( parent, 0, 0, "message window" );
7174 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
7175 }
7176
7177 /* test IsChild behavior */
7178
7179 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
7180
7181 /* test IsWindowVisible behavior */
7182
7183 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
7184 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
7185
7186 DestroyWindow(hwnd);
7187 }
7188
7189 static void test_layered_window(void)
7190 {
7191 HWND hwnd;
7192 COLORREF key = 0;
7193 BYTE alpha = 0;
7194 DWORD flags = 0;
7195 POINT pt = { 0, 0 };
7196 SIZE sz = { 200, 200 };
7197 HDC hdc;
7198 HBITMAP hbm;
7199 BOOL ret;
7200
7201 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
7202 {
7203 win_skip( "layered windows not supported\n" );
7204 return;
7205 }
7206
7207 hdc = CreateCompatibleDC( 0 );
7208 hbm = CreateCompatibleBitmap( hdc, 200, 200 );
7209 SelectObject( hdc, hbm );
7210
7211 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
7212 100, 100, 200, 200, 0, 0, 0, NULL);
7213 assert( hwnd );
7214 SetLastError( 0xdeadbeef );
7215 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7216 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
7217 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7218 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7219 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
7220 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
7221 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
7222 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7223 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7224 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7225 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7226 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
7227 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7228 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7229 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
7230 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7231 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7232 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7233 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
7234 ok( alpha == 44, "wrong alpha %u\n", alpha );
7235 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
7236 SetLastError( 0xdeadbeef );
7237 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7238 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7239 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7240
7241 /* clearing WS_EX_LAYERED resets attributes */
7242 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7243 SetLastError( 0xdeadbeef );
7244 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7245 ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
7246 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7247 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
7248 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7249 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7250 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
7251 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7252 ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
7253 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE | ULW_EX_NORESIZE );
7254 ok( !ret, "UpdateLayeredWindow should fail with ex flag\n" );
7255 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7256 if (pUpdateLayeredWindowIndirect)
7257 {
7258 UPDATELAYEREDWINDOWINFO info;
7259 info.cbSize = sizeof(info);
7260 info.hdcDst = 0;
7261 info.pptDst = NULL;
7262 info.psize = &sz;
7263 info.hdcSrc = hdc;
7264 info.pptSrc = &pt;
7265 info.crKey = 0;
7266 info.pblend = NULL;
7267 info.dwFlags = ULW_OPAQUE | ULW_EX_NORESIZE;
7268 info.prcDirty = NULL;
7269 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7270 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7271 sz.cx--;
7272 SetLastError(0);
7273 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7274 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7275 /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
7276 ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
7277 ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
7278 info.dwFlags = ULW_OPAQUE;
7279 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7280 ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
7281 sz.cx++;
7282 info.dwFlags = ULW_OPAQUE | 0xf00;
7283 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7284 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7285 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7286 info.cbSize--;
7287 info.dwFlags = ULW_OPAQUE;
7288 ret = pUpdateLayeredWindowIndirect( hwnd, &info );
7289 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7290 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7291 ret = pUpdateLayeredWindowIndirect( hwnd, NULL );
7292 ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
7293 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
7294 }
7295
7296 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
7297 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7298 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7299 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7300 ok( key == 0x654321, "wrong color key %x\n", key );
7301 ok( alpha == 22, "wrong alpha %u\n", alpha );
7302 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
7303 SetLastError( 0xdeadbeef );
7304 ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
7305 ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
7306 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
7307
7308 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
7309 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7310 alpha = 0;
7311 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7312 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7313 ok( key == 0x888888, "wrong color key %x\n", key );
7314 /* alpha not changed on vista if LWA_ALPHA is not set */
7315 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
7316 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
7317
7318 /* color key may or may not be changed without LWA_COLORKEY */
7319 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
7320 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7321 alpha = 0;
7322 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7323 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7324 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
7325 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
7326 ok( flags == 0, "wrong flags %x\n", flags );
7327
7328 /* default alpha and color key is 0 */
7329 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
7330 SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
7331 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
7332 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
7333 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
7334 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
7335 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
7336 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
7337 ok( flags == 0, "wrong flags %x\n", flags );
7338
7339 DestroyWindow( hwnd );
7340 DeleteDC( hdc );
7341 DeleteObject( hbm );
7342 }
7343
7344 static MONITORINFO mi;
7345
7346 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
7347 {
7348 switch (msg)
7349 {
7350 case WM_NCCREATE:
7351 {
7352 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
7353 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
7354 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
7355 "expected %s, got (%d,%d)-(%d,%d)\n", wine_dbgstr_rect(&mi.rcMonitor),
7356 cs->x, cs->y, cs->cx, cs->cy);
7357 break;
7358 }
7359 case WM_GETMINMAXINFO:
7360 {
7361 MINMAXINFO *minmax = (MINMAXINFO *)lp;
7362 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
7363 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
7364 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
7365 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
7366 break;
7367 }
7368 }
7369 return DefWindowProcA(hwnd, msg, wp, lp);
7370 }
7371
7372 static void test_fullscreen(void)
7373 {
7374 static const DWORD t_style[] = {
7375 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
7376 };
7377 static const DWORD t_ex_style[] = {
7378 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
7379 };
7380 WNDCLASSA cls;
7381 HWND hwnd;
7382 int i, j;
7383 POINT pt;
7384 RECT rc;
7385 HMONITOR hmon;
7386 LRESULT ret;
7387
7388 if (!pGetMonitorInfoA || !pMonitorFromPoint)
7389 {
7390 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
7391 return;
7392 }
7393
7394 pt.x = pt.y = 0;
7395 SetLastError(0xdeadbeef);
7396 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
7397 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
7398
7399 mi.cbSize = sizeof(mi);
7400 SetLastError(0xdeadbeef);
7401 ret = pGetMonitorInfoA(hmon, &mi);
7402 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
7403 trace("monitor %s, work %s\n", wine_dbgstr_rect(&mi.rcMonitor), wine_dbgstr_rect(&mi.rcWork));
7404
7405 cls.style = 0;
7406 cls.lpfnWndProc = fullscreen_wnd_proc;
7407 cls.cbClsExtra = 0;
7408 cls.cbWndExtra = 0;
7409 cls.hInstance = GetModuleHandleA(NULL);
7410 cls.hIcon = 0;
7411 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7412 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7413 cls.lpszMenuName = NULL;
7414 cls.lpszClassName = "fullscreen_class";
7415 RegisterClassA(&cls);
7416
7417 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
7418 {
7419 DWORD style, ex_style;
7420
7421 /* avoid a WM interaction */
7422 assert(!(t_style[i] & WS_VISIBLE));
7423
7424 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
7425 {
7426 int fixup;
7427
7428 style = t_style[i];
7429 ex_style = t_ex_style[j];
7430
7431 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7432 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7433 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7434 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7435 GetWindowRect(hwnd, &rc);
7436 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7437 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7438 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7439 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7440 DestroyWindow(hwnd);
7441
7442 style = t_style[i] | WS_MAXIMIZE;
7443 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7444 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7445 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7446 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7447 GetWindowRect(hwnd, &rc);
7448 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7449 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7450 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7451 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7452 DestroyWindow(hwnd);
7453
7454 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
7455 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7456 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7457 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7458 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7459 GetWindowRect(hwnd, &rc);
7460 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7461 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7462 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7463 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7464 DestroyWindow(hwnd);
7465
7466 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
7467 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7468 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7469 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7470 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7471 GetWindowRect(hwnd, &rc);
7472 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7473 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7474 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7475 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7476 DestroyWindow(hwnd);
7477
7478 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
7479 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7480 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7481 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7482 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7483 GetWindowRect(hwnd, &rc);
7484 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7485 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7486 fixup = min(abs(rc.left), abs(rc.top));
7487 InflateRect(&rc, -fixup, -fixup);
7488 ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
7489 rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
7490 "%#x/%#x: window rect %s must be in %s\n", ex_style, style, wine_dbgstr_rect(&rc),
7491 wine_dbgstr_rect(&mi.rcMonitor));
7492 DestroyWindow(hwnd);
7493
7494 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
7495 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
7496 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
7497 GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
7498 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
7499 GetWindowRect(hwnd, &rc);
7500 trace("%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7501 /* Windows makes a maximized window slightly larger (to hide the borders?) */
7502 fixup = min(abs(rc.left), abs(rc.top));
7503 InflateRect(&rc, -fixup, -fixup);
7504 if (style & (WS_CHILD | WS_POPUP))
7505 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
7506 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
7507 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7508 else
7509 ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
7510 rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
7511 "%#x/%#x: window rect %s\n", ex_style, style, wine_dbgstr_rect(&rc));
7512 DestroyWindow(hwnd);
7513 }
7514 }
7515
7516 UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
7517 }
7518
7519 static BOOL test_thick_child_got_minmax;
7520 static const char * test_thick_child_name;
7521 static LONG test_thick_child_style;
7522 static LONG test_thick_child_exStyle;
7523
7524 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
7525 {
7526 MINMAXINFO* minmax;
7527 int expectedMinTrackX;
7528 int expectedMinTrackY;
7529 int actualMinTrackX;
7530 int actualMinTrackY;
7531 int expectedMaxTrackX;
7532 int expectedMaxTrackY;
7533 int actualMaxTrackX;
7534 int actualMaxTrackY;
7535 int expectedMaxSizeX;
7536 int expectedMaxSizeY;
7537 int actualMaxSizeX;
7538 int actualMaxSizeY;
7539 int expectedPosX;
7540 int expectedPosY;
7541 int actualPosX;
7542 int actualPosY;
7543 LONG adjustedStyle;
7544 RECT rect;
7545 switch (msg)
7546 {
7547 case WM_GETMINMAXINFO:
7548 {
7549 minmax = (MINMAXINFO *)lparam;
7550 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
7551 dump_minmax_info( minmax );
7552
7553 test_thick_child_got_minmax = TRUE;
7554
7555
7556 adjustedStyle = test_thick_child_style;
7557 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
7558 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
7559 GetClientRect(GetParent(hwnd), &rect);
7560 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
7561
7562 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
7563 {
7564 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
7565 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
7566 }
7567 else
7568 {
7569 expectedMinTrackX = -2 * rect.left;
7570 expectedMinTrackY = -2 * rect.top;
7571 }
7572 actualMinTrackX = minmax->ptMinTrackSize.x;
7573 actualMinTrackY = minmax->ptMinTrackSize.y;
7574
7575 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
7576 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
7577 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
7578 test_thick_child_name);
7579
7580 actualMaxTrackX = minmax->ptMaxTrackSize.x;
7581 actualMaxTrackY = minmax->ptMaxTrackSize.y;
7582 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
7583 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
7584 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
7585 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
7586 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
7587 test_thick_child_name);
7588
7589 expectedMaxSizeX = rect.right - rect.left;
7590 expectedMaxSizeY = rect.bottom - rect.top;
7591 actualMaxSizeX = minmax->ptMaxSize.x;
7592 actualMaxSizeY = minmax->ptMaxSize.y;
7593
7594 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
7595 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
7596 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
7597 test_thick_child_name);
7598
7599
7600 expectedPosX = rect.left;
7601 expectedPosY = rect.top;
7602 actualPosX = minmax->ptMaxPosition.x;
7603 actualPosY = minmax->ptMaxPosition.y;
7604 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
7605 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
7606 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
7607
7608 break;
7609 }
7610 }
7611
7612 return DefWindowProcA(hwnd, msg, wparam, lparam);
7613 }
7614
7615 #define NUMBER_OF_THICK_CHILD_TESTS 16
7616 static void test_thick_child_size(HWND parentWindow)
7617 {
7618 BOOL success;
7619 RECT childRect;
7620 RECT adjustedParentRect;
7621 HWND childWindow;
7622 LONG childWidth;
7623 LONG childHeight;
7624 LONG expectedWidth;
7625 LONG expectedHeight;
7626 WNDCLASSA cls;
7627 static const char className[] = "THICK_CHILD_CLASS";
7628 int i;
7629 LONG adjustedStyle;
7630 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
7631 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
7632 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
7633 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
7634 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
7635 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
7636 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
7637 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
7638 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
7639 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
7640 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
7641 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
7642 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
7643 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
7644 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
7645 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
7646 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
7647 };
7648
7649 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
7650 0,
7651 0,
7652 0,
7653 0,
7654 WS_EX_DLGMODALFRAME,
7655 WS_EX_DLGMODALFRAME,
7656 WS_EX_DLGMODALFRAME,
7657 WS_EX_DLGMODALFRAME,
7658 WS_EX_STATICEDGE,
7659 WS_EX_STATICEDGE,
7660 WS_EX_STATICEDGE,
7661 WS_EX_STATICEDGE,
7662 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
7663 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
7664 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
7665 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
7666 };
7667 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
7668 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
7669 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
7670 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
7671 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
7672 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
7673 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
7674 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
7675 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
7676 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
7677 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
7678 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
7679 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
7680 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7681 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7682 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7683 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
7684 };
7685
7686 cls.style = 0;
7687 cls.lpfnWndProc = test_thick_child_size_winproc;
7688 cls.cbClsExtra = 0;
7689 cls.cbWndExtra = 0;
7690 cls.hInstance = GetModuleHandleA(0);
7691 cls.hIcon = 0;
7692 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
7693 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
7694 cls.lpszMenuName = NULL;
7695 cls.lpszClassName = className;
7696 SetLastError(0xdeadbeef);
7697 success = RegisterClassA(&cls);
7698 ok(success,"RegisterClassA failed, error: %u\n", GetLastError());
7699
7700 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
7701 {
7702 test_thick_child_name = styleName[i];
7703 test_thick_child_style = styles[i];
7704 test_thick_child_exStyle = exStyles[i];
7705 test_thick_child_got_minmax = FALSE;
7706
7707 SetLastError(0xdeadbeef);
7708 childWindow = CreateWindowExA( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
7709 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
7710
7711 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
7712
7713 SetLastError(0xdeadbeef);
7714 success = GetWindowRect(childWindow, &childRect);
7715 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
7716 childWidth = childRect.right - childRect.left;
7717 childHeight = childRect.bottom - childRect.top;
7718
7719 adjustedStyle = styles[i];
7720 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
7721 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
7722 GetClientRect(GetParent(childWindow), &adjustedParentRect);
7723 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
7724
7725
7726 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
7727 {
7728 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
7729 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
7730 }
7731 else
7732 {
7733 expectedWidth = -2 * adjustedParentRect.left;
7734 expectedHeight = -2 * adjustedParentRect.top;
7735 }
7736
7737 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
7738 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
7739 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
7740
7741 SetLastError(0xdeadbeef);
7742 success = DestroyWindow(childWindow);
7743 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
7744 }
7745 ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
7746 }
7747
7748 static void test_handles( HWND full_hwnd )
7749 {
7750 HWND hwnd = full_hwnd;
7751 BOOL ret;
7752 RECT rect;
7753
7754 SetLastError( 0xdeadbeef );
7755 ret = GetWindowRect( hwnd, &rect );
7756 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
7757
7758 #ifdef _WIN64
7759 if ((ULONG_PTR)full_hwnd >> 32)
7760 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
7761 else
7762 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
7763 SetLastError( 0xdeadbeef );
7764 ret = GetWindowRect( hwnd, &rect );
7765 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
7766
7767 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
7768 SetLastError( 0xdeadbeef );
7769 ret = GetWindowRect( hwnd, &rect );
7770 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
7771
7772 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
7773 SetLastError( 0xdeadbeef );
7774 ret = GetWindowRect( hwnd, &rect );
7775 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
7776 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
7777
7778 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
7779 SetLastError( 0xdeadbeef );
7780 ret = GetWindowRect( hwnd, &rect );
7781 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
7782 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
7783 #endif
7784 }
7785
7786 static void test_winregion(void)
7787 {
7788 HWND hwnd;
7789 RECT r;
7790 int ret, width;
7791 HRGN hrgn;
7792
7793 if (!pGetWindowRgnBox)
7794 {
7795 win_skip("GetWindowRgnBox not supported\n");
7796 return;
7797 }
7798
7799 hwnd = CreateWindowExA(0, "static", NULL, WS_VISIBLE, 10, 10, 10, 10, NULL, 0, 0, NULL);
7800 /* NULL prect */
7801 SetLastError(0xdeadbeef);
7802 ret = pGetWindowRgnBox(hwnd, NULL);
7803 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
7804 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7805
7806 hrgn = CreateRectRgn(2, 3, 10, 15);
7807 ok( hrgn != NULL, "Region creation failed\n");
7808 if (hrgn)
7809 {
7810 SetWindowRgn(hwnd, hrgn, FALSE);
7811
7812 SetLastError(0xdeadbeef);
7813 ret = pGetWindowRgnBox(hwnd, NULL);
7814 ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
7815 ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
7816
7817 SetRectEmpty(&r);
7818 ret = pGetWindowRgnBox(hwnd, &r);
7819 ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
7820 ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
7821 "Expected (2,3)-(10,15), got %s\n", wine_dbgstr_rect( &r ));
7822 if (pMirrorRgn)
7823 {
7824 hrgn = CreateRectRgn(2, 3, 10, 15);
7825 ret = pMirrorRgn( hwnd, hrgn );
7826 ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
7827 SetRectEmpty(&r);
7828 GetWindowRect( hwnd, &r );
7829 width = r.right - r.left;
7830 SetRectEmpty(&r);
7831 ret = GetRgnBox( hrgn, &r );
7832 ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
7833 ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
7834 "Wrong rectangle %s for width %d\n", wine_dbgstr_rect( &r ), width );
7835 }
7836 else win_skip( "MirrorRgn not supported\n" );
7837 }
7838 DestroyWindow(hwnd);
7839 }
7840
7841 static void test_rtl_layout(void)
7842 {
7843 HWND parent, child;
7844 RECT r;
7845 POINT pt;
7846
7847 if (!pSetProcessDefaultLayout)
7848 {
7849 win_skip( "SetProcessDefaultLayout not supported\n" );
7850 return;
7851 }
7852
7853 parent = CreateWindowExA(WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP, 100, 100, 300, 300, NULL, 0, 0, NULL);
7854 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 10, 10, 20, 20, parent, 0, 0, NULL);
7855
7856 GetWindowRect( parent, &r );
7857 ok( r.left == 100 && r.right == 400, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7858 GetClientRect( parent, &r );
7859 ok( r.left == 0 && r.right == 300, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7860 GetClientRect( child, &r );
7861 ok( r.left == 0 && r.right == 20, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7862 MapWindowPoints( child, parent, (POINT *)&r, 2 );
7863 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7864 GetWindowRect( child, &r );
7865 ok( r.left == 370 && r.right == 390, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7866 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7867 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7868 GetWindowRect( child, &r );
7869 MapWindowPoints( NULL, parent, (POINT *)&r, 1 );
7870 MapWindowPoints( NULL, parent, (POINT *)&r + 1, 1 );
7871 ok( r.left == 30 && r.right == 10, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7872 pt.x = pt.y = 12;
7873 MapWindowPoints( child, parent, &pt, 1 );
7874 ok( pt.x == 22 && pt.y == 22, "wrong point %d,%d\n", pt.x, pt.y );
7875 SetWindowPos( parent, 0, 0, 0, 250, 250, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
7876 GetWindowRect( parent, &r );
7877 ok( r.left == 100 && r.right == 350, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7878 GetWindowRect( child, &r );
7879 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7880 SetWindowLongW( parent, GWL_EXSTYLE, 0 );
7881 GetWindowRect( child, &r );
7882 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7883 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7884 ok( r.left == 220 && r.right == 240, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7885 SetWindowLongW( parent, GWL_EXSTYLE, WS_EX_LAYOUTRTL );
7886 GetWindowRect( child, &r );
7887 ok( r.left == 320 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7888 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7889 ok( r.left == 10 && r.right == 30, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7890 SetWindowPos( child, 0, 0, 0, 30, 30, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE );
7891 GetWindowRect( child, &r );
7892 ok( r.left == 310 && r.right == 340, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7893 MapWindowPoints( NULL, parent, (POINT *)&r, 2 );
7894 ok( r.left == 10 && r.right == 40, "wrong rect %s\n", wine_dbgstr_rect( &r ));
7895 DestroyWindow( child );
7896 DestroyWindow( parent );
7897 }
7898
7899 static void test_FlashWindow(void)
7900 {
7901 HWND hwnd;
7902 BOOL ret;
7903 if (!pFlashWindow)
7904 {
7905 win_skip( "FlashWindow not supported\n" );
7906 return;
7907 }
7908
7909 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
7910 0, 0, 0, 0, 0, 0, 0, NULL );
7911 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7912
7913 SetLastError( 0xdeadbeef );
7914 ret = pFlashWindow( NULL, TRUE );
7915 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
7916 "FlashWindow returned with %d\n", GetLastError() );
7917
7918 DestroyWindow( hwnd );
7919
7920 SetLastError( 0xdeadbeef );
7921 ret = pFlashWindow( hwnd, TRUE );
7922 ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
7923 "FlashWindow returned with %d\n", GetLastError() );
7924 }
7925
7926 static void test_FlashWindowEx(void)
7927 {
7928 HWND hwnd;
7929 FLASHWINFO finfo;
7930 BOOL prev, ret;
7931
7932 if (!pFlashWindowEx)
7933 {
7934 win_skip( "FlashWindowEx not supported\n" );
7935 return;
7936 }
7937
7938 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
7939 0, 0, 0, 0, 0, 0, 0, NULL );
7940 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7941
7942 finfo.cbSize = sizeof(FLASHWINFO);
7943 finfo.dwFlags = FLASHW_TIMER;
7944 finfo.uCount = 3;
7945 finfo.dwTimeout = 200;
7946 finfo.hwnd = NULL;
7947 SetLastError(0xdeadbeef);
7948 ret = pFlashWindowEx(&finfo);
7949 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7950 "FlashWindowEx returned with %d\n", GetLastError());
7951
7952 finfo.hwnd = hwnd;
7953 SetLastError(0xdeadbeef);
7954 ret = pFlashWindowEx(NULL);
7955 ok(!ret && GetLastError() == ERROR_NOACCESS,
7956 "FlashWindowEx returned with %d\n", GetLastError());
7957
7958 SetLastError(0xdeadbeef);
7959 ret = pFlashWindowEx(&finfo);
7960 todo_wine ok(!ret, "previous window state should not be active\n");
7961
7962 finfo.cbSize = sizeof(FLASHWINFO) - 1;
7963 SetLastError(0xdeadbeef);
7964 ret = pFlashWindowEx(&finfo);
7965 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7966 "FlashWindowEx succeeded\n");
7967
7968 finfo.cbSize = sizeof(FLASHWINFO) + 1;
7969 SetLastError(0xdeadbeef);
7970 ret = pFlashWindowEx(&finfo);
7971 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7972 "FlashWindowEx succeeded\n");
7973 finfo.cbSize = sizeof(FLASHWINFO);
7974
7975 DestroyWindow( hwnd );
7976
7977 SetLastError(0xdeadbeef);
7978 ret = pFlashWindowEx(&finfo);
7979 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
7980 "FlashWindowEx returned with %d\n", GetLastError());
7981
7982 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
7983 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
7984 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
7985 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
7986 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
7987
7988 hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_VISIBLE | WS_POPUPWINDOW,
7989 0, 0, 0, 0, 0, 0, 0, NULL );
7990 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
7991 finfo.hwnd = hwnd;
7992
7993 SetLastError(0xdeadbeef);
7994 ret = pFlashWindowEx(NULL);
7995 ok(!ret && GetLastError() == ERROR_NOACCESS,
7996 "FlashWindowEx returned with %d\n", GetLastError());
7997
7998 SetLastError(0xdeadbeef);
7999 prev = pFlashWindowEx(&finfo);
8000
8001 ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
8002 ok(finfo.hwnd == hwnd, "FlashWindowEx modified hwnd to %p\n", finfo.hwnd);
8003 ok(finfo.dwFlags == FLASHW_TIMER, "FlashWindowEx modified dwFlags to %x\n", finfo.dwFlags);
8004 ok(finfo.uCount == 3, "FlashWindowEx modified uCount to %x\n", finfo.uCount);
8005 ok(finfo.dwTimeout == 200, "FlashWindowEx modified dwTimeout to %x\n", finfo.dwTimeout);
8006
8007 finfo.dwFlags = FLASHW_STOP;
8008 SetLastError(0xdeadbeef);
8009 ret = pFlashWindowEx(&finfo);
8010 ok(prev != ret, "previous window state should be different\n");
8011
8012 DestroyWindow( hwnd );
8013 }
8014
8015 static void test_FindWindowEx(void)
8016 {
8017 HWND hwnd, found;
8018
8019 hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8020 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8021
8022 num_gettext_msgs = 0;
8023 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
8024 ok( found == NULL, "expected a NULL hwnd\n" );
8025 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8026
8027 num_gettext_msgs = 0;
8028 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
8029 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8030 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8031
8032 num_gettext_msgs = 0;
8033 found = FindWindowExA( 0, 0, "MainWindowClass", "caption" );
8034 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8035 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8036
8037 DestroyWindow( hwnd );
8038
8039 hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
8040 ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
8041
8042 num_gettext_msgs = 0;
8043 found = FindWindowExA( 0, 0, "MainWindowClass", "" );
8044 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8045 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8046
8047 num_gettext_msgs = 0;
8048 found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
8049 ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
8050 ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
8051
8052 DestroyWindow( hwnd );
8053
8054 /* test behaviour with a window title that is an empty character */
8055 found = FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
8056 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8057 found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
8058 ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
8059 }
8060
8061 static void test_GetLastActivePopup(void)
8062 {
8063 HWND hwndOwner, hwndPopup1, hwndPopup2;
8064
8065 hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
8066 WS_VISIBLE | WS_POPUPWINDOW,
8067 100, 100, 200, 200,
8068 NULL, 0, GetModuleHandleA(NULL), NULL);
8069 hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
8070 WS_VISIBLE | WS_POPUPWINDOW,
8071 100, 100, 200, 200,
8072 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
8073 hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
8074 WS_VISIBLE | WS_POPUPWINDOW,
8075 100, 100, 200, 200,
8076 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
8077 ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
8078 DestroyWindow( hwndPopup2 );
8079 DestroyWindow( hwndPopup1 );
8080 DestroyWindow( hwndOwner );
8081 }
8082
8083 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8084 {
8085 if (msg == WM_NCHITTEST) return HTTRANSPARENT;
8086 return DefWindowProcA(hwnd, msg, wp, lp);
8087 }
8088
8089 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8090 {
8091 return DefWindowProcA(hwnd, msg, wp, lp);
8092 }
8093
8094 static void create_window_tree(HWND parent, HWND *window, int size)
8095 {
8096 static const DWORD style[] = { 0, WS_VISIBLE, WS_DISABLED, WS_VISIBLE | WS_DISABLED };
8097 int i, pos;
8098
8099 memset(window, 0, size * sizeof(window[0]));
8100
8101 pos = 0;
8102 for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
8103 {
8104 assert(pos < size);
8105 window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
8106 0, 0, 100, 100, parent, 0, 0, NULL);
8107 ok(window[pos] != 0, "CreateWindowEx failed\n");
8108 pos++;
8109 assert(pos < size);
8110 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
8111 0, 0, 100, 100, parent, 0, 0, NULL);
8112 ok(window[pos] != 0, "CreateWindowEx failed\n");
8113 pos++;
8114
8115 assert(pos < size);
8116 window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
8117 0, 0, 100, 100, parent, 0, 0, NULL);
8118 ok(window[pos] != 0, "CreateWindowEx failed\n");
8119 pos++;
8120 assert(pos < size);
8121 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
8122 0, 0, 100, 100, parent, 0, 0, NULL);
8123 ok(window[pos] != 0, "CreateWindowEx failed\n");
8124 pos++;
8125
8126 assert(pos < size);
8127 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8128 0, 0, 100, 100, parent, 0, 0, NULL);
8129 ok(window[pos] != 0, "CreateWindowEx failed\n");
8130 pos++;
8131 assert(pos < size);
8132 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8133 0, 0, 100, 100, parent, 0, 0, NULL);
8134 ok(window[pos] != 0, "CreateWindowEx failed\n");
8135 pos++;
8136 assert(pos < size);
8137 window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8138 0, 0, 100, 100, parent, 0, 0, NULL);
8139 ok(window[pos] != 0, "CreateWindowEx failed\n");
8140 pos++;
8141 assert(pos < size);
8142 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8143 0, 0, 100, 100, parent, 0, 0, NULL);
8144 ok(window[pos] != 0, "CreateWindowEx failed\n");
8145 pos++;
8146
8147 assert(pos < size);
8148 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8149 0, 0, 100, 100, parent, 0, 0, NULL);
8150 ok(window[pos] != 0, "CreateWindowEx failed\n");
8151 pos++;
8152 assert(pos < size);
8153 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
8154 0, 0, 100, 100, parent, 0, 0, NULL);
8155 ok(window[pos] != 0, "CreateWindowEx failed\n");
8156 pos++;
8157 assert(pos < size);
8158 window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8159 0, 0, 100, 100, parent, 0, 0, NULL);
8160 ok(window[pos] != 0, "CreateWindowEx failed\n");
8161 pos++;
8162 assert(pos < size);
8163 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
8164 0, 0, 100, 100, parent, 0, 0, NULL);
8165 ok(window[pos] != 0, "CreateWindowEx failed\n");
8166 pos++;
8167
8168 assert(pos < size);
8169 window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
8170 0, 0, 100, 100, parent, 0, 0, NULL);
8171 ok(window[pos] != 0, "CreateWindowEx failed\n");
8172 pos++;
8173 assert(pos < size);
8174 window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
8175 0, 0, 100, 100, parent, 0, 0, NULL);
8176 ok(window[pos] != 0, "CreateWindowEx failed\n");
8177 pos++;
8178 }
8179 }
8180
8181 struct window_attributes
8182 {
8183 char class_name[128];
8184 BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
8185 };
8186
8187 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
8188 {
8189 DWORD style, ex_style, hittest;
8190
8191 style = GetWindowLongA(hwnd, GWL_STYLE);
8192 ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
8193 attrs->class_name[0] = 0;
8194 GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
8195 hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
8196
8197 attrs->is_visible = (style & WS_VISIBLE) != 0;
8198 attrs->is_enabled = (style & WS_DISABLED) == 0;
8199 attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
8200 attrs->is_httransparent = hittest == HTTRANSPARENT;
8201 attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
8202 }
8203
8204 static int window_to_index(HWND hwnd, HWND *window, int size)
8205 {
8206 int i;
8207
8208 for (i = 0; i < size; i++)
8209 {
8210 if (!window[i]) break;
8211 if (window[i] == hwnd) return i;
8212 }
8213 return -1;
8214 }
8215
8216 static void test_child_window_from_point(void)
8217 {
8218 static const int real_child_pos[] = { 14,15,16,17,18,19,20,21,24,25,26,27,42,43,
8219 44,45,46,47,48,49,52,53,54,55,51,50,23,22,-1 };
8220 static const int real_child_pos_nt4[] = { 14,15,16,17,20,21,24,25,26,27,42,43,44,45,
8221 48,49,52,53,54,55,51,50,47,46,23,22,19,18,-1 };
8222 WNDCLASSA cls;
8223 HWND hwnd, parent, window[100];
8224 POINT pt;
8225 int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
8226 int ret, i;
8227
8228 ret = GetClassInfoA(0, "Button", &cls);
8229 ok(ret, "GetClassInfo(Button) failed\n");
8230 cls.lpszClassName = "my_button";
8231 ret = RegisterClassA(&cls);
8232 ok(ret, "RegisterClass(my_button) failed\n");
8233
8234 cls.lpszClassName = "my_httrasparent";
8235 cls.lpfnWndProc = my_httrasparent_proc;
8236 ret = RegisterClassA(&cls);
8237 ok(ret, "RegisterClass(my_httrasparent) failed\n");
8238
8239 cls.lpszClassName = "my_window";
8240 cls.lpfnWndProc = my_window_proc;
8241 ret = RegisterClassA(&cls);
8242 ok(ret, "RegisterClass(my_window) failed\n");
8243
8244 parent = CreateWindowExA(0, "MainWindowClass", NULL,
8245 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
8246 100, 100, 200, 200,
8247 0, 0, GetModuleHandleA(NULL), NULL);
8248 ok(parent != 0, "CreateWindowEx failed\n");
8249 trace("parent %p\n", parent);
8250
8251 create_window_tree(parent, window, sizeof(window)/sizeof(window[0]));
8252
8253 found_invisible = 0;
8254 found_disabled = 0;
8255 found_groupbox = 0;
8256 found_httransparent = 0;
8257 found_extransparent = 0;
8258
8259 /* FIXME: also test WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx */
8260 for (i = 0; i < sizeof(real_child_pos)/sizeof(real_child_pos[0]); i++)
8261 {
8262 struct window_attributes attrs;
8263
8264 pt.x = pt.y = 50;
8265 hwnd = RealChildWindowFromPoint(parent, pt);
8266 ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
8267 ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
8268 /* FIXME: remove once Wine is fixed */
8269 todo_wine_if (ret != real_child_pos[i])
8270 ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
8271
8272 get_window_attributes(hwnd, &attrs);
8273 if (!attrs.is_visible) found_invisible++;
8274 if (!attrs.is_enabled) found_disabled++;
8275 if (attrs.is_groupbox) found_groupbox++;
8276 if (attrs.is_httransparent) found_httransparent++;
8277 if (attrs.is_extransparent) found_extransparent++;
8278
8279 if (ret != real_child_pos[i] && ret != -1)
8280 {
8281 trace("found hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8282 hwnd, attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
8283 get_window_attributes(window[real_child_pos[i]], &attrs);
8284 trace("expected hwnd %p (%s), is_visible %d, is_enabled %d, is_groupbox %d, is_httransparent %d, is_extransparent %d\n",
8285 window[real_child_pos[i]], attrs.class_name, attrs.is_visible, attrs.is_enabled, attrs.is_groupbox, attrs.is_httransparent, attrs.is_extransparent);
8286 }
8287 if (ret == -1)
8288 {
8289 ok(hwnd == parent, "expected %p, got %p\n", parent, hwnd);
8290 break;
8291 }
8292 DestroyWindow(hwnd);
8293 }
8294
8295 DestroyWindow(parent);
8296
8297 ok(!found_invisible, "found %d invisible windows\n", found_invisible);
8298 ok(found_disabled, "found %d disabled windows\n", found_disabled);
8299 todo_wine
8300 ok(found_groupbox == 4, "found %d groupbox windows\n", found_groupbox);
8301 ok(found_httransparent, "found %d httransparent windows\n", found_httransparent);
8302 todo_wine
8303 ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
8304
8305 ret = UnregisterClassA("my_button", cls.hInstance);
8306 ok(ret, "UnregisterClass(my_button) failed\n");
8307 ret = UnregisterClassA("my_httrasparent", cls.hInstance);
8308 ok(ret, "UnregisterClass(my_httrasparent) failed\n");
8309 ret = UnregisterClassA("my_window", cls.hInstance);
8310 ok(ret, "UnregisterClass(my_window) failed\n");
8311 }
8312
8313 static void simulate_click(int x, int y)
8314 {
8315 INPUT input[2];
8316 UINT events_no;
8317
8318 SetCursorPos(x, y);
8319 memset(input, 0, sizeof(input));
8320 input[0].type = INPUT_MOUSE;
8321 U(input[0]).mi.dx = x;
8322 U(input[0]).mi.dy = y;
8323 U(input[0]).mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
8324 input[1].type = INPUT_MOUSE;
8325 U(input[1]).mi.dx = x;
8326 U(input[1]).mi.dy = y;
8327 U(input[1]).mi.dwFlags = MOUSEEVENTF_LEFTUP;
8328 events_no = SendInput(2, input, sizeof(input[0]));
8329 ok(events_no == 2, "SendInput returned %d\n", events_no);
8330 }
8331
8332 static WNDPROC def_static_proc;
8333 static BOOL got_hittest;
8334 static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
8335 {
8336 if(msg == WM_NCHITTEST)
8337 got_hittest = TRUE;
8338 if(msg == WM_LBUTTONDOWN)
8339 ok(0, "unexpected call\n");
8340
8341 return def_static_proc(hwnd, msg, wp, lp);
8342 }
8343
8344 static void window_from_point_proc(HWND parent)
8345 {
8346 HANDLE start_event, end_event;
8347 HANDLE win, child_static, child_button;
8348 BOOL got_click;
8349 DWORD ret;
8350 POINT pt;
8351 MSG msg;
8352
8353 start_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_start");
8354 ok(start_event != 0, "OpenEvent failed\n");
8355 end_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_end");
8356 ok(end_event != 0, "OpenEvent failed\n");
8357
8358 child_static = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
8359 0, 0, 100, 100, parent, 0, NULL, NULL);
8360 ok(child_static != 0, "CreateWindowEx failed\n");
8361 pt.x = pt.y = 150;
8362 win = WindowFromPoint(pt);
8363 ok(win == parent, "WindowFromPoint returned %p, expected %p\n", win, parent);
8364
8365 child_button = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8366 100, 0, 100, 100, parent, 0, NULL, NULL);
8367 ok(child_button != 0, "CreateWindowEx failed\n");
8368 pt.x = 250;
8369 win = WindowFromPoint(pt);
8370 ok(win == child_button, "WindowFromPoint returned %p, expected %p\n", win, child_button);
8371
8372 /* without this window simulate click test keeps sending WM_NCHITTEST
8373 * message to child_static in an infinite loop */
8374 win = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8375 0, 0, 100, 100, parent, 0, NULL, NULL);
8376 ok(win != 0, "CreateWindowEx failed\n");
8377 def_static_proc = (void*)SetWindowLongPtrA(child_static,
8378 GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
8379 flush_events(TRUE);
8380 SetEvent(start_event);
8381
8382 got_hittest = FALSE;
8383 got_click = FALSE;
8384 while(!got_click && wait_for_message(&msg)) {
8385 if(msg.message == WM_LBUTTONUP) {
8386 ok(msg.hwnd == win, "msg.hwnd = %p, expected %p\n", msg.hwnd, win);
8387 got_click = TRUE;
8388 }
8389 DispatchMessageA(&msg);
8390 }
8391 ok(got_hittest, "transparent window didn't get WM_NCHITTEST message\n");
8392 ok(got_click, "button under static window didn't get WM_LBUTTONUP\n");
8393
8394 ret = WaitForSingleObject(end_event, 5000);
8395 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %x\n", ret);
8396
8397 CloseHandle(start_event);
8398 CloseHandle(end_event);
8399 }
8400
8401 static void test_window_from_point(const char *argv0)
8402 {
8403 HWND hwnd, child, win;
8404 POINT pt;
8405 PROCESS_INFORMATION info;
8406 STARTUPINFOA startup;
8407 char cmd[MAX_PATH];
8408 HANDLE start_event, end_event;
8409
8410 hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP | WS_VISIBLE,
8411 100, 100, 200, 100, 0, 0, NULL, NULL);
8412 ok(hwnd != 0, "CreateWindowEx failed\n");
8413
8414 pt.x = pt.y = 150;
8415 win = WindowFromPoint(pt);
8416 pt.x = 250;
8417 if(win == hwnd)
8418 win = WindowFromPoint(pt);
8419 if(win != hwnd) {
8420 skip("there's another window covering test window\n");
8421 DestroyWindow(hwnd);
8422 return;
8423 }
8424
8425 child = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
8426 0, 0, 100, 100, hwnd, 0, NULL, NULL);
8427 ok(child != 0, "CreateWindowEx failed\n");
8428 pt.x = pt.y = 150;
8429 win = WindowFromPoint(pt);
8430 ok(win == hwnd, "WindowFromPoint returned %p, expected %p\n", win, hwnd);
8431 DestroyWindow(child);
8432
8433 child = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
8434 0, 0, 100, 100, hwnd, 0, NULL, NULL);
8435 ok(child != 0, "CreateWindowEx failed\n");
8436 win = WindowFromPoint(pt);
8437 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8438 DestroyWindow(child);
8439
8440 start_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_start");
8441 ok(start_event != 0, "CreateEvent failed\n");
8442 end_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_end");
8443 ok(start_event != 0, "CreateEvent failed\n");
8444
8445 sprintf(cmd, "%s win create_children %p\n", argv0, hwnd);
8446 memset(&startup, 0, sizeof(startup));
8447 startup.cb = sizeof(startup);
8448 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
8449 &startup, &info), "CreateProcess failed.\n");
8450 ok(wait_for_event(start_event, 1000), "didn't get start_event\n");
8451
8452 child = GetWindow(hwnd, GW_CHILD);
8453 win = WindowFromPoint(pt);
8454 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8455
8456 simulate_click(150, 150);
8457 flush_events(TRUE);
8458
8459 child = GetWindow(child, GW_HWNDNEXT);
8460 pt.x = 250;
8461 win = WindowFromPoint(pt);
8462 ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
8463
8464 SetEvent(end_event);
8465 winetest_wait_child_process(info.hProcess);
8466 CloseHandle(start_event);
8467 CloseHandle(end_event);
8468 CloseHandle(info.hProcess);
8469 CloseHandle(info.hThread);
8470
8471 DestroyWindow(hwnd);
8472 }
8473
8474 static void test_map_points(void)
8475 {
8476 BOOL ret;
8477 POINT p;
8478 HWND wnd, wnd0, dwnd;
8479 INT n;
8480 DWORD err;
8481 POINT pos = { 100, 200 };
8482 int width = 150;
8483 int height = 150;
8484 RECT window_rect;
8485 RECT client_rect;
8486
8487 /* Create test windows */
8488 wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
8489 ok(wnd != NULL, "Failed %p\n", wnd);
8490 wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
8491 ok(wnd0 != NULL, "Failed %p\n", wnd);
8492 dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
8493 DestroyWindow(dwnd);
8494 ok(dwnd != NULL, "Failed %p\n", dwnd);
8495
8496 /* Verify window rect and client rect (they should have the same width and height) */
8497 GetWindowRect(wnd, &window_rect);
8498 ok(window_rect.left == pos.x, "left is %d instead of %d\n", window_rect.left, pos.x);
8499 ok(window_rect.top == pos.y, "top is %d instead of %d\n", window_rect.top, pos.y);
8500 ok(window_rect.right == pos.x + width, "right is %d instead of %d\n", window_rect.right, pos.x + width);
8501 ok(window_rect.bottom == pos.y + height, "bottom is %d instead of %d\n", window_rect.bottom, pos.y + height);
8502 GetClientRect(wnd, &client_rect);
8503 ok(client_rect.left == 0, "left is %d instead of 0\n", client_rect.left);
8504 ok(client_rect.top == 0, "top is %d instead of 0\n", client_rect.top);
8505 ok(client_rect.right == width, "right is %d instead of %d\n", client_rect.right, width);
8506 ok(client_rect.bottom == height, "bottom is %d instead of %d\n", client_rect.bottom, height);
8507
8508 /* Test MapWindowPoints */
8509
8510 /* MapWindowPoints(NULL or wnd, NULL or wnd, NULL, 1); crashes on Windows */
8511
8512 SetLastError(0xdeadbeef);
8513 n = MapWindowPoints(NULL, NULL, NULL, 0);
8514 err = GetLastError();
8515 ok(n == 0, "Got %d, expected %d\n", n, 0);
8516 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8517
8518 SetLastError(0xdeadbeef);
8519 n = MapWindowPoints(wnd, wnd, NULL, 0);
8520 err = GetLastError();
8521 ok(n == 0, "Got %d, expected %d\n", n, 0);
8522 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8523
8524 n = MapWindowPoints(wnd, NULL, NULL, 0);
8525 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
8526 n, MAKELONG(window_rect.left, window_rect.top));
8527
8528 n = MapWindowPoints(NULL, wnd, NULL, 0);
8529 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
8530 n, MAKELONG(-window_rect.left, -window_rect.top));
8531
8532 SetLastError(0xdeadbeef);
8533 p.x = p.y = 100;
8534 n = MapWindowPoints(dwnd, NULL, &p, 1);
8535 err = GetLastError();
8536 ok(n == 0, "Got %d, expected %d\n", n, 0);
8537 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8538 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8539
8540 SetLastError(0xdeadbeef);
8541 p.x = p.y = 100;
8542 n = MapWindowPoints(dwnd, wnd, &p, 1);
8543 err = GetLastError();
8544 ok(n == 0, "Got %d, expected %d\n", n, 0);
8545 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8546 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8547
8548 SetLastError(0xdeadbeef);
8549 p.x = p.y = 100;
8550 n = MapWindowPoints(NULL, dwnd, &p, 1);
8551 err = GetLastError();
8552 ok(n == 0, "Got %d, expected %d\n", n, 0);
8553 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8554 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8555
8556 SetLastError(0xdeadbeef);
8557 p.x = p.y = 100;
8558 n = MapWindowPoints(wnd, dwnd, &p, 1);
8559 err = GetLastError();
8560 ok(n == 0, "Got %d, expected %d\n", n, 0);
8561 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8562 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8563
8564 SetLastError(0xdeadbeef);
8565 p.x = p.y = 100;
8566 n = MapWindowPoints(dwnd, dwnd, &p, 1);
8567 err = GetLastError();
8568 ok(n == 0, "Got %d, expected %d\n", n, 0);
8569 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8570 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8571
8572 SetLastError(0xdeadbeef);
8573 p.x = p.y = 100;
8574 n = MapWindowPoints(NULL, NULL, &p, 1);
8575 err = GetLastError();
8576 ok(n == 0, "Got %d, expected %d\n", n, 0);
8577 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8578 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8579
8580 SetLastError(0xdeadbeef);
8581 p.x = p.y = 100;
8582 n = MapWindowPoints(wnd, wnd, &p, 1);
8583 err = GetLastError();
8584 ok(n == 0, "Got %d, expected %d\n", n, 0);
8585 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8586 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8587
8588 p.x = p.y = 100;
8589 n = MapWindowPoints(wnd, NULL, &p, 1);
8590 ok(n == MAKELONG(window_rect.left, window_rect.top), "Got %x, expected %x\n",
8591 n, MAKELONG(window_rect.left, window_rect.top));
8592 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8593 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
8594
8595 p.x = p.y = 100;
8596 n = MapWindowPoints(NULL, wnd, &p, 1);
8597 ok(n == MAKELONG(-window_rect.left, -window_rect.top), "Got %x, expected %x\n",
8598 n, MAKELONG(-window_rect.left, -window_rect.top));
8599 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8600 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
8601
8602 SetLastError(0xdeadbeef);
8603 p.x = p.y = 0;
8604 n = MapWindowPoints(wnd0, NULL, &p, 1);
8605 err = GetLastError();
8606 ok(n == 0, "Got %x, expected 0\n", n);
8607 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
8608 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8609
8610 SetLastError(0xdeadbeef);
8611 p.x = p.y = 0;
8612 n = MapWindowPoints(NULL, wnd0, &p, 1);
8613 err = GetLastError();
8614 ok(n == 0, "Got %x, expected 0\n", n);
8615 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
8616 ok(err == 0xdeadbeef, "Got %x, expected %x\n", err, 0xdeadbeef);
8617
8618 /* Test ClientToScreen */
8619
8620 /* ClientToScreen(wnd, NULL); crashes on Windows */
8621
8622 SetLastError(0xdeadbeef);
8623 ret = ClientToScreen(NULL, NULL);
8624 err = GetLastError();
8625 ok(!ret, "Should fail\n");
8626 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8627
8628 SetLastError(0xdeadbeef);
8629 p.x = p.y = 100;
8630 ret = ClientToScreen(NULL, &p);
8631 err = GetLastError();
8632 ok(!ret, "Should fail\n");
8633 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8634 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8635
8636 SetLastError(0xdeadbeef);
8637 p.x = p.y = 100;
8638 ret = ClientToScreen(dwnd, &p);
8639 err = GetLastError();
8640 ok(!ret, "Should fail\n");
8641 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8642 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8643
8644 p.x = p.y = 100;
8645 ret = ClientToScreen(wnd, &p);
8646 ok(ret, "Failed with error %u\n", GetLastError());
8647 ok((p.x == (window_rect.left + 100)) && (p.y == (window_rect.top + 100)), "Failed got (%d, %d), expected (%d, %d)\n",
8648 p.x, p.y, window_rect.left + 100, window_rect.top + 100);
8649
8650 p.x = p.y = 0;
8651 ret = ClientToScreen(wnd0, &p);
8652 ok(ret, "Failed with error %u\n", GetLastError());
8653 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
8654
8655 /* Test ScreenToClient */
8656
8657 /* ScreenToClient(wnd, NULL); crashes on Windows */
8658
8659 SetLastError(0xdeadbeef);
8660 ret = ScreenToClient(NULL, NULL);
8661 err = GetLastError();
8662 ok(!ret, "Should fail\n");
8663 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8664
8665 SetLastError(0xdeadbeef);
8666 p.x = p.y = 100;
8667 ret = ScreenToClient(NULL, &p);
8668 err = GetLastError();
8669 ok(!ret, "Should fail\n");
8670 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8671 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8672
8673 SetLastError(0xdeadbeef);
8674 p.x = p.y = 100;
8675 ret = ScreenToClient(dwnd, &p);
8676 err = GetLastError();
8677 ok(!ret, "Should fail\n");
8678 ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
8679 ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
8680
8681 p.x = p.y = 100;
8682 ret = ScreenToClient(wnd, &p);
8683 ok(ret, "Failed with error %u\n", GetLastError());
8684 ok((p.x == (-window_rect.left + 100)) && (p.y == (-window_rect.top + 100)), "Failed got(%d, %d), expected (%d, %d)\n",
8685 p.x, p.y, -window_rect.left + 100, -window_rect.top + 100);
8686
8687 p.x = p.y = 0;
8688 ret = ScreenToClient(wnd0, &p);
8689 ok(ret, "Failed with error %u\n", GetLastError());
8690 ok((p.x == 0) && (p.y == 0), "Failed got (%d, %d), expected (0, 0)\n", p.x, p.y);
8691
8692 DestroyWindow(wnd);
8693 DestroyWindow(wnd0);
8694 }
8695
8696 static void test_update_region(void)
8697 {
8698 HWND hwnd, parent, child;
8699 HRGN rgn1, rgn2;
8700 const RECT rc = {15, 15, 40, 40};
8701 const POINT wnd_orig = {30, 20};
8702 const POINT child_orig = {10, 5};
8703
8704 parent = CreateWindowExA(0, "MainWindowClass", NULL,
8705 WS_VISIBLE | WS_CLIPCHILDREN,
8706 0, 0, 300, 150, NULL, NULL, GetModuleHandleA(0), 0);
8707 hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
8708 WS_VISIBLE | WS_CLIPCHILDREN | WS_CHILD,
8709 0, 0, 200, 100, parent, NULL, GetModuleHandleA(0), 0);
8710 child = CreateWindowExA(0, "MainWindowClass", NULL,
8711 WS_VISIBLE | WS_CHILD,
8712 child_orig.x, child_orig.y, 100, 50,
8713 hwnd, NULL, GetModuleHandleA(0), 0);
8714 assert(parent && hwnd && child);
8715
8716 ValidateRgn(parent, NULL);
8717 ValidateRgn(hwnd, NULL);
8718 InvalidateRect(hwnd, &rc, FALSE);
8719 ValidateRgn(child, NULL);
8720
8721 rgn1 = CreateRectRgn(0, 0, 0, 0);
8722 ok(GetUpdateRgn(parent, rgn1, FALSE) == NULLREGION,
8723 "has invalid area after ValidateRgn(NULL)\n");
8724 GetUpdateRgn(hwnd, rgn1, FALSE);
8725 rgn2 = CreateRectRgnIndirect(&rc);
8726 ok(EqualRgn(rgn1, rgn2), "assigned and retrieved update regions are different\n");
8727 ok(GetUpdateRgn(child, rgn2, FALSE) == NULLREGION,
8728 "has invalid area after ValidateRgn(NULL)\n");
8729
8730 SetWindowPos(hwnd, 0, wnd_orig.x, wnd_orig.y, 0, 0,
8731 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
8732
8733 /* parent now has non-simple update region, it consist of
8734 * two rects, that was exposed after hwnd moving ... */
8735 SetRectRgn(rgn1, 0, 0, 200, wnd_orig.y);
8736 SetRectRgn(rgn2, 0, 0, wnd_orig.x, 100);
8737 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
8738 /* ... and mapped hwnd's invalid area, that hwnd has before moving */
8739 SetRectRgn(rgn2, rc.left + wnd_orig.x, rc.top + wnd_orig.y,
8740 rc.right + wnd_orig.x, rc.bottom + wnd_orig.y);
8741 CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
8742 GetUpdateRgn(parent, rgn2, FALSE);
8743 todo_wine
8744 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
8745
8746 /* hwnd has the same invalid region as before moving */
8747 SetRectRgn(rgn1, rc.left, rc.top, rc.right, rc.bottom);
8748 GetUpdateRgn(hwnd, rgn2, FALSE);
8749 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
8750
8751 /* hwnd's invalid area maps to child during moving */
8752 SetRectRgn(rgn1, rc.left - child_orig.x , rc.top - child_orig.y,
8753 rc.right - child_orig.x, rc.bottom - child_orig.y);
8754 GetUpdateRgn(child, rgn2, FALSE);
8755 todo_wine
8756 ok(EqualRgn(rgn1, rgn2), "wrong update region\n");
8757
8758 DeleteObject(rgn1);
8759 DeleteObject(rgn2);
8760 DestroyWindow(parent);
8761 }
8762
8763 static void test_window_without_child_style(void)
8764 {
8765 HWND hwnd;
8766
8767 hwnd = CreateWindowExA(0, "edit", NULL, WS_VISIBLE|WS_CHILD,
8768 0, 0, 50, 50, hwndMain, NULL, 0, NULL);
8769 ok(hwnd != NULL, "CreateWindow failed\n");
8770
8771 ok(SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & (~WS_CHILD)),
8772 "can't remove WS_CHILD style\n");
8773
8774 SetActiveWindow(hwndMain);
8775 PostMessageW(hwnd, WM_LBUTTONUP, 0, 0);
8776 SendMessageW(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
8777 check_active_state(hwnd, hwnd, hwnd);
8778 flush_events(TRUE);
8779
8780 DestroyWindow(hwnd);
8781 }
8782
8783
8784 struct smresult_thread_data
8785 {
8786 HWND main_hwnd;
8787 HWND thread_hwnd;
8788 HANDLE thread_started;
8789 HANDLE thread_got_wm_app;
8790 HANDLE main_in_wm_app_1;
8791 HANDLE thread_replied;
8792 };
8793
8794
8795 static LRESULT WINAPI smresult_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
8796 {
8797 switch (msg)
8798 {
8799 case WM_APP:
8800 {
8801 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
8802
8803 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
8804
8805 SendNotifyMessageA(data->main_hwnd, WM_APP+1, 0, lparam);
8806
8807 /* Don't return until the main thread is processing our sent message. */
8808 ok(WaitForSingleObject(data->main_in_wm_app_1, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8809
8810 /* Break the PeekMessage loop so we can notify the main thread after we return. */
8811 SetEvent(data->thread_got_wm_app);
8812
8813 return 0x240408ea;
8814 }
8815 case WM_APP+1:
8816 {
8817 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
8818 LRESULT res;
8819
8820 ok(hwnd == data->main_hwnd, "unexpected hwnd %p\n", hwnd);
8821
8822 /* Ask the thread to reply to our WM_APP message. */
8823 SetEvent(data->main_in_wm_app_1);
8824
8825 /* Wait until the thread has sent a reply. */
8826 ok(WaitForSingleObject(data->thread_replied, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8827
8828 /* Send another message while we have a reply queued for the current one. */
8829 res = SendMessageA(data->thread_hwnd, WM_APP+2, 0, lparam);
8830 ok(res == 0x449b0190, "unexpected result %lx\n", res);
8831
8832 return 0;
8833 }
8834 case WM_APP+2:
8835 {
8836 struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
8837
8838 ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
8839
8840 /* Don't return until we know the main thread is processing sent messages. */
8841 SendMessageA(data->main_hwnd, WM_NULL, 0, 0);
8842
8843 return 0x449b0190;
8844 }
8845 case WM_CLOSE:
8846 PostQuitMessage(0);
8847 break;
8848 }
8849 return DefWindowProcA(hwnd, msg, wparam, lparam);
8850 }
8851
8852 static DWORD WINAPI smresult_thread_proc(void *param)
8853 {
8854 MSG msg;
8855 struct smresult_thread_data *data = param;
8856
8857 data->thread_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
8858 100, 100, 200, 200, 0, 0, 0, NULL);
8859 ok(data->thread_hwnd != 0, "Failed to create overlapped window\n");
8860
8861 SetEvent(data->thread_started);
8862
8863 /* Loop until we've processed WM_APP. */
8864 while (WaitForSingleObject(data->thread_got_wm_app, 0) != WAIT_OBJECT_0)
8865 {
8866 if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
8867 {
8868 TranslateMessage(&msg);
8869 DispatchMessageA(&msg);
8870 }
8871 else
8872 {
8873 MsgWaitForMultipleObjects(1, &data->thread_got_wm_app, FALSE, INFINITE, QS_SENDMESSAGE);
8874 }
8875 }
8876
8877 /* Notify the main thread that we replied to its WM_APP message. */
8878 SetEvent(data->thread_replied);
8879
8880 while (GetMessageA(&msg, 0, 0, 0))
8881 {
8882 TranslateMessage(&msg);
8883 DispatchMessageA(&msg);
8884 }
8885
8886 return 0;
8887 }
8888
8889 static void test_smresult(void)
8890 {
8891 WNDCLASSA cls;
8892 HANDLE hThread;
8893 DWORD tid;
8894 struct smresult_thread_data data;
8895 BOOL ret;
8896 LRESULT res;
8897
8898 cls.style = CS_DBLCLKS;
8899 cls.lpfnWndProc = smresult_wndproc;
8900 cls.cbClsExtra = 0;
8901 cls.cbWndExtra = 0;
8902 cls.hInstance = GetModuleHandleA(0);
8903 cls.hIcon = 0;
8904 cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
8905 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
8906 cls.lpszMenuName = NULL;
8907 cls.lpszClassName = "SmresultClass";
8908
8909 ret = RegisterClassA(&cls);
8910 ok(ret, "RegisterClassA failed\n");
8911
8912 data.thread_started = CreateEventA(NULL, TRUE, FALSE, NULL);
8913 ok(data.thread_started != NULL, "CreateEventA failed\n");
8914
8915 data.thread_got_wm_app = CreateEventA(NULL, TRUE, FALSE, NULL);
8916 ok(data.thread_got_wm_app != NULL, "CreateEventA failed\n");
8917
8918 data.main_in_wm_app_1 = CreateEventA(NULL, TRUE, FALSE, NULL);
8919 ok(data.main_in_wm_app_1 != NULL, "CreateEventA failed\n");
8920
8921 data.thread_replied = CreateEventA(NULL, TRUE, FALSE, NULL);
8922 ok(data.thread_replied != NULL, "CreateEventA failed\n");
8923
8924 data.main_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
8925 100, 100, 200, 200, 0, 0, 0, NULL);
8926
8927 hThread = CreateThread(NULL, 0, smresult_thread_proc, &data, 0, &tid);
8928 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
8929
8930 ok(WaitForSingleObject(data.thread_started, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8931
8932 res = SendMessageA(data.thread_hwnd, WM_APP, 0, (LPARAM)&data);
8933 ok(res == 0x240408ea, "unexpected result %lx\n", res);
8934
8935 SendMessageA(data.thread_hwnd, WM_CLOSE, 0, 0);
8936
8937 DestroyWindow(data.main_hwnd);
8938
8939 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
8940
8941 CloseHandle(data.thread_started);
8942 CloseHandle(data.thread_got_wm_app);
8943 CloseHandle(data.main_in_wm_app_1);
8944 CloseHandle(data.thread_replied);
8945 }
8946
8947 static void test_GetMessagePos(void)
8948 {
8949 HWND button;
8950 DWORD pos;
8951 MSG msg;
8952
8953 button = CreateWindowExA(0, "button", "button", WS_VISIBLE,
8954 100, 100, 100, 100, 0, 0, 0, NULL);
8955 ok(button != 0, "CreateWindowExA failed\n");
8956
8957 SetCursorPos(120, 140);
8958 flush_events(TRUE);
8959 pos = GetMessagePos();
8960 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8961
8962 SetCursorPos(340, 320);
8963 pos = GetMessagePos();
8964 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8965
8966 SendMessageW(button, WM_APP, 0, 0);
8967 pos = GetMessagePos();
8968 ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
8969
8970 PostMessageA(button, WM_APP, 0, 0);
8971 GetMessageA(&msg, button, 0, 0);
8972 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8973 pos = GetMessagePos();
8974 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8975
8976 PostMessageA(button, WM_APP, 0, 0);
8977 SetCursorPos(350, 330);
8978 GetMessageA(&msg, button, 0, 0);
8979 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8980 pos = GetMessagePos();
8981 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8982
8983 PostMessageA(button, WM_APP, 0, 0);
8984 SetCursorPos(320, 340);
8985 PostMessageA(button, WM_APP+1, 0, 0);
8986 pos = GetMessagePos();
8987 ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
8988 GetMessageA(&msg, button, 0, 0);
8989 ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
8990 pos = GetMessagePos();
8991 ok(pos == MAKELONG(350, 330), "pos = %08x\n", pos);
8992 GetMessageA(&msg, button, 0, 0);
8993 ok(msg.message == WM_APP+1, "msg.message = %x\n", msg.message);
8994 pos = GetMessagePos();
8995 ok(pos == MAKELONG(320, 340), "pos = %08x\n", pos);
8996
8997 SetTimer(button, 1, 250, NULL);
8998 SetCursorPos(330, 350);
8999 GetMessageA(&msg, button, 0, 0);
9000 while (msg.message == WM_PAINT)
9001 {
9002 UpdateWindow( button );
9003 GetMessageA(&msg, button, 0, 0);
9004 }
9005 ok(msg.message == WM_TIMER, "msg.message = %x\n", msg.message);
9006 pos = GetMessagePos();
9007 ok(pos == MAKELONG(330, 350), "pos = %08x\n", pos);
9008 KillTimer(button, 1);
9009
9010 DestroyWindow(button);
9011 }
9012
9013 #define SET_FOREGROUND_STEAL_1 0x01
9014 #define SET_FOREGROUND_SET_1 0x02
9015 #define SET_FOREGROUND_STEAL_2 0x04
9016 #define SET_FOREGROUND_SET_2 0x08
9017 #define SET_FOREGROUND_INJECT 0x10
9018
9019 struct set_foreground_thread_params
9020 {
9021 UINT msg_quit, msg_command;
9022 HWND window1, window2, thread_window;
9023 HANDLE command_executed;
9024 };
9025
9026 static DWORD WINAPI set_foreground_thread(void *params)
9027 {
9028 struct set_foreground_thread_params *p = params;
9029 MSG msg;
9030
9031 p->thread_window = CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9032 0, 0, 10, 10, 0, 0, 0, NULL);
9033 SetEvent(p->command_executed);
9034
9035 while(GetMessageA(&msg, 0, 0, 0))
9036 {
9037 if (msg.message == p->msg_quit)
9038 break;
9039
9040 if (msg.message == p->msg_command)
9041 {
9042 if (msg.wParam & SET_FOREGROUND_STEAL_1)
9043 {
9044 SetForegroundWindow(p->thread_window);
9045 check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
9046 }
9047 if (msg.wParam & SET_FOREGROUND_INJECT)
9048 {
9049 SendNotifyMessageA(p->window1, WM_ACTIVATEAPP, 0, 0);
9050 }
9051 if (msg.wParam & SET_FOREGROUND_SET_1)
9052 {
9053 SetForegroundWindow(p->window1);
9054 check_wnd_state(0, p->window1, 0, 0);
9055 }
9056 if (msg.wParam & SET_FOREGROUND_STEAL_2)
9057 {
9058 SetForegroundWindow(p->thread_window);
9059 check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
9060 }
9061 if (msg.wParam & SET_FOREGROUND_SET_2)
9062 {
9063 SetForegroundWindow(p->window2);
9064 check_wnd_state(0, p->window2, 0, 0);
9065 }
9066
9067 SetEvent(p->command_executed);
9068 continue;
9069 }
9070
9071 TranslateMessage(&msg);
9072 DispatchMessageA(&msg);
9073 }
9074
9075 DestroyWindow(p->thread_window);
9076 return 0;
9077 }
9078
9079 static void test_activateapp(HWND window1)
9080 {
9081 HWND window2, test_window;
9082 HANDLE thread;
9083 struct set_foreground_thread_params thread_params;
9084 DWORD tid;
9085 MSG msg;
9086
9087 window2 = CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
9088 300, 0, 10, 10, 0, 0, 0, NULL);
9089 thread_params.msg_quit = WM_USER;
9090 thread_params.msg_command = WM_USER + 1;
9091 thread_params.window1 = window1;
9092 thread_params.window2 = window2;
9093 thread_params.command_executed = CreateEventW(NULL, FALSE, FALSE, NULL);
9094
9095 thread = CreateThread(NULL, 0, set_foreground_thread, &thread_params, 0, &tid);
9096 WaitForSingleObject(thread_params.command_executed, INFINITE);
9097
9098 SetForegroundWindow(window1);
9099 check_wnd_state(window1, window1, window1, 0);
9100 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9101
9102 /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
9103 app_activated = app_deactivated = FALSE;
9104 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1, 0);
9105 WaitForSingleObject(thread_params.command_executed, INFINITE);
9106 test_window = GetForegroundWindow();
9107 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9108 thread_params.thread_window, test_window);
9109 /* Active and Focus window are sometimes 0 on KDE. Ignore them.
9110 * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
9111 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9112 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9113 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9114 check_wnd_state(0, thread_params.thread_window, 0, 0);
9115 test_window = GetForegroundWindow();
9116 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9117 thread_params.thread_window, test_window);
9118 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9119 /* This message is reliable on Windows and inside a virtual desktop.
9120 * It is unreliable on KDE (50/50) and never arrives on FVWM.
9121 * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
9122
9123 /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
9124 app_activated = app_deactivated = FALSE;
9125 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1, 0);
9126 WaitForSingleObject(thread_params.command_executed, INFINITE);
9127 check_wnd_state(0, 0, 0, 0);
9128 test_window = GetForegroundWindow();
9129 ok(!test_window, "Expected foreground window 0, got %p\n", test_window);
9130 ok(!app_activated, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
9131 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9132 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9133 check_wnd_state(window1, window1, window1, 0);
9134 test_window = GetForegroundWindow();
9135 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9136 window1, test_window);
9137 ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9138 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9139
9140 /* Steal foreground then set it back: No messages are delivered. */
9141 app_activated = app_deactivated = FALSE;
9142 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_1, 0);
9143 WaitForSingleObject(thread_params.command_executed, INFINITE);
9144 test_window = GetForegroundWindow();
9145 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9146 window1, test_window);
9147 check_wnd_state(window1, window1, window1, 0);
9148 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9149 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9150 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9151 test_window = GetForegroundWindow();
9152 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9153 window1, test_window);
9154 check_wnd_state(window1, window1, window1, 0);
9155 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9156 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9157
9158 /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
9159 app_activated = app_deactivated = FALSE;
9160 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1
9161 | SET_FOREGROUND_INJECT | SET_FOREGROUND_SET_1, 0);
9162 WaitForSingleObject(thread_params.command_executed, INFINITE);
9163 test_window = GetForegroundWindow();
9164 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9165 window1, test_window);
9166 check_wnd_state(window1, window1, window1, 0);
9167 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9168 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9169 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9170 test_window = GetForegroundWindow();
9171 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9172 window1, test_window);
9173 check_wnd_state(window1, window1, window1, 0);
9174 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9175 ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9176
9177 SetForegroundWindow(thread_params.thread_window);
9178
9179 /* Set foreground then remove: Both messages are delivered. */
9180 app_activated = app_deactivated = FALSE;
9181 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1 | SET_FOREGROUND_STEAL_2, 0);
9182 WaitForSingleObject(thread_params.command_executed, INFINITE);
9183 test_window = GetForegroundWindow();
9184 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9185 thread_params.thread_window, test_window);
9186 check_wnd_state(0, thread_params.thread_window, 0, 0);
9187 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9188 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9189 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9190 test_window = GetForegroundWindow();
9191 ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
9192 thread_params.thread_window, test_window);
9193 /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
9194 * message is never generated. GetCapture() returns 0 though, so we'd get a test success
9195 * in todo_wine in the line below.
9196 * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
9197 ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
9198 todo_wine ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
9199
9200 SetForegroundWindow(window1);
9201 test_window = GetForegroundWindow();
9202 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9203 window1, test_window);
9204 check_wnd_state(window1, window1, window1, 0);
9205
9206 /* Switch to a different window from the same thread? No messages. */
9207 app_activated = app_deactivated = FALSE;
9208 PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_2, 0);
9209 WaitForSingleObject(thread_params.command_executed, INFINITE);
9210 test_window = GetForegroundWindow();
9211 ok(test_window == window1, "Expected foreground window %p, got %p\n",
9212 window1, test_window);
9213 check_wnd_state(window1, window1, window1, 0);
9214 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9215 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9216 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
9217 test_window = GetForegroundWindow();
9218 ok(test_window == window2, "Expected foreground window %p, got %p\n",
9219 window2, test_window);
9220 check_wnd_state(window2, window2, window2, 0);
9221 ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
9222 ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
9223
9224 PostThreadMessageA(tid, thread_params.msg_quit, 0, 0);
9225 WaitForSingleObject(thread, INFINITE);
9226
9227 CloseHandle(thread_params.command_executed);
9228 DestroyWindow(window2);
9229 }
9230
9231 static LRESULT WINAPI winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9232 {
9233 if(!hwnd) {
9234 int *count = (int*)lparam;
9235 (*count)++;
9236 }
9237 return 0;
9238 }
9239
9240 static LRESULT WINAPI winproc_convA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9241 {
9242 if(msg == WM_SETTEXT)
9243 {
9244 const char *text = (const char*)lparam;
9245
9246 ok(!wparam, "wparam = %08lx\n", wparam);
9247 ok(!strcmp(text, "text"), "WM_SETTEXT lparam = %s\n", text);
9248 return 1;
9249 }
9250 return 0;
9251 }
9252
9253 static const WCHAR textW[] = {'t','e','x','t',0};
9254 static LRESULT WINAPI winproc_convW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
9255 {
9256 if(msg == WM_SETTEXT)
9257 {
9258 const WCHAR *text = (const WCHAR*)lparam;
9259
9260 ok(!wparam, "wparam = %08lx\n", wparam);
9261 ok(!lstrcmpW(text, textW), "WM_SETTEXT lparam = %s\n", wine_dbgstr_w(text));
9262 return 1;
9263 }
9264 return 0;
9265 }
9266
9267 static void test_winproc_handles(const char *argv0)
9268 {
9269 static const WCHAR winproc_testW[] = {'w','i','n','p','r','o','c','_','t','e','s','t',0};
9270
9271 HINSTANCE hinst = GetModuleHandleA(NULL);
9272 WNDCLASSA wnd_classA;
9273 WNDCLASSW wnd_classW;
9274 int count, ret;
9275 PROCESS_INFORMATION info;
9276 STARTUPINFOA startup;
9277 char cmd[MAX_PATH];
9278
9279 memset(&wnd_classA, 0, sizeof(wnd_classA));
9280 wnd_classA.lpszClassName = "winproc_test";
9281 wnd_classA.lpfnWndProc = winproc;
9282 ret = RegisterClassA(&wnd_classA);
9283 ok(ret, "RegisterClass failed with error %d\n", GetLastError());
9284
9285 ret = GetClassInfoW(hinst, winproc_testW, &wnd_classW);
9286 ok(ret, "GetClassInfoW failed with error %d\n", GetLastError());
9287 ok(wnd_classA.lpfnWndProc != wnd_classW.lpfnWndProc,
9288 "winproc pointers should not be identical\n");
9289
9290 count = 0;
9291 CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9292 ok(count == 1, "winproc should be called once (%d)\n", count);
9293 count = 0;
9294 CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9295 ok(count == 1, "winproc should be called once (%d)\n", count);
9296
9297 ret = UnregisterClassW(winproc_testW, hinst);
9298 ok(ret, "UnregisterClass failed with error %d\n", GetLastError());
9299
9300 /* crashes on 64-bit windows because lpfnWndProc handle is already freed */
9301 if (sizeof(void*) == 4)
9302 {
9303 count = 0;
9304 CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9305 todo_wine ok(!count, "winproc should not be called (%d)\n", count);
9306 CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
9307 todo_wine ok(!count, "winproc should not be called (%d)\n", count);
9308 }
9309
9310 sprintf(cmd, "%s win winproc_limit", argv0);
9311 memset(&startup, 0, sizeof(startup));
9312 startup.cb = sizeof(startup);
9313 ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
9314 &startup, &info), "CreateProcess failed.\n");
9315 winetest_wait_child_process(info.hProcess);
9316 CloseHandle(info.hProcess);
9317 CloseHandle(info.hThread);
9318 }
9319
9320 static void test_winproc_limit(void)
9321 {
9322 WNDPROC winproc_handle;
9323 LONG_PTR ret;
9324 HWND hwnd;
9325 int i;
9326
9327 hwnd = CreateWindowExA(0, "static", "test", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
9328 ok(hwnd != 0, "CreateWindowEx failed\n");
9329
9330 ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc),
9331 "SetWindowLongPtr failed\n");
9332 winproc_handle = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
9333 ok(winproc_handle != winproc, "winproc pointers should not be identical\n");
9334
9335 /* run out of winproc slots */
9336 for(i = 2; i<0xffff; i++)
9337 {
9338 ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, i), "SetWindowLongPtr failed (%d)\n", i);
9339 if(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == i)
9340 break;
9341 }
9342 ok(i != 0xffff, "unable to run out of winproc slots\n");
9343
9344 ret = SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convA);
9345 ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
9346 ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
9347 ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
9348
9349 ret = SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convW);
9350 ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
9351 ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
9352 ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
9353
9354 /* Show that there's no message conversion when CallWindowProc is used */
9355 ok(CallWindowProcA(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
9356 "winproc_convW returned error\n");
9357 ok(CallWindowProcW(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
9358 "winproc_convW returned error\n");
9359
9360 i = 0;
9361 CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
9362 ok(i == 1, "winproc should be called once (%d)\n", i);
9363 i = 0;
9364 CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
9365 ok(i == 1, "winproc should be called once (%d)\n", i);
9366
9367 DestroyWindow(hwnd);
9368
9369 i = 0;
9370 CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
9371 ok(i == 1, "winproc should be called once (%d)\n", i);
9372 i = 0;
9373 CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
9374 ok(i == 1, "winproc should be called once (%d)\n", i);
9375 }
9376
9377 static void test_deferwindowpos(void)
9378 {
9379 HDWP hdwp, hdwp2;
9380 BOOL ret;
9381
9382 hdwp = BeginDeferWindowPos(0);
9383 ok(hdwp != NULL, "got %p\n", hdwp);
9384
9385 ret = EndDeferWindowPos(NULL);
9386 ok(!ret, "got %d\n", ret);
9387
9388 hdwp2 = DeferWindowPos(NULL, NULL, NULL, 0, 0, 10, 10, 0);
9389 todo_wine
9390 ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
9391 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
9392
9393 hdwp2 = DeferWindowPos((HDWP)0xdead, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
9394 todo_wine
9395 ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
9396 broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
9397
9398 hdwp2 = DeferWindowPos(hdwp, NULL, NULL, 0, 0, 10, 10, 0);
9399 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9400
9401 hdwp2 = DeferWindowPos(hdwp, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
9402 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9403
9404 hdwp2 = DeferWindowPos(hdwp, (HWND)0xdead, NULL, 0, 0, 10, 10, 0);
9405 ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
9406
9407 ret = EndDeferWindowPos(hdwp);
9408 ok(ret, "got %d\n", ret);
9409 }
9410
9411 START_TEST(win)
9412 {
9413 char **argv;
9414 int argc = winetest_get_mainargs( &argv );
9415 HMODULE user32 = GetModuleHandleA( "user32.dll" );
9416 HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
9417 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
9418 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
9419 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
9420 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
9421 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
9422 pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
9423 pUpdateLayeredWindowIndirect = (void *)GetProcAddress( user32, "UpdateLayeredWindowIndirect" );
9424 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
9425 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
9426 pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
9427 pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
9428 pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
9429 pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
9430 pFlashWindow = (void *)GetProcAddress( user32, "FlashWindow" );
9431 pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
9432 pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
9433 pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
9434 pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
9435
9436 if (argc==4 && !strcmp(argv[2], "create_children"))
9437 {
9438 HWND hwnd;
9439
9440 sscanf(argv[3], "%p", &hwnd);
9441 window_from_point_proc(hwnd);
9442 return;
9443 }
9444
9445 if (argc==3 && !strcmp(argv[2], "winproc_limit"))
9446 {
9447 test_winproc_limit();
9448 return;
9449 }
9450
9451 if (!RegisterWindowClasses()) assert(0);
9452
9453 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
9454 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
9455 WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
9456 100, 100, 200, 200,
9457 0, 0, GetModuleHandleA(NULL), NULL);
9458 assert( hwndMain );
9459
9460 if(!SetForegroundWindow(hwndMain)) {
9461 /* workaround for foreground lock timeout */
9462 simulate_click(101, 101);
9463 ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
9464 }
9465
9466 SetLastError(0xdeafbeef);
9467 GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
9468 is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
9469
9470 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
9471 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
9472
9473 /* make sure that these tests are executed first */
9474 test_FindWindowEx();
9475 test_SetParent();
9476
9477 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
9478 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
9479 WS_MAXIMIZEBOX | WS_POPUP,
9480 100, 100, 200, 200,
9481 0, 0, GetModuleHandleA(NULL), NULL);
9482 assert( hwndMain2 );
9483
9484 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
9485
9486 /* Add the tests below this line */
9487 test_child_window_from_point();
9488 test_window_from_point(argv[0]);
9489 test_thick_child_size(hwndMain);
9490 test_fullscreen();
9491 test_hwnd_message();
9492 test_nonclient_area(hwndMain);
9493 test_params();
9494 test_GetWindowModuleFileName();
9495 test_capture_1();
9496 test_capture_2();
9497 test_capture_3(hwndMain, hwndMain2);
9498 test_capture_4();
9499 test_rtl_layout();
9500 test_FlashWindow();
9501 test_FlashWindowEx();
9502
9503 test_CreateWindow();
9504 test_parent_owner();
9505 test_enum_thread_windows();
9506
9507 test_mdi();
9508 test_icons();
9509 test_SetWindowPos(hwndMain, hwndMain2);
9510 test_SetMenu(hwndMain);
9511 test_SetFocus(hwndMain);
9512 test_SetActiveWindow(hwndMain);
9513 test_NCRedraw();
9514
9515 test_children_zorder(hwndMain);
9516 test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
9517 test_popup_zorder(hwndMain2, hwndMain, 0);
9518 test_GetLastActivePopup();
9519 test_keyboard_input(hwndMain);
9520 test_mouse_input(hwndMain);
9521 test_validatergn(hwndMain);
9522 test_nccalcscroll( hwndMain);
9523 test_scrollwindow( hwndMain);
9524 test_scrollvalidate( hwndMain);
9525 test_scrolldc( hwndMain);
9526 test_scroll();
9527 test_IsWindowUnicode();
9528 test_vis_rgn(hwndMain);
9529
9530 test_AdjustWindowRect();
9531 test_window_styles();
9532 test_dialog_styles();
9533 test_dialog_parent();
9534 test_redrawnow();
9535 test_csparentdc();
9536 test_SetWindowLong();
9537 test_set_window_style();
9538 test_ShowWindow();
9539 test_gettext();
9540 test_GetUpdateRect();
9541 test_Expose();
9542 test_layered_window();
9543
9544 test_SetForegroundWindow(hwndMain);
9545 test_shell_window();
9546 test_handles( hwndMain );
9547 test_winregion();
9548 test_map_points();
9549 test_update_region();
9550 test_window_without_child_style();
9551 test_smresult();
9552 test_GetMessagePos();
9553
9554 test_activateapp(hwndMain);
9555 test_winproc_handles(argv[0]);
9556 test_deferwindowpos();
9557
9558 /* add the tests above this line */
9559 if (hhook) UnhookWindowsHookEx(hhook);
9560
9561 DestroyWindow(hwndMain2);
9562 DestroyWindow(hwndMain);
9563 }