- Sync winetests with Wine head (comcat, crypt32, gdiplus, lz32, mapi32, mlang, msacm...
[reactos.git] / rostests / winetests / user32 / win.c
1 /*
2 * Unit tests for window handling
3 *
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 #include "wine/test.h"
37
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
40 #endif
41
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
44
45 void dump_region(HRGN hrgn);
46
47 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
48 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
49 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
50 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
51 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
52 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
53 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
54
55 static BOOL test_lbuttondown_flag;
56 static HWND hwndMessage;
57 static HWND hwndMain, hwndMain2;
58 static HHOOK hhook;
59
60 static const char* szAWRClass = "Winsize";
61 static HMENU hmenu;
62 static DWORD our_pid;
63
64 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
65
66 static void dump_minmax_info( const MINMAXINFO *minmax )
67 {
68 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
69 minmax->ptReserved.x, minmax->ptReserved.y,
70 minmax->ptMaxSize.x, minmax->ptMaxSize.y,
71 minmax->ptMaxPosition.x, minmax->ptMaxPosition.y,
72 minmax->ptMinTrackSize.x, minmax->ptMinTrackSize.y,
73 minmax->ptMaxTrackSize.x, minmax->ptMaxTrackSize.y);
74 }
75
76 /* try to make sure pending X events have been processed before continuing */
77 static void flush_events( BOOL remove_messages )
78 {
79 MSG msg;
80 int diff = 200;
81 int min_timeout = 100;
82 DWORD time = GetTickCount() + diff;
83
84 while (diff > 0)
85 {
86 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
87 if (remove_messages)
88 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
89 diff = time - GetTickCount();
90 min_timeout = 50;
91 }
92 }
93
94 /* check the values returned by the various parent/owner functions on a given window */
95 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
96 HWND gw_owner, HWND ga_root, HWND ga_root_owner )
97 {
98 HWND res;
99
100 if (pGetAncestor)
101 {
102 res = pGetAncestor( hwnd, GA_PARENT );
103 ok( res == ga_parent, "Wrong result for GA_PARENT %p expected %p\n", res, ga_parent );
104 }
105 res = (HWND)GetWindowLongPtrA( hwnd, GWLP_HWNDPARENT );
106 ok( res == gwl_parent, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res, gwl_parent );
107 res = GetParent( hwnd );
108 ok( res == get_parent, "Wrong result for GetParent %p expected %p\n", res, get_parent );
109 res = GetWindow( hwnd, GW_OWNER );
110 ok( res == gw_owner, "Wrong result for GW_OWNER %p expected %p\n", res, gw_owner );
111 if (pGetAncestor)
112 {
113 res = pGetAncestor( hwnd, GA_ROOT );
114 ok( res == ga_root, "Wrong result for GA_ROOT %p expected %p\n", res, ga_root );
115 res = pGetAncestor( hwnd, GA_ROOTOWNER );
116 ok( res == ga_root_owner, "Wrong result for GA_ROOTOWNER %p expected %p\n", res, ga_root_owner );
117 }
118 }
119
120 static BOOL CALLBACK EnumChildProc( HWND hwndChild, LPARAM lParam)
121 {
122 (*(LPINT)lParam)++;
123 trace("EnumChildProc on %p\n", hwndChild);
124 if (*(LPINT)lParam > 1) return FALSE;
125 return TRUE;
126 }
127
128 /* will search for the given window */
129 static BOOL CALLBACK EnumChildProc1( HWND hwndChild, LPARAM lParam)
130 {
131 trace("EnumChildProc1 on %p\n", hwndChild);
132 if ((HWND)lParam == hwndChild) return FALSE;
133 return TRUE;
134 }
135
136 static HWND create_tool_window( LONG style, HWND parent )
137 {
138 HWND ret = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style,
139 0, 0, 100, 100, parent, 0, 0, NULL );
140 ok( ret != 0, "Creation failed\n" );
141 return ret;
142 }
143
144 /* test parent and owner values for various combinations */
145 static void test_parent_owner(void)
146 {
147 LONG style;
148 HWND test, owner, ret;
149 HWND desktop = GetDesktopWindow();
150 HWND child = create_tool_window( WS_CHILD, hwndMain );
151 INT numChildren;
152
153 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain, hwndMain2, desktop, child );
154
155 /* child without parent, should fail */
156 SetLastError(0xdeadbeef);
157 test = CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
158 WS_CHILD, 0, 0, 100, 100, 0, 0, 0, NULL );
159 ok( !test, "WS_CHILD without parent created\n" );
160 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD ||
161 broken(GetLastError() == 0xdeadbeef), /* win9x */
162 "CreateWindowExA error %u\n", GetLastError() );
163
164 /* desktop window */
165 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
166 style = GetWindowLongA( desktop, GWL_STYLE );
167 ok( !SetWindowLongA( desktop, GWL_STYLE, WS_POPUP ), "Set GWL_STYLE on desktop succeeded\n" );
168 ok( !SetWindowLongA( desktop, GWL_STYLE, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
169 ok( GetWindowLongA( desktop, GWL_STYLE ) == style, "Desktop style changed\n" );
170
171 /* normal child window */
172 test = create_tool_window( WS_CHILD, hwndMain );
173 trace( "created child %p\n", test );
174 check_parents( test, hwndMain, hwndMain, hwndMain, 0, hwndMain, hwndMain );
175 SetWindowLongA( test, GWL_STYLE, 0 );
176 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
177 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
178 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
179 SetWindowLongA( test, GWL_STYLE, WS_POPUP|WS_CHILD );
180 check_parents( test, hwndMain, hwndMain, 0, 0, hwndMain, test );
181 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
182 DestroyWindow( test );
183
184 /* normal child window with WS_MAXIMIZE */
185 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, hwndMain );
186 DestroyWindow( test );
187
188 /* normal child window with WS_THICKFRAME */
189 test = create_tool_window( WS_CHILD | WS_THICKFRAME, hwndMain );
190 DestroyWindow( test );
191
192 /* popup window with WS_THICKFRAME */
193 test = create_tool_window( WS_POPUP | WS_THICKFRAME, hwndMain );
194 DestroyWindow( test );
195
196 /* child of desktop */
197 test = create_tool_window( WS_CHILD, desktop );
198 trace( "created child of desktop %p\n", test );
199 check_parents( test, desktop, 0, desktop, 0, test, desktop );
200 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
201 check_parents( test, desktop, 0, 0, 0, test, test );
202 SetWindowLongA( test, GWL_STYLE, 0 );
203 check_parents( test, desktop, 0, 0, 0, test, test );
204 DestroyWindow( test );
205
206 /* child of desktop with WS_MAXIMIZE */
207 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, desktop );
208 DestroyWindow( test );
209
210 /* child of desktop with WS_MINIMIZE */
211 test = create_tool_window( WS_CHILD | WS_MINIMIZE, desktop );
212 DestroyWindow( test );
213
214 /* child of child */
215 test = create_tool_window( WS_CHILD, child );
216 trace( "created child of child %p\n", test );
217 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
218 SetWindowLongA( test, GWL_STYLE, 0 );
219 check_parents( test, child, child, 0, 0, hwndMain, test );
220 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
221 check_parents( test, child, child, 0, 0, hwndMain, test );
222 DestroyWindow( test );
223
224 /* child of child with WS_MAXIMIZE */
225 test = create_tool_window( WS_CHILD | WS_MAXIMIZE, child );
226 DestroyWindow( test );
227
228 /* child of child with WS_MINIMIZE */
229 test = create_tool_window( WS_CHILD | WS_MINIMIZE, child );
230 DestroyWindow( test );
231
232 /* not owned top-level window */
233 test = create_tool_window( 0, 0 );
234 trace( "created top-level %p\n", test );
235 check_parents( test, desktop, 0, 0, 0, test, test );
236 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
237 check_parents( test, desktop, 0, 0, 0, test, test );
238 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
239 check_parents( test, desktop, 0, desktop, 0, test, desktop );
240 DestroyWindow( test );
241
242 /* not owned top-level window with WS_MAXIMIZE */
243 test = create_tool_window( WS_MAXIMIZE, 0 );
244 DestroyWindow( test );
245
246 /* owned top-level window */
247 test = create_tool_window( 0, hwndMain );
248 trace( "created owned top-level %p\n", test );
249 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
250 SetWindowLongA( test, GWL_STYLE, WS_POPUP );
251 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
252 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
253 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
254 DestroyWindow( test );
255
256 /* owned top-level window with WS_MAXIMIZE */
257 test = create_tool_window( WS_MAXIMIZE, hwndMain );
258 DestroyWindow( test );
259
260 /* not owned popup */
261 test = create_tool_window( WS_POPUP, 0 );
262 trace( "created popup %p\n", test );
263 check_parents( test, desktop, 0, 0, 0, test, test );
264 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
265 check_parents( test, desktop, 0, desktop, 0, test, desktop );
266 SetWindowLongA( test, GWL_STYLE, 0 );
267 check_parents( test, desktop, 0, 0, 0, test, test );
268 DestroyWindow( test );
269
270 /* not owned popup with WS_MAXIMIZE */
271 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, 0 );
272 DestroyWindow( test );
273
274 /* owned popup */
275 test = create_tool_window( WS_POPUP, hwndMain );
276 trace( "created owned popup %p\n", test );
277 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
278 SetWindowLongA( test, GWL_STYLE, WS_CHILD );
279 check_parents( test, desktop, hwndMain, desktop, hwndMain, test, desktop );
280 SetWindowLongA( test, GWL_STYLE, 0 );
281 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
282 DestroyWindow( test );
283
284 /* owned popup with WS_MAXIMIZE */
285 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, hwndMain );
286 DestroyWindow( test );
287
288 /* top-level window owned by child (same as owned by top-level) */
289 test = create_tool_window( 0, child );
290 trace( "created top-level owned by child %p\n", test );
291 check_parents( test, desktop, hwndMain, 0, hwndMain, test, test );
292 DestroyWindow( test );
293
294 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
295 test = create_tool_window( WS_MAXIMIZE, child );
296 DestroyWindow( test );
297
298 /* popup owned by desktop (same as not owned) */
299 test = create_tool_window( WS_POPUP, desktop );
300 trace( "created popup owned by desktop %p\n", test );
301 check_parents( test, desktop, 0, 0, 0, test, test );
302 DestroyWindow( test );
303
304 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
305 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, desktop );
306 DestroyWindow( test );
307
308 /* popup owned by child (same as owned by top-level) */
309 test = create_tool_window( WS_POPUP, child );
310 trace( "created popup owned by child %p\n", test );
311 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
312 DestroyWindow( test );
313
314 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
315 test = create_tool_window( WS_POPUP | WS_MAXIMIZE, child );
316 DestroyWindow( test );
317
318 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
319 test = create_tool_window( WS_POPUP | WS_CHILD, 0 );
320 trace( "created WS_CHILD popup %p\n", test );
321 check_parents( test, desktop, 0, 0, 0, test, test );
322 DestroyWindow( test );
323
324 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
325 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, 0 );
326 DestroyWindow( test );
327
328 /* owned popup with WS_CHILD (same as WS_POPUP only) */
329 test = create_tool_window( WS_POPUP | WS_CHILD, hwndMain );
330 trace( "created owned WS_CHILD popup %p\n", test );
331 check_parents( test, desktop, hwndMain, hwndMain, hwndMain, test, hwndMain );
332 DestroyWindow( test );
333
334 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
335 test = create_tool_window( WS_POPUP | WS_CHILD | WS_MAXIMIZE, hwndMain );
336 DestroyWindow( test );
337
338 /******************** parent changes *************************/
339 trace( "testing parent changes\n" );
340
341 /* desktop window */
342 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
343 if (0)
344 {
345 /* this test succeeds on NT but crashes on win9x systems */
346 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
347 ok( !ret, "Set GWL_HWNDPARENT succeeded on desktop\n" );
348 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
349 ok( !SetParent( desktop, hwndMain ), "SetParent succeeded on desktop\n" );
350 check_parents( desktop, 0, 0, 0, 0, 0, 0 );
351 }
352 /* normal child window */
353 test = create_tool_window( WS_CHILD, hwndMain );
354 trace( "created child %p\n", test );
355
356 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
357 ok( ret == hwndMain, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain );
358 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
359
360 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
361 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
362 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
363
364 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)desktop );
365 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
366 check_parents( test, desktop, 0, desktop, 0, test, desktop );
367
368 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
369 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
370 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
371 check_parents( test, desktop, child, desktop, child, test, desktop );
372
373 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
374 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
375 check_parents( test, desktop, 0, desktop, 0, test, desktop );
376 DestroyWindow( test );
377
378 /* not owned top-level window */
379 test = create_tool_window( 0, 0 );
380 trace( "created top-level %p\n", test );
381
382 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
383 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
384 check_parents( test, desktop, hwndMain2, 0, hwndMain2, test, test );
385
386 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
387 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
388 check_parents( test, desktop, child, 0, child, test, test );
389
390 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
391 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
392 check_parents( test, desktop, 0, 0, 0, test, test );
393 DestroyWindow( test );
394
395 /* not owned popup */
396 test = create_tool_window( WS_POPUP, 0 );
397 trace( "created popup %p\n", test );
398
399 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)hwndMain2 );
400 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
401 check_parents( test, desktop, hwndMain2, hwndMain2, hwndMain2, test, hwndMain2 );
402
403 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (LONG_PTR)child );
404 ok( ret == hwndMain2, "GWL_HWNDPARENT return value %p expected %p\n", ret, hwndMain2 );
405 check_parents( test, desktop, child, child, child, test, hwndMain );
406
407 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, 0 );
408 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
409 check_parents( test, desktop, 0, 0, 0, test, test );
410 DestroyWindow( test );
411
412 /* normal child window */
413 test = create_tool_window( WS_CHILD, hwndMain );
414 trace( "created child %p\n", test );
415
416 ret = SetParent( test, desktop );
417 ok( ret == hwndMain, "SetParent return value %p expected %p\n", ret, hwndMain );
418 check_parents( test, desktop, 0, desktop, 0, test, desktop );
419
420 ret = SetParent( test, child );
421 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
422 check_parents( test, child, child, child, 0, hwndMain, hwndMain );
423
424 ret = SetParent( test, hwndMain2 );
425 ok( ret == child, "SetParent return value %p expected %p\n", ret, child );
426 check_parents( test, hwndMain2, hwndMain2, hwndMain2, 0, hwndMain2, hwndMain2 );
427 DestroyWindow( test );
428
429 /* not owned top-level window */
430 test = create_tool_window( 0, 0 );
431 trace( "created top-level %p\n", test );
432
433 ret = SetParent( test, child );
434 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
435 check_parents( test, child, child, 0, 0, hwndMain, test );
436 DestroyWindow( test );
437
438 /* owned popup */
439 test = create_tool_window( WS_POPUP, hwndMain2 );
440 trace( "created owned popup %p\n", test );
441
442 ret = SetParent( test, child );
443 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
444 check_parents( test, child, child, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
445
446 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)hwndMain );
447 ok( ret == child, "GWL_HWNDPARENT return value %p expected %p\n", ret, child );
448 check_parents( test, hwndMain, hwndMain, hwndMain2, hwndMain2, hwndMain, hwndMain2 );
449 DestroyWindow( test );
450
451 /**************** test owner destruction *******************/
452
453 /* owned child popup */
454 owner = create_tool_window( 0, 0 );
455 test = create_tool_window( WS_POPUP, owner );
456 trace( "created owner %p and popup %p\n", owner, test );
457 ret = SetParent( test, child );
458 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
459 check_parents( test, child, child, owner, owner, hwndMain, owner );
460 /* window is now child of 'child' but owned by 'owner' */
461 DestroyWindow( owner );
462 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
463 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
464 * while Win95, Win2k, WinXP do.
465 */
466 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
467 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
468 DestroyWindow(test);
469
470 /* owned top-level popup */
471 owner = create_tool_window( 0, 0 );
472 test = create_tool_window( WS_POPUP, owner );
473 trace( "created owner %p and popup %p\n", owner, test );
474 check_parents( test, desktop, owner, owner, owner, test, owner );
475 DestroyWindow( owner );
476 ok( !IsWindow(test), "Window %p not destroyed by owner destruction\n", test );
477
478 /* top-level popup owned by child */
479 owner = create_tool_window( WS_CHILD, hwndMain2 );
480 test = create_tool_window( WS_POPUP, 0 );
481 trace( "created owner %p and popup %p\n", owner, test );
482 ret = (HWND)SetWindowLongPtrA( test, GWLP_HWNDPARENT, (ULONG_PTR)owner );
483 ok( ret == 0, "GWL_HWNDPARENT return value %p expected 0\n", ret );
484 check_parents( test, desktop, owner, owner, owner, test, hwndMain2 );
485 DestroyWindow( owner );
486 ok( IsWindow(test), "Window %p destroyed by owner destruction\n", test );
487 ok( !IsWindow(owner), "Owner %p not destroyed\n", owner );
488 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
489 * while Win95, Win2k, WinXP do.
490 */
491 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
492 DestroyWindow(test);
493
494 /* final cleanup */
495 DestroyWindow(child);
496
497
498 owner = create_tool_window( WS_OVERLAPPED, 0 );
499 test = create_tool_window( WS_POPUP, desktop );
500
501 ok( !GetWindow( test, GW_OWNER ), "Wrong owner window\n" );
502 numChildren = 0;
503 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
504 "EnumChildWindows should have returned FALSE\n" );
505 ok( numChildren == 0, "numChildren should be 0 got %d\n", numChildren );
506
507 SetWindowLongA( test, GWL_STYLE, (GetWindowLongA( test, GWL_STYLE ) & ~WS_POPUP) | WS_CHILD );
508 ret = SetParent( test, owner );
509 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
510
511 numChildren = 0;
512 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
513 "EnumChildWindows should have returned TRUE\n" );
514 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
515
516 child = create_tool_window( WS_CHILD, owner );
517 numChildren = 0;
518 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
519 "EnumChildWindows should have returned FALSE\n" );
520 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
521 DestroyWindow( child );
522
523 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner );
524 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
525 numChildren = 0;
526 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
527 "EnumChildWindows should have returned TRUE\n" );
528 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
529
530 ret = SetParent( child, owner );
531 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
532 ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop );
533 numChildren = 0;
534 ok( !EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
535 "EnumChildWindows should have returned FALSE\n" );
536 ok( numChildren == 2, "numChildren should be 2 got %d\n", numChildren );
537
538 ret = SetParent( child, NULL );
539 ok( GetWindow( child, GW_OWNER ) == owner, "Wrong owner window\n" );
540 ok( ret == owner, "SetParent return value %p expected %p\n", ret, owner );
541 numChildren = 0;
542 ok( EnumChildWindows( owner, EnumChildProc, (LPARAM)&numChildren ),
543 "EnumChildWindows should have returned TRUE\n" );
544 ok( numChildren == 1, "numChildren should be 1 got %d\n", numChildren );
545
546 /* even GW_OWNER == owner it's still a desktop's child */
547 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
548 "EnumChildWindows should have found %p and returned FALSE\n", child );
549
550 DestroyWindow( child );
551 child = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, NULL );
552
553 ok( !EnumChildWindows( desktop, EnumChildProc1, (LPARAM)child ),
554 "EnumChildWindows should have found %p and returned FALSE\n", child );
555
556 DestroyWindow( child );
557 DestroyWindow( test );
558 DestroyWindow( owner );
559 }
560
561
562 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
563 {
564 switch (msg)
565 {
566 case WM_GETMINMAXINFO:
567 {
568 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
569
570 trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
571 dump_minmax_info( minmax );
572 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
573 break;
574 }
575 case WM_WINDOWPOSCHANGING:
576 {
577 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
578 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
579 trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
580 winpos->hwnd, winpos->hwndInsertAfter,
581 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
582 if (!(winpos->flags & SWP_NOMOVE))
583 {
584 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
585 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
586 }
587 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
588 if (!(winpos->flags & SWP_NOSIZE) && !is_win9x)
589 {
590 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
591 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
592 }
593 break;
594 }
595 case WM_WINDOWPOSCHANGED:
596 {
597 RECT rc1, rc2;
598 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
599 trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
600 winpos->hwnd, winpos->hwndInsertAfter,
601 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
602 ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
603 ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
604
605 ok(winpos->cx >= 0 && winpos->cx <= 32767, "bad winpos->cx %d\n", winpos->cx);
606 ok(winpos->cy >= 0 && winpos->cy <= 32767, "bad winpos->cy %d\n", winpos->cy);
607
608 GetWindowRect(hwnd, &rc1);
609 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
610 /* note: winpos coordinates are relative to parent */
611 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
612 if (0)
613 {
614 /* Uncomment this once the test succeeds in all cases */
615 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
616 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
617
618 GetClientRect(hwnd, &rc2);
619 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
620 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
621 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
622 rc1.left, rc1.top, rc1.right, rc1.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom );
623 }
624 break;
625 }
626 case WM_NCCREATE:
627 {
628 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
629 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
630
631 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
632 if (got_getminmaxinfo)
633 trace("%p got WM_GETMINMAXINFO\n", hwnd);
634
635 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
636 ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
637 else
638 ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
639 break;
640 }
641 case WM_COMMAND:
642 if (test_lbuttondown_flag)
643 {
644 ShowWindow((HWND)wparam, SW_SHOW);
645 flush_events( FALSE );
646 }
647 break;
648 }
649
650 return DefWindowProcA(hwnd, msg, wparam, lparam);
651 }
652
653 static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
654 {
655 switch (msg)
656 {
657 case WM_GETMINMAXINFO:
658 {
659 MINMAXINFO* minmax = (MINMAXINFO *)lparam;
660
661 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
662 dump_minmax_info( minmax );
663 SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
664 break;
665 }
666 case WM_NCCREATE:
667 {
668 BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
669 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
670
671 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
672 if (got_getminmaxinfo)
673 trace("%p got WM_GETMINMAXINFO\n", hwnd);
674
675 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
676 ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
677 else
678 ok(!got_getminmaxinfo, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
679 break;
680 }
681 }
682
683 return DefWindowProcA(hwnd, msg, wparam, lparam);
684 }
685
686 static BOOL RegisterWindowClasses(void)
687 {
688 WNDCLASSA cls;
689
690 cls.style = CS_DBLCLKS;
691 cls.lpfnWndProc = main_window_procA;
692 cls.cbClsExtra = 0;
693 cls.cbWndExtra = 0;
694 cls.hInstance = GetModuleHandleA(0);
695 cls.hIcon = 0;
696 cls.hCursor = LoadCursorA(0, IDC_ARROW);
697 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
698 cls.lpszMenuName = NULL;
699 cls.lpszClassName = "MainWindowClass";
700
701 if(!RegisterClassA(&cls)) return FALSE;
702
703 cls.style = 0;
704 cls.lpfnWndProc = tool_window_procA;
705 cls.cbClsExtra = 0;
706 cls.cbWndExtra = 0;
707 cls.hInstance = GetModuleHandleA(0);
708 cls.hIcon = 0;
709 cls.hCursor = LoadCursorA(0, IDC_ARROW);
710 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
711 cls.lpszMenuName = NULL;
712 cls.lpszClassName = "ToolWindowClass";
713
714 if(!RegisterClassA(&cls)) return FALSE;
715
716 return TRUE;
717 }
718
719 static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *info)
720 {
721 RECT rcWindow, rcClient;
722 DWORD status;
723
724 ok(IsWindow(hwnd), "bad window handle %p in hook %s\n", hwnd, hook);
725
726 GetWindowRect(hwnd, &rcWindow);
727 ok(EqualRect(&rcWindow, &info->rcWindow), "wrong rcWindow for %p in hook %s\n", hwnd, hook);
728
729 GetClientRect(hwnd, &rcClient);
730 /* translate to screen coordinates */
731 MapWindowPoints(hwnd, 0, (LPPOINT)&rcClient, 2);
732 ok(EqualRect(&rcClient, &info->rcClient), "wrong rcClient for %p in hook %s\n", hwnd, hook);
733
734 ok(info->dwStyle == (DWORD)GetWindowLongA(hwnd, GWL_STYLE),
735 "wrong dwStyle: %08x != %08x for %p in hook %s\n",
736 info->dwStyle, GetWindowLongA(hwnd, GWL_STYLE), hwnd, hook);
737 /* Windows reports some undocumented exstyles in WINDOWINFO, but
738 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
739 */
740 ok((info->dwExStyle & ~0xe0000800) == (DWORD)GetWindowLongA(hwnd, GWL_EXSTYLE),
741 "wrong dwExStyle: %08x != %08x for %p in hook %s\n",
742 info->dwExStyle, GetWindowLongA(hwnd, GWL_EXSTYLE), hwnd, hook);
743 status = (GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0;
744 if (GetForegroundWindow())
745 ok(info->dwWindowStatus == status, "wrong dwWindowStatus: %04x != %04x active %p fg %p in hook %s\n",
746 info->dwWindowStatus, status, GetActiveWindow(), GetForegroundWindow(), hook);
747
748 /* win2k and XP return broken border info in GetWindowInfo most of
749 * the time, so there is no point in testing it.
750 */
751 #if 0
752 UINT border;
753 ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
754 "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
755 border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
756 ok(info->cyWindowBorders == border,
757 "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
758 #endif
759 ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
760 hwnd, hook);
761 ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
762 info->wCreatorVersion == 0x0500 /* Vista */,
763 "wrong wCreatorVersion %04x for %p in hook %s\n", info->wCreatorVersion, hwnd, hook);
764 }
765
766 static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyle)
767 {
768 AdjustWindowRectEx(rc, style, menu, exstyle);
769 /* AdjustWindowRectEx does not include scroll bars */
770 if (style & WS_VSCROLL)
771 {
772 if(exstyle & WS_EX_LEFTSCROLLBAR)
773 rc->left -= GetSystemMetrics(SM_CXVSCROLL);
774 else
775 rc->right += GetSystemMetrics(SM_CXVSCROLL);
776 }
777 if (style & WS_HSCROLL)
778 rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
779 }
780
781 static void test_nonclient_area(HWND hwnd)
782 {
783 DWORD style, exstyle;
784 RECT rc_window, rc_client, rc;
785 BOOL menu;
786 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
787 LRESULT ret;
788
789 style = GetWindowLongA(hwnd, GWL_STYLE);
790 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
791 menu = !(style & WS_CHILD) && GetMenu(hwnd) != 0;
792
793 GetWindowRect(hwnd, &rc_window);
794 GetClientRect(hwnd, &rc_client);
795
796 /* avoid some cases when things go wrong */
797 if (IsRectEmpty(&rc_window) || IsRectEmpty(&rc_client) ||
798 rc_window.right > 32768 || rc_window.bottom > 32768) return;
799
800 CopyRect(&rc, &rc_client);
801 MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
802 FixedAdjustWindowRectEx(&rc, style, menu, exstyle);
803
804 ok(EqualRect(&rc, &rc_window),
805 "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
806 style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
807 rc.left, rc.top, rc.right, rc.bottom);
808
809
810 CopyRect(&rc, &rc_window);
811 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
812 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
813 ok(EqualRect(&rc, &rc_client),
814 "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
815 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
816 rc.left, rc.top, rc.right, rc.bottom);
817
818 /* NULL rectangle shouldn't crash */
819 ret = DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, 0);
820 ok(ret == 0, "NULL rectangle returned %ld instead of 0\n", ret);
821
822 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
823 if (is_win9x)
824 return;
825
826 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
827 SetRect(&rc_client, 0, 0, 250, 150);
828 CopyRect(&rc_window, &rc_client);
829 MapWindowPoints(hwnd, 0, (LPPOINT)&rc_window, 2);
830 FixedAdjustWindowRectEx(&rc_window, style, menu, exstyle);
831
832 CopyRect(&rc, &rc_window);
833 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
834 MapWindowPoints(0, hwnd, (LPPOINT)&rc, 2);
835 ok(EqualRect(&rc, &rc_client),
836 "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, client=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
837 style, exstyle, menu, rc_client.left, rc_client.top, rc_client.right, rc_client.bottom,
838 rc.left, rc.top, rc.right, rc.bottom);
839 }
840
841 static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
842 {
843 static const char *CBT_code_name[10] = {
844 "HCBT_MOVESIZE",
845 "HCBT_MINMAX",
846 "HCBT_QS",
847 "HCBT_CREATEWND",
848 "HCBT_DESTROYWND",
849 "HCBT_ACTIVATE",
850 "HCBT_CLICKSKIPPED",
851 "HCBT_KEYSKIPPED",
852 "HCBT_SYSCOMMAND",
853 "HCBT_SETFOCUS" };
854 const char *code_name = (nCode >= 0 && nCode <= HCBT_SETFOCUS) ? CBT_code_name[nCode] : "Unknown";
855 HWND hwnd = (HWND)wParam;
856
857 switch (nCode)
858 {
859 case HCBT_CREATEWND:
860 {
861 static const RECT rc_null;
862 RECT rc;
863 LONG style;
864 CBT_CREATEWNDA *createwnd = (CBT_CREATEWNDA *)lParam;
865 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
866 hwnd, createwnd->lpcs->hwndParent, createwnd->lpcs->style);
867 ok(createwnd->hwndInsertAfter == HWND_TOP, "hwndInsertAfter should be always HWND_TOP\n");
868
869 if (pGetWindowInfo)
870 {
871 WINDOWINFO info;
872 info.cbSize = sizeof(WINDOWINFO);
873 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
874 verify_window_info(code_name, hwnd, &info);
875 }
876
877 /* WS_VISIBLE should be turned off yet */
878 style = createwnd->lpcs->style & ~WS_VISIBLE;
879 ok(style == GetWindowLongA(hwnd, GWL_STYLE),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA(hwnd, GWL_STYLE), style);
882
883 if (0)
884 {
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
887 {
888 ok(GetParent(hwnd) == hwndMessage,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent(hwnd), hwndMessage);
891 }
892 else
893 ok(!GetParent(hwnd), "GetParent should return 0 at this point\n");
894
895 ok(!GetWindow(hwnd, GW_OWNER), "GW_OWNER should be set to 0 at this point\n");
896 }
897 if (0)
898 {
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
901 */
902 ok(GetWindow(hwnd, GW_HWNDFIRST) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow(hwnd, GW_HWNDLAST) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
904 }
905 ok(!GetWindow(hwnd, GW_HWNDPREV), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow(hwnd, GW_HWNDNEXT), "GW_HWNDNEXT should be set to 0 at this point\n");
907
908 if (0)
909 {
910 /* Uncomment this once the test succeeds in all cases */
911 if (pGetAncestor)
912 {
913 ok(pGetAncestor(hwnd, GA_PARENT) == hwndMessage, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor(hwnd, GA_ROOT) == hwnd,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOT), hwnd);
916
917 if ((style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
918 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwndMessage,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
920 else
921 ok(pGetAncestor(hwnd, GA_ROOTOWNER) == hwnd,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor(hwnd, GA_ROOTOWNER), hwnd);
923 }
924
925 ok(GetWindowRect(hwnd, &rc), "GetWindowRect failed\n");
926 ok(EqualRect(&rc, &rc_null), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect(hwnd, &rc), "GetClientRect failed\n");
928 ok(EqualRect(&rc, &rc_null), "client rect should be set to 0 on HCBT_CREATEWND\n");
929 }
930 break;
931 }
932 case HCBT_MOVESIZE:
933 case HCBT_MINMAX:
934 case HCBT_ACTIVATE:
935 case HCBT_SETFOCUS:
936 if (pGetWindowInfo && IsWindow(hwnd))
937 {
938 WINDOWINFO info;
939
940 /* Win98 actually does check the info.cbSize and doesn't allow
941 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
942 * WinXP do not check it at all.
943 */
944 info.cbSize = sizeof(WINDOWINFO);
945 ok(pGetWindowInfo(hwnd, &info), "GetWindowInfo should not fail\n");
946 verify_window_info(code_name, hwnd, &info);
947 }
948 break;
949 /* on HCBT_DESTROYWND window state is undefined */
950 case HCBT_DESTROYWND:
951 trace( "HCBT_DESTROYWND: hwnd %p\n", hwnd );
952 break;
953 default:
954 break;
955 }
956
957 return CallNextHookEx(hhook, nCode, wParam, lParam);
958 }
959
960 static void test_shell_window(void)
961 {
962 BOOL ret;
963 DWORD error;
964 HMODULE hinst, hUser32;
965 BOOL (WINAPI*SetShellWindow)(HWND);
966 BOOL (WINAPI*SetShellWindowEx)(HWND, HWND);
967 HWND hwnd1, hwnd2, hwnd3, hwnd4, hwnd5;
968 HWND shellWindow, nextWnd;
969
970 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE))
971 {
972 trace("Skipping shell window test on Win9x\n");
973 return;
974 }
975
976 shellWindow = GetShellWindow();
977 hinst = GetModuleHandle(0);
978 hUser32 = GetModuleHandleA("user32");
979
980 SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
981 SetShellWindowEx = (void *)GetProcAddress(hUser32, "SetShellWindowEx");
982
983 trace("previous shell window: %p\n", shellWindow);
984
985 if (shellWindow) {
986 DWORD pid;
987 HANDLE hProcess;
988
989 GetWindowThreadProcessId(shellWindow, &pid);
990 hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
991 if (!hProcess)
992 {
993 skip( "cannot get access to shell process\n" );
994 return;
995 }
996
997 SetLastError(0xdeadbeef);
998 ret = DestroyWindow(shellWindow);
999 error = GetLastError();
1000
1001 ok(!ret, "DestroyWindow(shellWindow)\n");
1002 /* passes on Win XP, but not on Win98 */
1003 ok(error==ERROR_ACCESS_DENIED || error == 0xdeadbeef,
1004 "got %u after DestroyWindow(shellWindow)\n", error);
1005
1006 /* close old shell instance */
1007 ret = TerminateProcess(hProcess, 0);
1008 ok(ret, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
1009 WaitForSingleObject(hProcess, INFINITE); /* wait for termination */
1010 CloseHandle(hProcess);
1011 }
1012
1013 hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
1014 trace("created window 1: %p\n", hwnd1);
1015
1016 ret = SetShellWindow(hwnd1);
1017 ok(ret, "first call to SetShellWindow(hwnd1)\n");
1018 shellWindow = GetShellWindow();
1019 ok(shellWindow==hwnd1, "wrong shell window: %p\n", shellWindow);
1020
1021 ret = SetShellWindow(hwnd1);
1022 ok(!ret, "second call to SetShellWindow(hwnd1)\n");
1023
1024 ret = SetShellWindow(0);
1025 error = GetLastError();
1026 /* passes on Win XP, but not on Win98
1027 ok(!ret, "reset shell window by SetShellWindow(0)\n");
1028 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
1029
1030 ret = SetShellWindow(hwnd1);
1031 /* passes on Win XP, but not on Win98
1032 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1033
1034 SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
1035 ret = GetWindowLong(hwnd1,GWL_EXSTYLE)&WS_EX_TOPMOST? TRUE: FALSE;
1036 ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1037
1038 ret = DestroyWindow(hwnd1);
1039 ok(ret, "DestroyWindow(hwnd1)\n");
1040
1041 hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
1042 trace("created window 2: %p\n", hwnd2);
1043 ret = SetShellWindow(hwnd2);
1044 ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1045
1046 hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
1047 trace("created window 3: %p\n", hwnd3);
1048
1049 hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
1050 trace("created window 4: %p\n", hwnd4);
1051
1052 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1053 ok(nextWnd==hwnd3, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd);
1054
1055 ret = SetShellWindow(hwnd4);
1056 ok(ret, "SetShellWindow(hwnd4)\n");
1057 shellWindow = GetShellWindow();
1058 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1059
1060 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1061 ok(nextWnd==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd);
1062
1063 ret = SetWindowPos(hwnd4, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1064 ok(ret, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1065
1066 ret = SetWindowPos(hwnd4, hwnd3, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1067 ok(ret, "SetWindowPos(hwnd4, hwnd3\n");
1068
1069 ret = SetShellWindow(hwnd3);
1070 ok(!ret, "SetShellWindow(hwnd3)\n");
1071 shellWindow = GetShellWindow();
1072 ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
1073
1074 hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
1075 trace("created window 5: %p\n", hwnd5);
1076 ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1077 ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
1078
1079 todo_wine
1080 {
1081 nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
1082 ok(nextWnd==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd);
1083 }
1084
1085 /* destroy test windows */
1086 DestroyWindow(hwnd2);
1087 DestroyWindow(hwnd3);
1088 DestroyWindow(hwnd4);
1089 DestroyWindow(hwnd5);
1090 }
1091
1092 /************** MDI test ****************/
1093
1094 static char mdi_lParam_test_message[] = "just a test string";
1095
1096 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
1097 {
1098 MDICREATESTRUCTA mdi_cs;
1099 HWND mdi_child;
1100 INT_PTR id;
1101 static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1102 static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
1103 BOOL isWin9x = FALSE;
1104
1105 mdi_cs.szClass = "MDI_child_Class_1";
1106 mdi_cs.szTitle = "MDI child";
1107 mdi_cs.hOwner = GetModuleHandle(0);
1108 mdi_cs.x = CW_USEDEFAULT;
1109 mdi_cs.y = CW_USEDEFAULT;
1110 mdi_cs.cx = CW_USEDEFAULT;
1111 mdi_cs.cy = CW_USEDEFAULT;
1112 mdi_cs.style = 0;
1113 mdi_cs.lParam = (LPARAM)mdi_lParam_test_message;
1114 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1115 ok(mdi_child != 0, "MDI child creation failed\n");
1116 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1117 ok(id == first_id, "wrong child id %ld\n", id);
1118 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1119 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1120
1121 mdi_cs.style = 0x7fffffff; /* without WS_POPUP */
1122 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1123 ok(mdi_child != 0, "MDI child creation failed\n");
1124 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1125 ok(id == first_id, "wrong child id %ld\n", id);
1126 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1127 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1128
1129 mdi_cs.style = 0xffffffff; /* with WS_POPUP */
1130 mdi_child = (HWND)SendMessageA(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1131 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1132 {
1133 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1134 }
1135 else
1136 {
1137 ok(mdi_child != 0, "MDI child creation failed\n");
1138 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1139 ok(id == first_id, "wrong child id %ld\n", id);
1140 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1141 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1142 }
1143
1144 /* test MDICREATESTRUCT A<->W mapping */
1145 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1146 mdi_cs.style = 0;
1147 mdi_cs.szClass = (LPCSTR)classW;
1148 mdi_cs.szTitle = (LPCSTR)titleW;
1149 SetLastError(0xdeadbeef);
1150 mdi_child = (HWND)SendMessageW(mdi_client, WM_MDICREATE, 0, (LPARAM)&mdi_cs);
1151 if (!mdi_child)
1152 {
1153 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1154 isWin9x = TRUE;
1155 else
1156 ok(mdi_child != 0, "MDI child creation failed\n");
1157 }
1158 else
1159 {
1160 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1161 ok(id == first_id, "wrong child id %ld\n", id);
1162 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1163 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1164 }
1165
1166 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1167 0,
1168 CW_USEDEFAULT, CW_USEDEFAULT,
1169 CW_USEDEFAULT, CW_USEDEFAULT,
1170 mdi_client, GetModuleHandle(0),
1171 (LPARAM)mdi_lParam_test_message);
1172 ok(mdi_child != 0, "MDI child creation failed\n");
1173 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1174 ok(id == first_id, "wrong child id %ld\n", id);
1175 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1176 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1177
1178 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1179 0x7fffffff, /* without WS_POPUP */
1180 CW_USEDEFAULT, CW_USEDEFAULT,
1181 CW_USEDEFAULT, CW_USEDEFAULT,
1182 mdi_client, GetModuleHandle(0),
1183 (LPARAM)mdi_lParam_test_message);
1184 ok(mdi_child != 0, "MDI child creation failed\n");
1185 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1186 ok(id == first_id, "wrong child id %ld\n", id);
1187 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1188 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1189
1190 mdi_child = CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1191 0xffffffff, /* with WS_POPUP */
1192 CW_USEDEFAULT, CW_USEDEFAULT,
1193 CW_USEDEFAULT, CW_USEDEFAULT,
1194 mdi_client, GetModuleHandle(0),
1195 (LPARAM)mdi_lParam_test_message);
1196 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1197 {
1198 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1199 }
1200 else
1201 {
1202 ok(mdi_child != 0, "MDI child creation failed\n");
1203 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1204 ok(id == first_id, "wrong child id %ld\n", id);
1205 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1206 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1207 }
1208
1209 /* test MDICREATESTRUCT A<->W mapping */
1210 SetLastError(0xdeadbeef);
1211 mdi_child = CreateMDIWindowW(classW, titleW,
1212 0,
1213 CW_USEDEFAULT, CW_USEDEFAULT,
1214 CW_USEDEFAULT, CW_USEDEFAULT,
1215 mdi_client, GetModuleHandle(0),
1216 (LPARAM)mdi_lParam_test_message);
1217 if (!mdi_child)
1218 {
1219 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1220 isWin9x = TRUE;
1221 else
1222 ok(mdi_child != 0, "MDI child creation failed\n");
1223 }
1224 else
1225 {
1226 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1227 ok(id == first_id, "wrong child id %ld\n", id);
1228 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1229 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1230 }
1231
1232 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1233 0,
1234 CW_USEDEFAULT, CW_USEDEFAULT,
1235 CW_USEDEFAULT, CW_USEDEFAULT,
1236 mdi_client, 0, GetModuleHandle(0),
1237 mdi_lParam_test_message);
1238 ok(mdi_child != 0, "MDI child creation failed\n");
1239 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1240 ok(id == first_id, "wrong child id %ld\n", id);
1241 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1242 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1243
1244 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1245 0x7fffffff, /* without WS_POPUP */
1246 CW_USEDEFAULT, CW_USEDEFAULT,
1247 CW_USEDEFAULT, CW_USEDEFAULT,
1248 mdi_client, 0, GetModuleHandle(0),
1249 mdi_lParam_test_message);
1250 ok(mdi_child != 0, "MDI child creation failed\n");
1251 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1252 ok(id == first_id, "wrong child id %ld\n", id);
1253 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1254 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1255
1256 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
1257 0xffffffff, /* with WS_POPUP */
1258 CW_USEDEFAULT, CW_USEDEFAULT,
1259 CW_USEDEFAULT, CW_USEDEFAULT,
1260 mdi_client, 0, GetModuleHandle(0),
1261 mdi_lParam_test_message);
1262 if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1263 {
1264 ok(!mdi_child, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1265 }
1266 else
1267 {
1268 ok(mdi_child != 0, "MDI child creation failed\n");
1269 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1270 ok(id == first_id, "wrong child id %ld\n", id);
1271 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1272 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1273 }
1274
1275 /* test MDICREATESTRUCT A<->W mapping */
1276 SetLastError(0xdeadbeef);
1277 mdi_child = CreateWindowExW(WS_EX_MDICHILD, classW, titleW,
1278 0,
1279 CW_USEDEFAULT, CW_USEDEFAULT,
1280 CW_USEDEFAULT, CW_USEDEFAULT,
1281 mdi_client, 0, GetModuleHandle(0),
1282 mdi_lParam_test_message);
1283 if (!mdi_child)
1284 {
1285 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1286 isWin9x = TRUE;
1287 else
1288 ok(mdi_child != 0, "MDI child creation failed\n");
1289 }
1290 else
1291 {
1292 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1293 ok(id == first_id, "wrong child id %ld\n", id);
1294 SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
1295 ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
1296 }
1297
1298 /* This test fails on Win9x */
1299 if (!isWin9x)
1300 {
1301 mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_2", "MDI child",
1302 WS_CHILD,
1303 CW_USEDEFAULT, CW_USEDEFAULT,
1304 CW_USEDEFAULT, CW_USEDEFAULT,
1305 parent, 0, GetModuleHandle(0),
1306 mdi_lParam_test_message);
1307 ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1308 }
1309
1310 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1311 WS_CHILD, /* without WS_POPUP */
1312 CW_USEDEFAULT, CW_USEDEFAULT,
1313 CW_USEDEFAULT, CW_USEDEFAULT,
1314 mdi_client, 0, GetModuleHandle(0),
1315 mdi_lParam_test_message);
1316 ok(mdi_child != 0, "MDI child creation failed\n");
1317 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1318 ok(id == 0, "wrong child id %ld\n", id);
1319 DestroyWindow(mdi_child);
1320
1321 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1322 WS_CHILD | WS_POPUP, /* with WS_POPUP */
1323 CW_USEDEFAULT, CW_USEDEFAULT,
1324 CW_USEDEFAULT, CW_USEDEFAULT,
1325 mdi_client, 0, GetModuleHandle(0),
1326 mdi_lParam_test_message);
1327 ok(mdi_child != 0, "MDI child creation failed\n");
1328 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1329 ok(id == 0, "wrong child id %ld\n", id);
1330 DestroyWindow(mdi_child);
1331
1332 /* maximized child */
1333 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1334 WS_CHILD | WS_MAXIMIZE,
1335 CW_USEDEFAULT, CW_USEDEFAULT,
1336 CW_USEDEFAULT, CW_USEDEFAULT,
1337 mdi_client, 0, GetModuleHandle(0),
1338 mdi_lParam_test_message);
1339 ok(mdi_child != 0, "MDI child creation failed\n");
1340 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1341 ok(id == 0, "wrong child id %ld\n", id);
1342 DestroyWindow(mdi_child);
1343
1344 trace("Creating maximized child with a caption\n");
1345 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1346 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
1347 CW_USEDEFAULT, CW_USEDEFAULT,
1348 CW_USEDEFAULT, CW_USEDEFAULT,
1349 mdi_client, 0, GetModuleHandle(0),
1350 mdi_lParam_test_message);
1351 ok(mdi_child != 0, "MDI child creation failed\n");
1352 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1353 ok(id == 0, "wrong child id %ld\n", id);
1354 DestroyWindow(mdi_child);
1355
1356 trace("Creating maximized child with a caption and a thick frame\n");
1357 mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1358 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
1359 CW_USEDEFAULT, CW_USEDEFAULT,
1360 CW_USEDEFAULT, CW_USEDEFAULT,
1361 mdi_client, 0, GetModuleHandle(0),
1362 mdi_lParam_test_message);
1363 ok(mdi_child != 0, "MDI child creation failed\n");
1364 id = GetWindowLongPtrA(mdi_child, GWLP_ID);
1365 ok(id == 0, "wrong child id %ld\n", id);
1366 DestroyWindow(mdi_child);
1367 }
1368
1369 /**********************************************************************
1370 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1371 *
1372 * Note: The rule here is that client rect of the maximized MDI child
1373 * is equal to the client rect of the MDI client window.
1374 */
1375 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
1376 {
1377 RECT rect;
1378
1379 GetClientRect( client, &rect );
1380 AdjustWindowRectEx( &rect, GetWindowLongA( hwnd, GWL_STYLE ),
1381 0, GetWindowLongA( hwnd, GWL_EXSTYLE ));
1382
1383 rect.right -= rect.left;
1384 rect.bottom -= rect.top;
1385 lpMinMax->ptMaxSize.x = rect.right;
1386 lpMinMax->ptMaxSize.y = rect.bottom;
1387
1388 lpMinMax->ptMaxPosition.x = rect.left;
1389 lpMinMax->ptMaxPosition.y = rect.top;
1390
1391 trace("max rect (%d,%d - %d, %d)\n",
1392 rect.left, rect.top, rect.right, rect.bottom);
1393 }
1394
1395 static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1396 {
1397 switch (msg)
1398 {
1399 case WM_NCCREATE:
1400 case WM_CREATE:
1401 {
1402 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1403 MDICREATESTRUCTA *mdi_cs = cs->lpCreateParams;
1404
1405 ok(cs->dwExStyle & WS_EX_MDICHILD, "WS_EX_MDICHILD should be set\n");
1406 ok(mdi_cs->lParam == (LPARAM)mdi_lParam_test_message, "wrong mdi_cs->lParam\n");
1407
1408 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_1"), "wrong class name\n");
1409 ok(!lstrcmpA(cs->lpszClass, mdi_cs->szClass), "class name does not match\n");
1410 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1411 ok(!lstrcmpA(cs->lpszName, mdi_cs->szTitle), "title does not match\n");
1412 ok(cs->hInstance == mdi_cs->hOwner, "%p != %p\n", cs->hInstance, mdi_cs->hOwner);
1413
1414 /* MDICREATESTRUCT should have original values */
1415 ok(mdi_cs->style == 0 || mdi_cs->style == 0x7fffffff || mdi_cs->style == 0xffffffff,
1416 "mdi_cs->style does not match (%08x)\n", mdi_cs->style);
1417 ok(mdi_cs->x == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->x);
1418 ok(mdi_cs->y == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->y);
1419 ok(mdi_cs->cx == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cx);
1420 ok(mdi_cs->cy == CW_USEDEFAULT, "%d != CW_USEDEFAULT\n", mdi_cs->cy);
1421
1422 /* CREATESTRUCT should have fixed values */
1423 ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);
1424 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1425
1426 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1427 ok(cs->cx != CW_USEDEFAULT && cs->cx != 0, "%d == CW_USEDEFAULT\n", cs->cx);
1428 ok(cs->cy != CW_USEDEFAULT && cs->cy != 0, "%d == CW_USEDEFAULT\n", cs->cy);
1429
1430 ok(!(cs->style & WS_POPUP), "WS_POPUP is not allowed\n");
1431
1432 if (GetWindowLongA(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1433 {
1434 LONG style = mdi_cs->style | WS_CHILD | WS_CLIPSIBLINGS;
1435 ok(cs->style == style,
1436 "cs->style does not match (%08x)\n", cs->style);
1437 }
1438 else
1439 {
1440 LONG style = mdi_cs->style;
1441 style &= ~WS_POPUP;
1442 style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1443 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1444 ok(cs->style == style,
1445 "cs->style does not match (%08x)\n", cs->style);
1446 }
1447 break;
1448 }
1449
1450 case WM_GETMINMAXINFO:
1451 {
1452 HWND client = GetParent(hwnd);
1453 RECT rc;
1454 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1455 MINMAXINFO my_minmax;
1456 LONG style, exstyle;
1457
1458 style = GetWindowLongA(hwnd, GWL_STYLE);
1459 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1460
1461 GetWindowRect(client, &rc);
1462 trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
1463 GetClientRect(client, &rc);
1464 trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
1465 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
1466 GetSystemMetrics(SM_CYSCREEN));
1467
1468 GetClientRect(client, &rc);
1469 if ((style & WS_CAPTION) == WS_CAPTION)
1470 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1471 AdjustWindowRectEx(&rc, style, 0, exstyle);
1472 trace("MDI child: calculated max window size = (%d x %d)\n", rc.right-rc.left, rc.bottom-rc.top);
1473 dump_minmax_info( minmax );
1474
1475 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1476 minmax->ptMaxSize.x, rc.right - rc.left);
1477 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1478 minmax->ptMaxSize.y, rc.bottom - rc.top);
1479
1480 DefMDIChildProcA(hwnd, msg, wparam, lparam);
1481
1482 trace("DefMDIChildProc returned:\n");
1483 dump_minmax_info( minmax );
1484
1485 MDI_ChildGetMinMaxInfo(client, hwnd, &my_minmax);
1486 ok(minmax->ptMaxSize.x == my_minmax.ptMaxSize.x, "default width of maximized child %d != %d\n",
1487 minmax->ptMaxSize.x, my_minmax.ptMaxSize.x);
1488 ok(minmax->ptMaxSize.y == my_minmax.ptMaxSize.y, "default height of maximized child %d != %d\n",
1489 minmax->ptMaxSize.y, my_minmax.ptMaxSize.y);
1490
1491 return 1;
1492 }
1493
1494 case WM_MDIACTIVATE:
1495 {
1496 HWND active, client = GetParent(hwnd);
1497 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1498 active = (HWND)SendMessageA(client, WM_MDIGETACTIVE, 0, 0);
1499 if (hwnd == (HWND)lparam) /* if we are being activated */
1500 ok (active == (HWND)lparam, "new active %p != active %p\n", (HWND)lparam, active);
1501 else
1502 ok (active == (HWND)wparam, "old active %p != active %p\n", (HWND)wparam, active);
1503 break;
1504 }
1505 }
1506 return DefMDIChildProcA(hwnd, msg, wparam, lparam);
1507 }
1508
1509 static LRESULT WINAPI mdi_child_wnd_proc_2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1510 {
1511 switch (msg)
1512 {
1513 case WM_NCCREATE:
1514 case WM_CREATE:
1515 {
1516 CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
1517
1518 trace("%s: x %d, y %d, cx %d, cy %d\n", (msg == WM_NCCREATE) ? "WM_NCCREATE" : "WM_CREATE",
1519 cs->x, cs->y, cs->cx, cs->cy);
1520
1521 ok(!(cs->dwExStyle & WS_EX_MDICHILD), "WS_EX_MDICHILD should not be set\n");
1522 ok(cs->lpCreateParams == mdi_lParam_test_message, "wrong cs->lpCreateParams\n");
1523
1524 ok(!lstrcmpA(cs->lpszClass, "MDI_child_Class_2"), "wrong class name\n");
1525 ok(!lstrcmpA(cs->lpszName, "MDI child"), "wrong title\n");
1526
1527 /* CREATESTRUCT should have fixed values */
1528 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1529 while NT does. */
1530 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1531 ok(cs->y != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->y);
1532
1533 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1534 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1535 while Win95, Win2k, WinXP do. */
1536 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1537 ok(cs->cy == 0, "%d != 0\n", cs->cy);
1538 break;
1539 }
1540
1541 case WM_GETMINMAXINFO:
1542 {
1543 HWND parent = GetParent(hwnd);
1544 RECT rc;
1545 MINMAXINFO *minmax = (MINMAXINFO *)lparam;
1546 LONG style, exstyle;
1547
1548 style = GetWindowLongA(hwnd, GWL_STYLE);
1549 exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
1550
1551 GetClientRect(parent, &rc);
1552 trace("WM_GETMINMAXINFO: parent %p client size = (%d x %d)\n", parent, rc.right, rc.bottom);
1553
1554 GetClientRect(parent, &rc);
1555 if ((style & WS_CAPTION) == WS_CAPTION)
1556 style &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1557 AdjustWindowRectEx(&rc, style, 0, exstyle);
1558 dump_minmax_info( minmax );
1559
1560 ok(minmax->ptMaxSize.x == rc.right - rc.left, "default width of maximized child %d != %d\n",
1561 minmax->ptMaxSize.x, rc.right - rc.left);
1562 ok(minmax->ptMaxSize.y == rc.bottom - rc.top, "default height of maximized child %d != %d\n",
1563 minmax->ptMaxSize.y, rc.bottom - rc.top);
1564 break;
1565 }
1566
1567 case WM_WINDOWPOSCHANGED:
1568 {
1569 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1570 RECT rc1, rc2;
1571
1572 GetWindowRect(hwnd, &rc1);
1573 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1574 /* note: winpos coordinates are relative to parent */
1575 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1576 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) pos=(%d,%d)-(%d,%d)\n",
1577 rc1.left, rc1.top, rc1.right, rc1.bottom,
1578 rc2.left, rc2.top, rc2.right, rc2.bottom);
1579 GetWindowRect(hwnd, &rc1);
1580 GetClientRect(hwnd, &rc2);
1581 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1582 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1583 ok(EqualRect(&rc1, &rc2), "rects do not match, window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1584 rc1.left, rc1.top, rc1.right, rc1.bottom,
1585 rc2.left, rc2.top, rc2.right, rc2.bottom);
1586 }
1587 /* fall through */
1588 case WM_WINDOWPOSCHANGING:
1589 {
1590 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1591 WINDOWPOS my_winpos = *winpos;
1592
1593 trace("%s: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1594 (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED",
1595 winpos->hwnd, winpos->hwndInsertAfter,
1596 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1597
1598 DefWindowProcA(hwnd, msg, wparam, lparam);
1599
1600 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1601 "DefWindowProc should not change WINDOWPOS: %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1602 winpos->hwnd, winpos->hwndInsertAfter,
1603 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1604
1605 return 1;
1606 }
1607 }
1608 return DefWindowProcA(hwnd, msg, wparam, lparam);
1609 }
1610
1611 static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1612 {
1613 static HWND mdi_client;
1614
1615 switch (msg)
1616 {
1617 case WM_CREATE:
1618 {
1619 CLIENTCREATESTRUCT client_cs;
1620 RECT rc;
1621
1622 GetClientRect(hwnd, &rc);
1623
1624 client_cs.hWindowMenu = 0;
1625 client_cs.idFirstChild = 1;
1626
1627 /* MDIClient without MDIS_ALLCHILDSTYLES */
1628 mdi_client = CreateWindowExA(0, "mdiclient",
1629 NULL,
1630 WS_CHILD /*| WS_VISIBLE*/,
1631 /* tests depend on a not zero MDIClient size */
1632 0, 0, rc.right, rc.bottom,
1633 hwnd, 0, GetModuleHandle(0),
1634 &client_cs);
1635 assert(mdi_client);
1636 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1637 DestroyWindow(mdi_client);
1638
1639 /* MDIClient with MDIS_ALLCHILDSTYLES */
1640 mdi_client = CreateWindowExA(0, "mdiclient",
1641 NULL,
1642 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
1643 /* tests depend on a not zero MDIClient size */
1644 0, 0, rc.right, rc.bottom,
1645 hwnd, 0, GetModuleHandle(0),
1646 &client_cs);
1647 assert(mdi_client);
1648 test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
1649 DestroyWindow(mdi_client);
1650 break;
1651 }
1652
1653 case WM_WINDOWPOSCHANGED:
1654 {
1655 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1656 RECT rc1, rc2;
1657
1658 GetWindowRect(hwnd, &rc1);
1659 trace("window: (%d,%d)-(%d,%d)\n", rc1.left, rc1.top, rc1.right, rc1.bottom);
1660 SetRect(&rc2, winpos->x, winpos->y, winpos->x + winpos->cx, winpos->y + winpos->cy);
1661 /* note: winpos coordinates are relative to parent */
1662 MapWindowPoints(GetParent(hwnd), 0, (LPPOINT)&rc2, 2);
1663 trace("pos: (%d,%d)-(%d,%d)\n", rc2.left, rc2.top, rc2.right, rc2.bottom);
1664 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1665
1666 GetWindowRect(hwnd, &rc1);
1667 GetClientRect(hwnd, &rc2);
1668 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc1);
1669 MapWindowPoints(0, hwnd, (LPPOINT)&rc1, 2);
1670 ok(EqualRect(&rc1, &rc2), "rects do not match\n");
1671 }
1672 /* fall through */
1673 case WM_WINDOWPOSCHANGING:
1674 {
1675 WINDOWPOS *winpos = (WINDOWPOS *)lparam;
1676 WINDOWPOS my_winpos = *winpos;
1677
1678 trace("%s\n", (msg == WM_WINDOWPOSCHANGING) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1679 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1680 winpos->hwnd, winpos->hwndInsertAfter,
1681 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1682
1683 DefWindowProcA(hwnd, msg, wparam, lparam);
1684
1685 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1686 winpos->hwnd, winpos->hwndInsertAfter,
1687 winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
1688
1689 ok(!memcmp(&my_winpos, winpos, sizeof(WINDOWPOS)),
1690 "DefWindowProc should not change WINDOWPOS values\n");
1691
1692 return 1;
1693 }
1694
1695 case WM_CLOSE:
1696 PostQuitMessage(0);
1697 break;
1698 }
1699 return DefFrameProcA(hwnd, mdi_client, msg, wparam, lparam);
1700 }
1701
1702 static BOOL mdi_RegisterWindowClasses(void)
1703 {
1704 WNDCLASSA cls;
1705
1706 cls.style = 0;
1707 cls.lpfnWndProc = mdi_main_wnd_procA;
1708 cls.cbClsExtra = 0;
1709 cls.cbWndExtra = 0;
1710 cls.hInstance = GetModuleHandleA(0);
1711 cls.hIcon = 0;
1712 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1713 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1714 cls.lpszMenuName = NULL;
1715 cls.lpszClassName = "MDI_parent_Class";
1716 if(!RegisterClassA(&cls)) return FALSE;
1717
1718 cls.lpfnWndProc = mdi_child_wnd_proc_1;
1719 cls.lpszClassName = "MDI_child_Class_1";
1720 if(!RegisterClassA(&cls)) return FALSE;
1721
1722 cls.lpfnWndProc = mdi_child_wnd_proc_2;
1723 cls.lpszClassName = "MDI_child_Class_2";
1724 if(!RegisterClassA(&cls)) return FALSE;
1725
1726 return TRUE;
1727 }
1728
1729 static void test_mdi(void)
1730 {
1731 HWND mdi_hwndMain;
1732 /*MSG msg;*/
1733
1734 if (!mdi_RegisterWindowClasses()) assert(0);
1735
1736 mdi_hwndMain = CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1737 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
1738 WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
1739 100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
1740 GetDesktopWindow(), 0,
1741 GetModuleHandle(0), NULL);
1742 assert(mdi_hwndMain);
1743 /*
1744 while(GetMessage(&msg, 0, 0, 0))
1745 {
1746 TranslateMessage(&msg);
1747 DispatchMessage(&msg);
1748 }
1749 */
1750 DestroyWindow(mdi_hwndMain);
1751 }
1752
1753 static void test_icons(void)
1754 {
1755 WNDCLASSEXA cls;
1756 HWND hwnd;
1757 HICON icon = LoadIconA(0, IDI_APPLICATION);
1758 HICON icon2 = LoadIconA(0, IDI_QUESTION);
1759 HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
1760 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
1761 HICON res;
1762
1763 cls.cbSize = sizeof(cls);
1764 cls.style = 0;
1765 cls.lpfnWndProc = DefWindowProcA;
1766 cls.cbClsExtra = 0;
1767 cls.cbWndExtra = 0;
1768 cls.hInstance = 0;
1769 cls.hIcon = LoadIconA(0, IDI_HAND);
1770 cls.hIconSm = small_icon;
1771 cls.hCursor = LoadCursorA(0, IDC_ARROW);
1772 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
1773 cls.lpszMenuName = NULL;
1774 cls.lpszClassName = "IconWindowClass";
1775
1776 RegisterClassExA(&cls);
1777
1778 hwnd = CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1779 100, 100, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL);
1780 assert( hwnd );
1781
1782 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1783 ok( res == 0, "wrong big icon %p/0\n", res );
1784 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon );
1785 ok( res == 0, "wrong previous big icon %p/0\n", res );
1786 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1787 ok( res == icon, "wrong big icon after set %p/%p\n", res, icon );
1788 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon2 );
1789 ok( res == icon, "wrong previous big icon %p/%p\n", res, icon );
1790 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1791 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1792
1793 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1794 ok( res == 0, "wrong small icon %p/0\n", res );
1795 /* this test is XP specific */
1796 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1797 ok( res != 0, "wrong small icon %p\n", res );*/
1798 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
1799 ok( res == 0, "wrong previous small icon %p/0\n", res );
1800 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1801 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
1802 /* this test is XP specific */
1803 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1804 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1805 res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
1806 ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
1807 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
1808 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
1809 /* this test is XP specific */
1810 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1811 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1812
1813 /* make sure the big icon hasn't changed */
1814 res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
1815 ok( res == icon2, "wrong big icon after set %p/%p\n", res, icon2 );
1816
1817 DestroyWindow( hwnd );
1818 }
1819
1820 static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
1821 {
1822 if (msg == WM_NCCALCSIZE)
1823 {
1824 RECT *rect = (RECT *)lparam;
1825 /* first time around increase the rectangle, next time decrease it */
1826 if (rect->left == 100) InflateRect( rect, 10, 10 );
1827 else InflateRect( rect, -10, -10 );
1828 return 0;
1829 }
1830 return DefWindowProc( hwnd, msg, wparam, lparam );
1831 }
1832
1833 static void test_SetWindowPos(HWND hwnd)
1834 {
1835 RECT orig_win_rc, rect;
1836 LONG_PTR old_proc;
1837 BOOL is_win9x = GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == 0;
1838
1839 SetRect(&rect, 111, 222, 333, 444);
1840 ok(!GetWindowRect(0, &rect), "GetWindowRect succeeded\n");
1841 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1842 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1843
1844 SetRect(&rect, 111, 222, 333, 444);
1845 ok(!GetClientRect(0, &rect), "GetClientRect succeeded\n");
1846 ok(rect.left == 111 && rect.top == 222 && rect.right == 333 && rect.bottom == 444,
1847 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1848
1849 GetWindowRect(hwnd, &orig_win_rc);
1850
1851 old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
1852 SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1853 GetWindowRect( hwnd, &rect );
1854 ok( rect.left == 100 && rect.top == 100 && rect.right == 100 && rect.bottom == 100,
1855 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1856 GetClientRect( hwnd, &rect );
1857 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1858 ok( rect.left == 90 && rect.top == 90 && rect.right == 110 && rect.bottom == 110,
1859 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1860
1861 SetWindowPos(hwnd, 0, 200, 200, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
1862 GetWindowRect( hwnd, &rect );
1863 ok( rect.left == 200 && rect.top == 200 && rect.right == 200 && rect.bottom == 200,
1864 "invalid window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1865 GetClientRect( hwnd, &rect );
1866 MapWindowPoints( hwnd, 0, (POINT *)&rect, 2 );
1867 ok( rect.left == 210 && rect.top == 210 && rect.right == 190 && rect.bottom == 190,
1868 "invalid client rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
1869
1870 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1871 orig_win_rc.right, orig_win_rc.bottom, 0);
1872 SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
1873
1874 /* Win9x truncates coordinates to 16-bit irrespectively */
1875 if (!is_win9x)
1876 {
1877 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE);
1878 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE);
1879
1880 SetWindowPos(hwnd, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE);
1881 SetWindowPos(hwnd, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE);
1882 }
1883
1884 SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
1885 orig_win_rc.right, orig_win_rc.bottom, 0);
1886
1887 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1888 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1889 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1890 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1891 ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
1892 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
1893 ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
1894 }
1895
1896 static void test_SetMenu(HWND parent)
1897 {
1898 HWND child;
1899 HMENU hMenu, ret;
1900 BOOL is_win9x = GetWindowLongPtrW(parent, GWLP_WNDPROC) == 0;
1901 BOOL retok;
1902 DWORD style;
1903
1904 hMenu = CreateMenu();
1905 assert(hMenu);
1906
1907 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1908 if (0)
1909 {
1910 /* fails on (at least) Wine, NT4, XP SP2 */
1911 test_nonclient_area(parent);
1912 }
1913 ret = GetMenu(parent);
1914 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1915 /* test whether we can destroy a menu assigned to a window */
1916 retok = DestroyMenu(hMenu);
1917 ok( retok, "DestroyMenu error %d\n", GetLastError());
1918 retok = IsMenu(hMenu);
1919 ok(!retok || broken(retok) /* nt4 */, "menu handle should be not valid after DestroyMenu\n");
1920 ret = GetMenu(parent);
1921 /* This test fails on Win9x */
1922 if (!is_win9x)
1923 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1924 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1925 test_nonclient_area(parent);
1926
1927 hMenu = CreateMenu();
1928 assert(hMenu);
1929
1930 /* parent */
1931 ret = GetMenu(parent);
1932 ok(ret == 0, "unexpected menu id %p\n", ret);
1933
1934 ok(!SetMenu(parent, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1935 test_nonclient_area(parent);
1936 ret = GetMenu(parent);
1937 ok(ret == 0, "unexpected menu id %p\n", ret);
1938
1939 ok(SetMenu(parent, hMenu), "SetMenu on a top level window should not fail\n");
1940 if (0)
1941 {
1942 /* fails on (at least) Wine, NT4, XP SP2 */
1943 test_nonclient_area(parent);
1944 }
1945 ret = GetMenu(parent);
1946 ok(ret == hMenu, "unexpected menu id %p\n", ret);
1947
1948 ok(SetMenu(parent, 0), "SetMenu(0) on a top level window should not fail\n");
1949 test_nonclient_area(parent);
1950 ret = GetMenu(parent);
1951 ok(ret == 0, "unexpected menu id %p\n", ret);
1952
1953 /* child */
1954 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, parent, (HMENU)10, 0, NULL);
1955 assert(child);
1956
1957 ret = GetMenu(child);
1958 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1959
1960 ok(!SetMenu(child, (HMENU)20), "SetMenu with invalid menu handle should fail\n");
1961 test_nonclient_area(child);
1962 ret = GetMenu(child);
1963 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1964
1965 ok(!SetMenu(child, hMenu), "SetMenu on a child window should fail\n");
1966 test_nonclient_area(child);
1967 ret = GetMenu(child);
1968 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1969
1970 ok(!SetMenu(child, 0), "SetMenu(0) on a child window should fail\n");
1971 test_nonclient_area(child);
1972 ret = GetMenu(child);
1973 ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
1974
1975 style = GetWindowLong(child, GWL_STYLE);
1976 SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
1977 ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
1978 ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
1979 SetWindowLong(child, GWL_STYLE, style);
1980
1981 SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
1982 ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
1983 SetWindowLong(child, GWL_STYLE, style);
1984
1985 DestroyWindow(child);
1986 DestroyMenu(hMenu);
1987 }
1988
1989 static void test_window_tree(HWND parent, const DWORD *style, const int *order, int total)
1990 {
1991 HWND child[5], hwnd;
1992 INT_PTR i;
1993
1994 assert(total <= 5);
1995
1996 hwnd = GetWindow(parent, GW_CHILD);
1997 ok(!hwnd, "have to start without children to perform the test\n");
1998
1999 for (i = 0; i < total; i++)
2000 {
2001 if (style[i] & DS_CONTROL)
2002 {
2003 child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
2004 0,0,0,0, parent, (HMENU)i, 0, NULL);
2005 if (style[i] & WS_VISIBLE)
2006 ShowWindow(child[i], SW_SHOW);
2007
2008 SetWindowPos(child[i], HWND_BOTTOM, 0,0,10,10, SWP_NOACTIVATE);
2009 }
2010 else
2011 child[i] = CreateWindowExA(0, "static", "", style[i], 0,0,10,10,
2012 parent, (HMENU)i, 0, NULL);
2013 trace("child[%ld] = %p\n", i, child[i]);
2014 ok(child[i] != 0, "CreateWindowEx failed to create child window\n");
2015 }
2016
2017 hwnd = GetWindow(parent, GW_CHILD);
2018 ok(hwnd != 0, "GetWindow(GW_CHILD) failed\n");
2019 ok(hwnd == GetWindow(child[total - 1], GW_HWNDFIRST), "GW_HWNDFIRST is wrong\n");
2020 ok(child[order[total - 1]] == GetWindow(child[0], GW_HWNDLAST), "GW_HWNDLAST is wrong\n");
2021
2022 for (i = 0; i < total; i++)
2023 {
2024 trace("hwnd[%ld] = %p\n", i, hwnd);
2025 ok(child[order[i]] == hwnd, "Z order of child #%ld is wrong\n", i);
2026
2027 hwnd = GetWindow(hwnd, GW_HWNDNEXT);
2028 }
2029
2030 for (i = 0; i < total; i++)
2031 ok(DestroyWindow(child[i]), "DestroyWindow failed\n");
2032 }
2033
2034 static void test_children_zorder(HWND parent)
2035 {
2036 const DWORD simple_style[5] = { WS_CHILD, WS_CHILD, WS_CHILD, WS_CHILD,
2037 WS_CHILD };
2038 const int simple_order[5] = { 0, 1, 2, 3, 4 };
2039
2040 const DWORD complex_style[5] = { WS_CHILD, WS_CHILD | WS_MAXIMIZE,
2041 WS_CHILD | WS_VISIBLE, WS_CHILD,
2042 WS_CHILD | WS_MAXIMIZE | WS_VISIBLE };
2043 const int complex_order_1[1] = { 0 };
2044 const int complex_order_2[2] = { 1, 0 };
2045 const int complex_order_3[3] = { 1, 0, 2 };
2046 const int complex_order_4[4] = { 1, 0, 2, 3 };
2047 const int complex_order_5[5] = { 4, 1, 0, 2, 3 };
2048 const DWORD complex_style_6[3] = { WS_CHILD | WS_VISIBLE,
2049 WS_CHILD | WS_CLIPSIBLINGS | DS_CONTROL | WS_VISIBLE,
2050 WS_CHILD | WS_VISIBLE };
2051 const int complex_order_6[3] = { 0, 1, 2 };
2052
2053 /* simple WS_CHILD */
2054 test_window_tree(parent, simple_style, simple_order, 5);
2055
2056 /* complex children styles */
2057 test_window_tree(parent, complex_style, complex_order_1, 1);
2058 test_window_tree(parent, complex_style, complex_order_2, 2);
2059 test_window_tree(parent, complex_style, complex_order_3, 3);
2060 test_window_tree(parent, complex_style, complex_order_4, 4);
2061 test_window_tree(parent, complex_style, complex_order_5, 5);
2062
2063 /* another set of complex children styles */
2064 test_window_tree(parent, complex_style_6, complex_order_6, 3);
2065 }
2066
2067 #define check_z_order(hwnd, next, prev, owner, topmost) \
2068 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2069 __FILE__, __LINE__)
2070
2071 static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
2072 BOOL topmost, const char *file, int line)
2073 {
2074 HWND test;
2075 DWORD ex_style;
2076
2077 test = GetWindow(hwnd, GW_HWNDNEXT);
2078 /* skip foreign windows */
2079 while (test && test != next &&
2080 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2081 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2082 GetWindow(test, GW_OWNER) == next))
2083 {
2084 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2085 test = GetWindow(test, GW_HWNDNEXT);
2086 }
2087 ok_(file, line)(next == test, "expected next %p, got %p\n", next, test);
2088
2089 test = GetWindow(hwnd, GW_HWNDPREV);
2090 /* skip foreign windows */
2091 while (test && test != prev &&
2092 (GetWindowThreadProcessId(test, NULL) != our_pid ||
2093 UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
2094 GetWindow(test, GW_OWNER) == hwnd))
2095 {
2096 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2097 test = GetWindow(test, GW_HWNDPREV);
2098 }
2099 ok_(file, line)(prev == test, "expected prev %p, got %p\n", prev, test);
2100
2101 test = GetWindow(hwnd, GW_OWNER);
2102 ok_(file, line)(owner == test, "expected owner %p, got %p\n", owner, test);
2103
2104 ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
2105 ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "expected %stopmost\n", topmost ? "" : "NOT ");
2106 }
2107
2108 static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E)
2109 {
2110 HWND hwnd_A, hwnd_B, hwnd_C, hwnd_F;
2111
2112 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D, hwnd_E);
2113
2114 SetWindowPos(hwnd_E, hwnd_D, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2115
2116 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2117 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2118
2119 hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
2120 WS_OVERLAPPED | WS_CAPTION,
2121 100, 100, 100, 100,
2122 0, 0, GetModuleHandle(0), NULL);
2123 trace("hwnd_F %p\n", hwnd_F);
2124 check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
2125
2126 SetWindowPos(hwnd_F, hwnd_E, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2127 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2128 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2129 check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
2130
2131 hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
2132 WS_POPUP,
2133 100, 100, 100, 100,
2134 hwnd_F, 0, GetModuleHandle(0), NULL);
2135 trace("hwnd_C %p\n", hwnd_C);
2136 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2137 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2138 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2139 check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
2140
2141 hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2142 WS_POPUP,
2143 100, 100, 100, 100,
2144 hwnd_F, 0, GetModuleHandle(0), NULL);
2145 trace("hwnd_B %p\n", hwnd_B);
2146 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2147 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2148 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2149 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2150 check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
2151
2152 hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
2153 WS_POPUP,
2154 100, 100, 100, 100,
2155 0, 0, GetModuleHandle(0), NULL);
2156 trace("hwnd_A %p\n", hwnd_A);
2157 check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
2158 check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
2159 check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
2160 check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
2161 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2162 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2163
2164 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);
2165
2166 /* move hwnd_F and its popups up */
2167 SetWindowPos(hwnd_F, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2168 check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
2169 check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
2170 check_z_order(hwnd_F, hwnd_D, hwnd_C, 0, FALSE);
2171 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2172 check_z_order(hwnd_B, hwnd_C, hwnd_A, hwnd_F, TRUE);
2173 check_z_order(hwnd_A, hwnd_B, 0, 0, TRUE);
2174
2175 /* move hwnd_F and its popups down */
2176 #if 0 /* enable once Wine is fixed to pass this test */
2177 SetWindowPos(hwnd_F, HWND_BOTTOM, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
2178 check_z_order(hwnd_F, 0, hwnd_C, 0, FALSE);
2179 check_z_order(hwnd_C, hwnd_F, hwnd_B, hwnd_F, FALSE);
2180 check_z_order(hwnd_B, hwnd_C, hwnd_E, hwnd_F, FALSE);
2181 check_z_order(hwnd_E, hwnd_B, hwnd_D, 0, FALSE);
2182 check_z_order(hwnd_D, hwnd_E, hwnd_A, 0, FALSE);
2183 check_z_order(hwnd_A, hwnd_D, 0, 0, TRUE);
2184 #endif
2185
2186 DestroyWindow(hwnd_A);
2187 DestroyWindow(hwnd_B);
2188 DestroyWindow(hwnd_C);
2189 DestroyWindow(hwnd_F);
2190 }
2191
2192 static void test_vis_rgn( HWND hwnd )
2193 {
2194 RECT win_rect, rgn_rect;
2195 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2196 HDC hdc;
2197
2198 ShowWindow(hwnd,SW_SHOW);
2199 hdc = GetDC( hwnd );
2200 ok( GetRandomRgn( hdc, hrgn, SYSRGN ) != 0, "GetRandomRgn failed\n" );
2201 GetWindowRect( hwnd, &win_rect );
2202 GetRgnBox( hrgn, &rgn_rect );
2203 if (GetVersion() & 0x80000000)
2204 {
2205 trace("win9x, mapping to screen coords\n");
2206 MapWindowPoints( hwnd, 0, (POINT *)&rgn_rect, 2 );
2207 }
2208 trace("win: %d,%d-%d,%d\n", win_rect.left, win_rect.top, win_rect.right, win_rect.bottom );
2209 trace("rgn: %d,%d-%d,%d\n", rgn_rect.left, rgn_rect.top, rgn_rect.right, rgn_rect.bottom );
2210 ok( win_rect.left <= rgn_rect.left, "rgn left %d not inside win rect %d\n",
2211 rgn_rect.left, win_rect.left );
2212 ok( win_rect.top <= rgn_rect.top, "rgn top %d not inside win rect %d\n",
2213 rgn_rect.top, win_rect.top );
2214 ok( win_rect.right >= rgn_rect.right, "rgn right %d not inside win rect %d\n",
2215 rgn_rect.right, win_rect.right );
2216 ok( win_rect.bottom >= rgn_rect.bottom, "rgn bottom %d not inside win rect %d\n",
2217 rgn_rect.bottom, win_rect.bottom );
2218 ReleaseDC( hwnd, hdc );
2219 }
2220
2221 static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
2222 {
2223 if (msg == WM_ACTIVATE && LOWORD(wp) == WA_ACTIVE)
2224 {
2225 HWND child = GetWindow(hwnd, GW_CHILD);
2226 ok(child != 0, "couldn't find child window\n");
2227 SetFocus(child);
2228 ok(GetFocus() == child, "Focus should be on child %p\n", child);
2229 return 0;
2230 }
2231 return DefWindowProc(hwnd, msg, wp, lp);
2232 }
2233
2234 static void test_SetFocus(HWND hwnd)
2235 {
2236 HWND child;
2237 WNDPROC old_wnd_proc;
2238
2239 /* check if we can set focus to non-visible windows */
2240
2241 ShowWindow(hwnd, SW_SHOW);
2242 SetFocus(0);
2243 SetFocus(hwnd);
2244 ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
2245 ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
2246 ShowWindow(hwnd, SW_HIDE);
2247 SetFocus(0);
2248 SetFocus(hwnd);
2249 ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
2250 ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
2251 child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2252 assert(child);
2253 SetFocus(child);
2254 ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
2255 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2256 ShowWindow(child, SW_SHOW);
2257 ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
2258 ok( GetFocus() == child, "Focus no longer on child %p\n", child );
2259 ShowWindow(child, SW_HIDE);
2260 ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
2261 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2262 ShowWindow(child, SW_SHOW);
2263 SetFocus(child);
2264 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2265 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_HIDEWINDOW);
2266 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2267
2268 ShowWindow(child, SW_HIDE);
2269 SetFocus(hwnd);
2270 ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
2271 SetWindowPos(child,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
2272 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2273 ShowWindow(child, SW_HIDE);
2274 ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
2275
2276 ShowWindow(hwnd, SW_SHOW);
2277 ShowWindow(child, SW_SHOW);
2278 SetFocus(child);
2279 ok( GetFocus() == child, "Focus should be on child %p\n", child );
2280 EnableWindow(hwnd, FALSE);
2281 ok( GetFocus() == child, "Focus should still be on child %p\n", child );
2282 EnableWindow(hwnd, TRUE);
2283
2284 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2285 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2286 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2287 todo_wine
2288 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2289 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2290 ShowWindow(hwnd, SW_RESTORE);
2291 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2292 ok( GetFocus() == hwnd, "Focus should be on parent %p\n", hwnd );
2293 ShowWindow(hwnd, SW_SHOWMINIMIZED);
2294 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2295 ok( GetFocus() != child, "Focus should not be on child %p\n", child );
2296 todo_wine
2297 ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
2298 old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
2299 ShowWindow(hwnd, SW_RESTORE);
2300 ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
2301 todo_wine
2302 ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
2303
2304 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
2305
2306 DestroyWindow( child );
2307 }
2308
2309 #define check_wnd_state(a,b,c,d) check_wnd_state_(__FILE__,__LINE__,a,b,c,d)
2310 static void check_wnd_state_(const char *file, int line,
2311 HWND active, HWND foreground, HWND focus, HWND capture)
2312 {
2313 ok_(file, line)(active == GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2314 if (foreground && GetForegroundWindow())
2315 ok_(file, line)(foreground == GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2316 ok_(file, line)(focus == GetFocus(), "GetFocus() = %p\n", GetFocus());
2317 ok_(file, line)(capture == GetCapture(), "GetCapture() = %p\n", GetCapture());
2318 }
2319
2320 static void test_SetActiveWindow(HWND hwnd)
2321 {
2322 HWND hwnd2;
2323
2324 flush_events( TRUE );
2325 ShowWindow(hwnd, SW_HIDE);
2326 SetFocus(0);
2327 SetActiveWindow(0);
2328 check_wnd_state(0, 0, 0, 0);
2329
2330 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2331
2332 ShowWindow(hwnd, SW_SHOW);
2333 check_wnd_state(hwnd, hwnd, hwnd, 0);
2334
2335 hwnd2 = SetActiveWindow(0);
2336 ok(hwnd2 == hwnd, "SetActiveWindow returned %p instead of %p\n", hwnd2, hwnd);
2337 if (!GetActiveWindow()) /* doesn't always work on vista */
2338 {
2339 check_wnd_state(0, 0, 0, 0);
2340 hwnd2 = SetActiveWindow(hwnd);
2341 ok(hwnd2 == 0, "SetActiveWindow returned %p instead of 0\n", hwnd2);
2342 }
2343 check_wnd_state(hwnd, hwnd, hwnd, 0);
2344
2345 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2346 check_wnd_state(hwnd, hwnd, hwnd, 0);
2347
2348 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2349 check_wnd_state(hwnd, hwnd, hwnd, 0);
2350
2351 ShowWindow(hwnd, SW_HIDE);
2352 check_wnd_state(0, 0, 0, 0);
2353
2354 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2355 SetActiveWindow(hwnd);
2356 check_wnd_state(hwnd, hwnd, hwnd, 0);
2357
2358 ShowWindow(hwnd, SW_SHOW);
2359 check_wnd_state(hwnd, hwnd, hwnd, 0);
2360
2361 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2362 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2363
2364 DestroyWindow(hwnd2);
2365 check_wnd_state(hwnd, hwnd, hwnd, 0);
2366
2367 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2368 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2369
2370 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2371 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2372
2373 DestroyWindow(hwnd2);
2374 check_wnd_state(hwnd, hwnd, hwnd, 0);
2375 }
2376
2377 static void test_SetForegroundWindow(HWND hwnd)
2378 {
2379 BOOL ret;
2380 HWND hwnd2;
2381
2382 flush_events( TRUE );
2383 ShowWindow(hwnd, SW_HIDE);
2384 SetFocus(0);
2385 SetActiveWindow(0);
2386 check_wnd_state(0, 0, 0, 0);
2387
2388 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2389
2390 ShowWindow(hwnd, SW_SHOW);
2391 check_wnd_state(hwnd, hwnd, hwnd, 0);
2392
2393 hwnd2 = SetActiveWindow(0);
2394 ok(hwnd2 == hwnd, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2, hwnd);
2395 if (GetActiveWindow() == hwnd) /* doesn't always work on vista */
2396 check_wnd_state(hwnd, hwnd, hwnd, 0);
2397 else
2398 check_wnd_state(0, 0, 0, 0);
2399
2400 ret = SetForegroundWindow(hwnd);
2401 if (!ret)
2402 {
2403 skip( "SetForegroundWindow not working\n" );
2404 return;
2405 }
2406 check_wnd_state(hwnd, hwnd, hwnd, 0);
2407
2408 SetLastError(0xdeadbeef);
2409 ret = SetForegroundWindow(0);
2410 ok(!ret, "SetForegroundWindow returned TRUE instead of FALSE\n");
2411 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE ||
2412 broken(GetLastError() == 0xdeadbeef), /* win9x */
2413 "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2414 check_wnd_state(hwnd, hwnd, hwnd, 0);
2415
2416 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2417 check_wnd_state(hwnd, hwnd, hwnd, 0);
2418
2419 SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
2420 check_wnd_state(hwnd, hwnd, hwnd, 0);
2421
2422 hwnd2 = GetForegroundWindow();
2423 ok(hwnd2 == hwnd, "Wrong foreground window %p\n", hwnd2);
2424 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2425 hwnd2 = GetForegroundWindow();
2426 ok(hwnd2 != hwnd, "Wrong foreground window %p\n", hwnd2);
2427
2428 ShowWindow(hwnd, SW_HIDE);
2429 check_wnd_state(0, 0, 0, 0);
2430
2431 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2432 ret = SetForegroundWindow(hwnd);
2433 ok(ret, "SetForegroundWindow returned FALSE instead of TRUE\n");
2434 check_wnd_state(hwnd, hwnd, hwnd, 0);
2435
2436 ShowWindow(hwnd, SW_SHOW);
2437 check_wnd_state(hwnd, hwnd, hwnd, 0);
2438
2439 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2440 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2441
2442 DestroyWindow(hwnd2);
2443 check_wnd_state(hwnd, hwnd, hwnd, 0);
2444
2445 hwnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP|WS_VISIBLE, 0, 0, 0, 0, hwnd, 0, 0, NULL);
2446 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2447
2448 SetWindowPos(hwnd2,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
2449 check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
2450
2451 DestroyWindow(hwnd2);
2452 check_wnd_state(hwnd, hwnd, hwnd, 0);
2453 }
2454
2455 static WNDPROC old_button_proc;
2456
2457 static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPARAM lparam)
2458 {
2459 LRESULT ret;
2460 USHORT key_state;
2461
2462 key_state = GetKeyState(VK_LBUTTON);
2463 ok(!(key_state & 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state);
2464
2465 ret = CallWindowProcA(old_button_proc, button, msg, wparam, lparam);
2466
2467 if (msg == WM_LBUTTONDOWN)
2468 {
2469 HWND hwnd, capture;
2470
2471 check_wnd_state(button, button, button, button);
2472
2473 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2474 assert(hwnd);
2475 trace("hwnd %p\n", hwnd);
2476
2477 check_wnd_state(button, button, button, button);
2478
2479 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2480
2481 check_wnd_state(button, button, button, button);
2482
2483 DestroyWindow(hwnd);
2484
2485 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2486 assert(hwnd);
2487 trace("hwnd %p\n", hwnd);
2488
2489 check_wnd_state(button, button, button, button);
2490
2491 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2492 * match internal button state.
2493 */
2494 SendMessage(button, WM_KILLFOCUS, 0, 0);
2495 check_wnd_state(button, button, button, 0);
2496
2497 ShowWindow(hwnd, SW_SHOW);
2498 check_wnd_state(hwnd, hwnd, hwnd, 0);
2499
2500 capture = SetCapture(hwnd);
2501 ok(capture == 0, "SetCapture() = %p\n", capture);
2502
2503 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2504
2505 DestroyWindow(hwnd);
2506
2507 check_wnd_state(button, 0, button, 0);
2508 }
2509
2510 return ret;
2511 }
2512
2513 static void test_capture_1(void)
2514 {
2515 HWND button, capture, oldFocus, oldActive;
2516
2517 oldFocus = GetFocus();
2518 oldActive = GetActiveWindow();
2519
2520 capture = GetCapture();
2521 ok(capture == 0, "GetCapture() = %p\n", capture);
2522
2523 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2524 assert(button);
2525 trace("button %p\n", button);
2526
2527 old_button_proc = (WNDPROC)SetWindowLongPtrA(button, GWLP_WNDPROC, (LONG_PTR)button_hook_proc);
2528
2529 SendMessageA(button, WM_LBUTTONDOWN, 0, 0);
2530
2531 capture = SetCapture(button);
2532 ok(capture == 0, "SetCapture() = %p\n", capture);
2533 check_wnd_state(button, 0, button, button);
2534
2535 DestroyWindow(button);
2536 check_wnd_state(oldActive, 0, oldFocus, 0);
2537 }
2538
2539 static void test_capture_2(void)
2540 {
2541 HWND button, hwnd, capture, oldFocus, oldActive;
2542
2543 oldFocus = GetFocus();
2544 oldActive = GetActiveWindow();
2545 check_wnd_state(oldActive, 0, oldFocus, 0);
2546
2547 button = CreateWindowExA(0, "button", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 10, 10, 0, 0, 0, NULL);
2548 assert(button);
2549 trace("button %p\n", button);
2550
2551 check_wnd_state(button, button, button, 0);
2552
2553 capture = SetCapture(button);
2554 ok(capture == 0, "SetCapture() = %p\n", capture);
2555
2556 check_wnd_state(button, button, button, button);
2557
2558 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2559 * internal button state.
2560 */
2561 SendMessage(button, WM_KILLFOCUS, 0, 0);
2562 check_wnd_state(button, button, button, button);
2563
2564 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2565 assert(hwnd);
2566 trace("hwnd %p\n", hwnd);
2567
2568 check_wnd_state(button, button, button, button);
2569
2570 ShowWindow(hwnd, SW_SHOWNOACTIVATE);
2571
2572 check_wnd_state(button, button, button, button);
2573
2574 DestroyWindow(hwnd);
2575
2576 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
2577 assert(hwnd);
2578 trace("hwnd %p\n", hwnd);
2579
2580 check_wnd_state(button, button, button, button);
2581
2582 ShowWindow(hwnd, SW_SHOW);
2583
2584 check_wnd_state(hwnd, hwnd, hwnd, button);
2585
2586 capture = SetCapture(hwnd);
2587 ok(capture == button, "SetCapture() = %p\n", capture);
2588
2589 check_wnd_state(hwnd, hwnd, hwnd, hwnd);
2590
2591 DestroyWindow(hwnd);
2592 check_wnd_state(button, button, button, 0);
2593
2594 DestroyWindow(button);
2595 check_wnd_state(oldActive, 0, oldFocus, 0);
2596 }
2597
2598 static void test_capture_3(HWND hwnd1, HWND hwnd2)
2599 {
2600 BOOL ret;
2601
2602 ShowWindow(hwnd1, SW_HIDE);
2603 ShowWindow(hwnd2, SW_HIDE);
2604
2605 ok(!IsWindowVisible(hwnd1), "%p should be invisible\n", hwnd1);
2606 ok(!IsWindowVisible(hwnd2), "%p should be invisible\n", hwnd2);
2607
2608 SetCapture(hwnd1);
2609 check_wnd_state(0, 0, 0, hwnd1);
2610
2611 SetCapture(hwnd2);
2612 check_wnd_state(0, 0, 0, hwnd2);
2613
2614 ShowWindow(hwnd1, SW_SHOW);
2615 check_wnd_state(hwnd1, hwnd1, hwnd1, hwnd2);
2616
2617 ret = ReleaseCapture();
2618 ok (ret, "releasecapture did not return TRUE.\n");
2619 ret = ReleaseCapture();
2620 ok (ret, "releasecapture did not return TRUE after second try.\n");
2621 }
2622
2623 static void test_keyboard_input(HWND hwnd)
2624 {
2625 MSG msg;
2626 BOOL ret;
2627
2628 flush_events( TRUE );
2629 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
2630 UpdateWindow(hwnd);
2631 flush_events( TRUE );
2632
2633 ok(GetActiveWindow() == hwnd, "wrong active window %p\n", GetActiveWindow());
2634
2635 SetFocus(hwnd);
2636 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2637
2638 flush_events( TRUE );
2639
2640 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2641 do
2642 {
2643 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2644 ok( ret, "no message available\n");
2645 }
2646 while (ret && msg.message >= 0xc000);
2647 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2648 do
2649 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2650 while (ret && (msg.message == WM_TIMER || msg.message >= 0xc000));
2651 ok( !ret, "message %04x available\n", msg.message);
2652
2653 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2654
2655 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2656 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2657 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2658 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2659 ok( !ret, "message %04x available\n", msg.message);
2660
2661 ok(GetFocus() == hwnd, "wrong focus window %p\n", GetFocus());
2662
2663 keybd_event(VK_SPACE, 0, 0, 0);
2664 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2665 if (!ret)
2666 {
2667 skip( "keybd_event didn't work, skipping keyboard test\n" );
2668 return;
2669 }
2670 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2671 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2672 ok( !ret, "message %04x available\n", msg.message);
2673
2674 SetFocus(0);
2675 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2676
2677 flush_events( TRUE );
2678
2679 PostMessageA(hwnd, WM_KEYDOWN, 0, 0);
2680 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2681 ok(msg.hwnd == hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2682 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2683 ok( !ret, "message %04x available\n", msg.message);
2684
2685 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2686
2687 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN, 0, 0);
2688 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2689 ok(!msg.hwnd && msg.message == WM_KEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2690 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2691 ok( !ret, "message %04x available\n", msg.message);
2692
2693 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2694
2695 keybd_event(VK_SPACE, 0, 0, 0);
2696 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2697 ok(msg.hwnd == hwnd && msg.message == WM_SYSKEYDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2698 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2699 ok( !ret, "message %04x available\n", msg.message);
2700 }
2701
2702 static BOOL wait_for_message( MSG *msg )
2703 {
2704 BOOL ret;
2705
2706 for (;;)
2707 {
2708 ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
2709 if (ret)
2710 {
2711 if (msg->message == WM_PAINT) DispatchMessage(msg);
2712 else if (msg->message < 0xc000) break; /* skip registered messages */
2713 }
2714 else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
2715 }
2716 if (!ret) msg->message = 0;
2717 return ret;
2718 }
2719
2720 static void test_mouse_input(HWND hwnd)
2721 {
2722 RECT rc;
2723 POINT pt;
2724 int x, y;
2725 HWND popup;
2726 MSG msg;
2727 BOOL ret;
2728 LRESULT res;
2729
2730 ShowWindow(hwnd, SW_SHOW);
2731 UpdateWindow(hwnd);
2732 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2733
2734 GetWindowRect(hwnd, &rc);
2735 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd, rc.left, rc.top, rc.right, rc.bottom);
2736
2737 popup = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP,
2738 rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
2739 hwnd, 0, 0, NULL);
2740 assert(popup != 0);
2741 ShowWindow(popup, SW_SHOW);
2742 UpdateWindow(popup);
2743 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2744
2745 GetWindowRect(popup, &rc);
2746 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup, rc.left, rc.top, rc.right, rc.bottom);
2747
2748 x = rc.left + (rc.right - rc.left) / 2;
2749 y = rc.top + (rc.bottom - rc.top) / 2;
2750 trace("setting cursor to (%d,%d)\n", x, y);
2751
2752 SetCursorPos(x, y);
2753 GetCursorPos(&pt);
2754 if (x != pt.x || y != pt.y)
2755 {
2756 skip( "failed to set mouse position, skipping mouse input tests\n" );
2757 goto done;
2758 }
2759
2760 flush_events( TRUE );
2761
2762 /* Check that setting the same position may generate WM_MOUSEMOVE */
2763 SetCursorPos(x, y);
2764 msg.message = 0;
2765 do
2766 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2767 while (ret && msg.message >= 0xc000); /* skip registered messages */
2768 if (ret)
2769 {
2770 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n",
2771 msg.hwnd, msg.message);
2772 ok(msg.pt.x == x && msg.pt.y == y, "wrong message coords (%d,%d)/(%d,%d)\n",
2773 x, y, msg.pt.x, msg.pt.y);
2774 }
2775
2776 /* force the system to update its internal queue mouse position,
2777 * otherwise it won't generate relative mouse movements below.
2778 */
2779 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2780 flush_events( TRUE );
2781
2782 msg.message = 0;
2783 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2784 flush_events( FALSE );
2785 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2786 while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
2787 {
2788 if (msg.message == WM_TIMER || msg.message >= 0xc000) continue; /* skip registered messages */
2789 ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
2790 "hwnd %p message %04x\n", msg.hwnd, msg.message);
2791 }
2792 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2793 ok( !ret, "message %04x available\n", msg.message);
2794
2795 mouse_event(MOUSEEVENTF_MOVE, -1, -1, 0, 0);
2796 ShowWindow(popup, SW_HIDE);
2797 ret = wait_for_message( &msg );
2798 if (ret)
2799 ok(msg.hwnd == hwnd && msg.message == WM_MOUSEMOVE, "hwnd %p message %04x\n", msg.hwnd, msg.message);
2800 flush_events( TRUE );
2801
2802 mouse_event(MOUSEEVENTF_MOVE, 1, 1, 0, 0);
2803 ShowWindow(hwnd, SW_HIDE);
2804 ret = wait_for_message( &msg );
2805 ok( !ret, "message %04x available\n", msg.message);
2806 flush_events( TRUE );
2807
2808 /* test mouse clicks */
2809
2810 ShowWindow(hwnd, SW_SHOW);
2811 SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2812 flush_events( TRUE );
2813 ShowWindow(popup, SW_SHOW);
2814 SetWindowPos( popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE );
2815 flush_events( TRUE );
2816
2817 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2818 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2819 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2820 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2821
2822 ret = wait_for_message( &msg );
2823 if (!ret)
2824 {
2825 skip( "simulating mouse click doesn't work, skipping mouse button tests\n" );
2826 goto done;
2827 }
2828 if (msg.message == WM_MOUSEMOVE) /* win2k has an extra WM_MOUSEMOVE here */
2829 {
2830 ret = wait_for_message( &msg );
2831 ok(ret, "no message available\n");
2832 }
2833
2834 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2835 msg.hwnd, popup, msg.message);
2836
2837 ret = wait_for_message( &msg );
2838 ok(ret, "no message available\n");
2839 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2840 msg.hwnd, popup, msg.message);
2841
2842 ret = wait_for_message( &msg );
2843 ok(ret, "no message available\n");
2844 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p/%p message %04x\n",
2845 msg.hwnd, popup, msg.message);
2846
2847 ret = wait_for_message( &msg );
2848 ok(ret, "no message available\n");
2849 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2850 msg.hwnd, popup, msg.message);
2851
2852 ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
2853 ok(!ret, "message %04x available\n", msg.message);
2854
2855 ShowWindow(popup, SW_HIDE);
2856 flush_events( TRUE );
2857
2858 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2859 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2860 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
2861 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
2862
2863 ret = wait_for_message( &msg );
2864 ok(ret, "no message available\n");
2865 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2866 msg.hwnd, hwnd, msg.message);
2867 ret = wait_for_message( &msg );
2868 ok(ret, "no message available\n");
2869 ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2870 msg.hwnd, hwnd, msg.message);
2871
2872 test_lbuttondown_flag = TRUE;
2873 SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
2874 test_lbuttondown_flag = FALSE;
2875
2876 ret = wait_for_message( &msg );
2877 ok(ret, "no message available\n");
2878 ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p/%p message %04x\n",
2879 msg.hwnd, popup, msg.message);
2880 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2881 ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p/%p message %04x\n",
2882 msg.hwnd, popup, msg.message);
2883 ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
2884
2885 /* Test WM_MOUSEACTIVATE */
2886 #define TEST_MOUSEACTIVATE(A,B) \
2887 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2888 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2889
2890 TEST_MOUSEACTIVATE(HTERROR,MA_ACTIVATE);
2891 TEST_MOUSEACTIVATE(HTTRANSPARENT,MA_ACTIVATE);
2892 TEST_MOUSEACTIVATE(HTNOWHERE,MA_ACTIVATE);
2893 TEST_MOUSEACTIVATE(HTCLIENT,MA_ACTIVATE);
2894 TEST_MOUSEACTIVATE(HTCAPTION,MA_ACTIVATE);
2895 TEST_MOUSEACTIVATE(HTSYSMENU,MA_ACTIVATE);
2896 TEST_MOUSEACTIVATE(HTSIZE,MA_ACTIVATE);
2897 TEST_MOUSEACTIVATE(HTMENU,MA_ACTIVATE);
2898 TEST_MOUSEACTIVATE(HTHSCROLL,MA_ACTIVATE);
2899 TEST_MOUSEACTIVATE(HTVSCROLL,MA_ACTIVATE);
2900 TEST_MOUSEACTIVATE(HTMINBUTTON,MA_ACTIVATE);
2901 TEST_MOUSEACTIVATE(HTMAXBUTTON,MA_ACTIVATE);
2902 TEST_MOUSEACTIVATE(HTLEFT,MA_ACTIVATE);
2903 TEST_MOUSEACTIVATE(HTRIGHT,MA_ACTIVATE);
2904 TEST_MOUSEACTIVATE(HTTOP,MA_ACTIVATE);
2905 TEST_MOUSEACTIVATE(HTTOPLEFT,MA_ACTIVATE);
2906 TEST_MOUSEACTIVATE(HTTOPRIGHT,MA_ACTIVATE);
2907 TEST_MOUSEACTIVATE(HTBOTTOM,MA_ACTIVATE);
2908 TEST_MOUSEACTIVATE(HTBOTTOMLEFT,MA_ACTIVATE);
2909 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT,MA_ACTIVATE);
2910 TEST_MOUSEACTIVATE(HTBORDER,MA_ACTIVATE);
2911 TEST_MOUSEACTIVATE(HTOBJECT,MA_ACTIVATE);
2912 TEST_MOUSEACTIVATE(HTCLOSE,MA_ACTIVATE);
2913 TEST_MOUSEACTIVATE(HTHELP,MA_ACTIVATE);
2914
2915 done:
2916 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2917 flush_events( TRUE );
2918
2919 DestroyWindow(popup);
2920 }
2921
2922 static void test_validatergn(HWND hwnd)
2923 {
2924 HWND child;
2925 RECT rc, rc2;
2926 HRGN rgn;
2927 int ret;
2928 child = CreateWindowExA(0, "static", NULL, WS_CHILD| WS_VISIBLE, 10, 10, 10, 10, hwnd, 0, 0, NULL);
2929 ShowWindow(hwnd, SW_SHOW);
2930 UpdateWindow( hwnd);
2931 /* test that ValidateRect validates children*/
2932 InvalidateRect( child, NULL, 1);
2933 GetWindowRect( child, &rc);
2934 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2935 ret = GetUpdateRect( child, &rc2, 0);
2936 ok( rc2.right > rc2.left && rc2.bottom > rc2.top,
2937 "Update rectangle is empty!\n");
2938 ValidateRect( hwnd, &rc);
2939 ret = GetUpdateRect( child, &rc2, 0);
2940 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2941 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2942 rc2.right, rc2.bottom);
2943
2944 /* now test ValidateRgn */
2945 InvalidateRect( child, NULL, 1);
2946 GetWindowRect( child, &rc);
2947 MapWindowPoints( NULL, hwnd, (POINT*) &rc, 2);
2948 rgn = CreateRectRgnIndirect( &rc);
2949 ValidateRgn( hwnd, rgn);
2950 ret = GetUpdateRect( child, &rc2, 0);
2951 ok( rc2.left == 0 && rc2.top == 0 && rc2.right == 0 && rc2.bottom == 0,
2952 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2.left, rc2.top,
2953 rc2.right, rc2.bottom);
2954
2955 DeleteObject( rgn);
2956 DestroyWindow( child );
2957 }
2958
2959 static void nccalchelper(HWND hwnd, INT x, INT y, RECT *prc)
2960 {
2961 RECT rc;
2962 MoveWindow( hwnd, 0, 0, x, y, 0);
2963 GetWindowRect( hwnd, prc);
2964 rc = *prc;
2965 DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)prc);
2966 trace("window rect is %d,%d - %d,%d, nccalc rect is %d,%d - %d,%d\n",
2967 rc.left,rc.top,rc.right,rc.bottom, prc->left,prc->top,prc->right,prc->bottom);
2968 }
2969
2970 static void test_nccalcscroll(HWND parent)
2971 {
2972 RECT rc1;
2973 INT sbheight = GetSystemMetrics( SM_CYHSCROLL);
2974 INT sbwidth = GetSystemMetrics( SM_CXVSCROLL);
2975 HWND hwnd = CreateWindowExA(0, "static", NULL,
2976 WS_CHILD| WS_VISIBLE | WS_VSCROLL | WS_HSCROLL ,
2977 10, 10, 200, 200, parent, 0, 0, NULL);
2978 ShowWindow( parent, SW_SHOW);
2979 UpdateWindow( parent);
2980
2981 /* test window too low for a horizontal scroll bar */
2982 nccalchelper( hwnd, 100, sbheight, &rc1);
2983 ok( rc1.bottom - rc1.top == sbheight, "Height should be %d size is %d,%d - %d,%d\n",
2984 sbheight, rc1.left, rc1.top, rc1.right, rc1.bottom);
2985
2986 /* test window just high enough for a horizontal scroll bar */
2987 nccalchelper( hwnd, 100, sbheight + 1, &rc1);
2988 ok( rc1.bottom - rc1.top == 1, "Height should be %d size is %d,%d - %d,%d\n",
2989 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2990
2991 /* test window too narrow for a vertical scroll bar */
2992 nccalchelper( hwnd, sbwidth - 1, 100, &rc1);
2993 ok( rc1.right - rc1.left == sbwidth - 1 , "Width should be %d size is %d,%d - %d,%d\n",
2994 sbwidth - 1, rc1.left, rc1.top, rc1.right, rc1.bottom);
2995
2996 /* test window just wide enough for a vertical scroll bar */
2997 nccalchelper( hwnd, sbwidth, 100, &rc1);
2998 ok( rc1.right - rc1.left == 0, "Width should be %d size is %d,%d - %d,%d\n",
2999 0, rc1.left, rc1.top, rc1.right, rc1.bottom);
3000
3001 /* same test, but with client edge: not enough width */
3002 SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
3003 nccalchelper( hwnd, sbwidth, 100, &rc1);
3004 ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
3005 "Width should be %d size is %d,%d - %d,%d\n",
3006 sbwidth - 2 * GetSystemMetrics(SM_CXEDGE), rc1.left, rc1.top, rc1.right, rc1.bottom);
3007
3008 DestroyWindow( hwnd);
3009 }
3010
3011 static void test_SetParent(void)
3012 {
3013 BOOL ret;
3014 HWND desktop = GetDesktopWindow();
3015 HMENU hMenu;
3016 BOOL is_win9x = GetWindowLongPtrW(desktop, GWLP_WNDPROC) == 0;
3017 HWND parent, child1, child2, child3, child4, sibling;
3018
3019 parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3020 100, 100, 200, 200, 0, 0, 0, NULL);
3021 assert(parent != 0);
3022 child1 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3023 0, 0, 50, 50, parent, 0, 0, NULL);
3024 assert(child1 != 0);
3025 child2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3026 0, 0, 50, 50, child1, 0, 0, NULL);
3027 assert(child2 != 0);
3028 child3 = CreateWindowExA(0, "static", NULL, WS_CHILD,
3029 0, 0, 50, 50, child2, 0, 0, NULL);
3030 assert(child3 != 0);
3031 child4 = CreateWindowExA(0, "static", NULL, WS_POPUP,
3032 0, 0, 50, 50, child3, 0, 0, NULL);
3033 assert(child4 != 0);
3034
3035 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
3036 parent, child1, child2, child3, child4);
3037
3038 check_parents(parent, desktop, 0, 0, 0, parent, parent);
3039 check_parents(child1, parent, parent, parent, 0, parent, parent);
3040 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3041 check_parents(child3, child2, child2, child2, 0, child2, parent);
3042 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3043
3044 ok(!IsChild(desktop, parent), "wrong parent/child %p/%p\n", desktop, parent);
3045 ok(!IsChild(desktop, child1), "wrong parent/child %p/%p\n", desktop, child1);
3046 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3047 ok(!IsChild(desktop, child3), "wrong parent/child %p/%p\n", desktop, child3);
3048 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3049
3050 ok(IsChild(parent, child1), "wrong parent/child %p/%p\n", parent, child1);
3051 ok(!IsChild(desktop, child2), "wrong parent/child %p/%p\n", desktop, child2);
3052 ok(!IsChild(parent, child2), "wrong parent/child %p/%p\n", parent, child2);
3053 ok(!IsChild(child1, child2), "wrong parent/child %p/%p\n", child1, child2);
3054 ok(!IsChild(parent, child3), "wrong parent/child %p/%p\n", parent, child3);
3055 ok(IsChild(child2, child3), "wrong parent/child %p/%p\n", child2, child3);
3056 ok(!IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
3057 ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
3058 ok(!IsChild(desktop, child4), "wrong parent/child %p/%p\n", desktop, child4);
3059
3060 if (!is_win9x) /* Win9x doesn't survive this test */
3061 {
3062 ok(!SetParent(parent, child1), "SetParent should fail\n");
3063 ok(!SetParent(child2, child3), "SetParent should fail\n");
3064 ok(SetParent(child1, parent) != 0, "SetParent should not fail\n");
3065 ok(SetParent(parent, child2) != 0, "SetParent should not fail\n");
3066 ok(SetParent(parent, child3) != 0, "SetParent should not fail\n");
3067 ok(!SetParent(child2, parent), "SetParent should fail\n");
3068 ok(SetParent(parent, child4) != 0, "SetParent should not fail\n");
3069
3070 check_parents(parent, child4, child4, 0, 0, child4, parent);
3071 check_parents(child1, parent, parent, parent, 0, child4, parent);
3072 check_parents(child2, desktop, parent, parent, parent, child2, parent);
3073 check_parents(child3, child2, child2, child2, 0, child2, parent);
3074 check_parents(child4, desktop, child2, child2, child2, child4, parent);
3075 }
3076
3077 hMenu = CreateMenu();
3078 sibling = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
3079 100, 100, 200, 200, 0, hMenu, 0, NULL);
3080 assert(sibling != 0);
3081
3082 ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
3083 ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
3084
3085 ret = DestroyWindow(parent);
3086 ok( ret, "DestroyWindow() error %d\n", GetLastError());
3087
3088 ok(!IsWindow(parent), "parent still exists\n");
3089 ok(!IsWindow(sibling), "sibling still exists\n");
3090 ok(!IsWindow(child1), "child1 still exists\n");
3091 ok(!IsWindow(child2), "child2 still exists\n");
3092 ok(!IsWindow(child3), "child3 still exists\n");
3093 ok(!IsWindow(child4), "child4 still exists\n");
3094 }
3095
3096 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3097 {
3098 LPCREATESTRUCT lpcs;
3099 LPSTYLESTRUCT lpss;
3100
3101 switch (msg)
3102 {
3103 case WM_NCCREATE:
3104 case WM_CREATE:
3105 lpcs = (LPCREATESTRUCT)lparam;
3106 lpss = lpcs->lpCreateParams;
3107 if (lpss)
3108 {
3109 if ((lpcs->dwExStyle & WS_EX_DLGMODALFRAME) ||
3110 ((!(lpcs->dwExStyle & WS_EX_STATICEDGE)) &&
3111 (lpcs->style & (WS_DLGFRAME | WS_THICKFRAME))))
3112 ok(lpcs->dwExStyle & WS_EX_WINDOWEDGE, "Window should have WS_EX_WINDOWEDGE style\n");
3113 else
3114 ok(!(lpcs->dwExStyle & WS_EX_WINDOWEDGE), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
3115
3116 ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
3117 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
3118 (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
3119
3120 ok(lpss->styleNew == lpcs->style,
3121 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
3122 lpss->styleNew, lpcs->style);
3123 }
3124 break;
3125 }
3126 return DefWindowProc(hwnd, msg, wparam, lparam);
3127 }
3128
3129 static ATOM atomStyleCheckClass;
3130
3131 static void register_style_check_class(void)
3132 {
3133 WNDCLASS wc =
3134 {
3135 0,
3136 StyleCheckProc,
3137 0,
3138 0,
3139 GetModuleHandle(NULL),
3140 NULL,
3141 LoadCursor(NULL, IDC_ARROW),
3142 (HBRUSH)(COLOR_BTNFACE+1),
3143 NULL,
3144 TEXT("WineStyleCheck"),
3145 };
3146
3147 atomStyleCheckClass = RegisterClass(&wc);
3148 }
3149
3150 static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyleOut, DWORD dwExStyleOut)
3151 {
3152 DWORD dwActualStyle;
3153 DWORD dwActualExStyle;
3154 STYLESTRUCT ss;
3155 HWND hwnd;
3156 HWND hwndParent = NULL;
3157
3158 ss.styleNew = dwStyleIn;
3159 ss.styleOld = dwExStyleIn;
3160
3161 if (dwStyleIn & WS_CHILD)
3162 {
3163 hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
3164 WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
3165 }
3166
3167 hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
3168 dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
3169 assert(hwnd);
3170
3171 flush_events( TRUE );
3172
3173 dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
3174 dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
3175 ok((dwActualStyle == dwStyleOut) && (dwActualExStyle == dwExStyleOut),
3176 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3177 dwActualStyle, dwStyleOut, dwActualExStyle, dwExStyleOut);
3178
3179 DestroyWindow(hwnd);
3180 if (hwndParent) DestroyWindow(hwndParent);
3181 }
3182
3183 /* tests what window styles the window manager automatically adds */
3184 static void test_window_styles(void)
3185 {
3186 register_style_check_class();
3187
3188 check_window_style(0, 0, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE);
3189 check_window_style(WS_OVERLAPPEDWINDOW, 0, WS_CLIPSIBLINGS|WS_OVERLAPPEDWINDOW, WS_EX_WINDOWEDGE);
3190 check_window_style(WS_CHILD, 0, WS_CHILD, 0);
3191 check_window_style(WS_CHILD, WS_EX_WINDOWEDGE, WS_CHILD, 0);
3192 check_window_style(0, WS_EX_TOOLWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW);
3193 check_window_style(WS_POPUP, 0, WS_POPUP|WS_CLIPSIBLINGS, 0);
3194 check_window_style(WS_POPUP, WS_EX_WINDOWEDGE, WS_POPUP|WS_CLIPSIBLINGS, 0);
3195 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME, WS_CHILD, WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3196 check_window_style(WS_CHILD, WS_EX_DLGMODALFRAME|WS_EX_STATICEDGE, WS_CHILD, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME);
3197 check_window_style(WS_CAPTION, WS_EX_STATICEDGE, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_STATICEDGE|WS_EX_WINDOWEDGE);
3198 check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
3199 }
3200
3201 static void test_scrollvalidate( HWND parent)
3202 {
3203 HDC hdc;
3204 HRGN hrgn=CreateRectRgn(0,0,0,0);
3205 HRGN exprgn, tmprgn, clipping;
3206 RECT rc, rcu, cliprc;
3207 /* create two overlapping child windows. The visual region
3208 * of hwnd1 is clipped by the overlapping part of
3209 * hwnd2 because of the WS_CLIPSIBLING style */
3210 HWND hwnd1, hwnd2;
3211
3212 clipping = CreateRectRgn(0,0,0,0);
3213 tmprgn = CreateRectRgn(0,0,0,0);
3214 exprgn = CreateRectRgn(0,0,0,0);
3215 hwnd2 = CreateWindowExA(0, "static", NULL,
3216 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3217 75, 30, 100, 100, parent, 0, 0, NULL);
3218 hwnd1 = CreateWindowExA(0, "static", NULL,
3219 WS_CHILD| WS_VISIBLE | WS_CLIPSIBLINGS | WS_BORDER ,
3220 25, 50, 100, 100, parent, 0, 0, NULL);
3221 ShowWindow( parent, SW_SHOW);
3222 UpdateWindow( parent);
3223 GetClientRect( hwnd1, &rc);
3224 cliprc=rc;
3225 SetRectRgn( clipping, 10, 10, 90, 90);
3226 hdc = GetDC( hwnd1);
3227 /* for a visual touch */
3228 TextOut( hdc, 0,10, "0123456789", 10);
3229 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3230 if (winetest_debug > 0) dump_region(hrgn);
3231 /* create a region with what is expected */
3232 SetRectRgn( exprgn, 39,0,49,74);
3233 SetRectRgn( tmprgn, 88,79,98,93);
3234 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3235 SetRectRgn( tmprgn, 0,93,98,98);
3236 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3237 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3238 trace("update rect is %d,%d - %d,%d\n",
3239 rcu.left,rcu.top,rcu.right,rcu.bottom);
3240 /* now with clipping region */
3241 SelectClipRgn( hdc, clipping);
3242 ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
3243 if (winetest_debug > 0) dump_region(hrgn);
3244 /* create a region with what is expected */
3245 SetRectRgn( exprgn, 39,10,49,74);
3246 SetRectRgn( tmprgn, 80,79,90,85);
3247 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3248 SetRectRgn( tmprgn, 10,85,90,90);
3249 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3250 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3251 trace("update rect is %d,%d - %d,%d\n",
3252 rcu.left,rcu.top,rcu.right,rcu.bottom);
3253 ReleaseDC( hwnd1, hdc);
3254
3255 /* test scrolling a window with an update region */
3256 DestroyWindow( hwnd2);
3257 ValidateRect( hwnd1, NULL);
3258 SetRect( &rc, 40,40, 50,50);
3259 InvalidateRect( hwnd1, &rc, 1);
3260 GetClientRect( hwnd1, &rc);
3261 cliprc=rc;
3262 ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
3263 SW_SCROLLCHILDREN | SW_INVALIDATE);
3264 if (winetest_debug > 0) dump_region(hrgn);
3265 SetRectRgn( exprgn, 88,0,98,98);
3266 SetRectRgn( tmprgn, 30, 40, 50, 50);
3267 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3268 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3269
3270 /* clear an update region */
3271 UpdateWindow( hwnd1 );
3272
3273 SetRect( &rc, 0,40, 100,60);
3274 SetRect( &cliprc, 0,0, 100,100);
3275 ScrollWindowEx( hwnd1, 0, -25, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3276 if (winetest_debug > 0) dump_region( hrgn );
3277 SetRectRgn( exprgn, 0, 40, 98, 60 );
3278 ok( EqualRgn( exprgn, hrgn), "wrong update region in excessive scroll\n");
3279
3280 /* now test ScrollWindowEx with a combination of
3281 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3282 /* make hwnd2 the child of hwnd1 */
3283 hwnd2 = CreateWindowExA(0, "static", NULL,
3284 WS_CHILD| WS_VISIBLE | WS_BORDER ,
3285 50, 50, 100, 100, hwnd1, 0, 0, NULL);
3286 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
3287 GetClientRect( hwnd1, &rc);
3288 cliprc=rc;
3289
3290 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3291 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3292 ValidateRect( hwnd1, NULL);
3293 ValidateRect( hwnd2, NULL);
3294 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
3295 SW_SCROLLCHILDREN | SW_INVALIDATE);
3296 if (winetest_debug > 0) dump_region(hrgn);
3297 SetRectRgn( exprgn, 88,0,98,88);
3298 SetRectRgn( tmprgn, 0,88,98,98);
3299 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3300 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3301
3302 /* SW_SCROLLCHILDREN */
3303 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3304 ValidateRect( hwnd1, NULL);
3305 ValidateRect( hwnd2, NULL);
3306 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
3307 if (winetest_debug > 0) dump_region(hrgn);
3308 /* expected region is the same as in previous test */
3309 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3310
3311 /* no SW_SCROLLCHILDREN */
3312 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
3313 ValidateRect( hwnd1, NULL);
3314 ValidateRect( hwnd2, NULL);
3315 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3316 if (winetest_debug > 0) dump_region(hrgn);
3317 /* expected region is the same as in previous test */
3318 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3319
3320 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3321 SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
3322 ValidateRect( hwnd1, NULL);
3323 ValidateRect( hwnd2, NULL);
3324 ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
3325 if (winetest_debug > 0) dump_region(hrgn);
3326 SetRectRgn( exprgn, 88,0,98,20);
3327 SetRectRgn( tmprgn, 20,20,98,30);
3328 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3329 SetRectRgn( tmprgn, 20,30,30,88);
3330 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3331 SetRectRgn( tmprgn, 0,88,30,98);
3332 CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
3333 ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
3334
3335 /* clean up */
3336 DeleteObject( hrgn);
3337 DeleteObject( exprgn);
3338 DeleteObject( tmprgn);
3339 DestroyWindow( hwnd1);
3340 DestroyWindow( hwnd2);
3341 }
3342
3343 /* couple of tests of return values of scrollbar functions
3344 * called on a scrollbarless window */
3345 static void test_scroll(void)
3346 {
3347 BOOL ret;
3348 INT min, max;
3349 SCROLLINFO si;
3350 HWND hwnd = CreateWindowExA(0, "Static", "Wine test window",
3351 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP,
3352 100, 100, 200, 200, 0, 0, 0, NULL);
3353 /* horizontal */
3354 ret = GetScrollRange( hwnd, SB_HORZ, &min, &max);
3355 if (!ret) /* win9x */
3356 {
3357 win_skip( "GetScrollRange doesn't work\n" );
3358 DestroyWindow( hwnd);
3359 return;
3360 }
3361 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3362 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3363 si.cbSize = sizeof( si);
3364 si.fMask = SIF_PAGE;
3365 si.nPage = 0xdeadbeef;
3366 ret = GetScrollInfo( hwnd, SB_HORZ, &si);
3367 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3368 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3369 /* vertical */
3370 ret = GetScrollRange( hwnd, SB_VERT, &min, &max);
3371 ok( ret, "GetScrollRange returns FALSE\n");
3372 ok( min == 0, "minimum scroll pos is %d (should be zero)\n", min);
3373 ok( max == 0, "maximum scroll pos is %d (should be zero)\n", min);
3374 si.cbSize = sizeof( si);
3375 si.fMask = SIF_PAGE;
3376 si.nPage = 0xdeadbeef;
3377 ret = GetScrollInfo( hwnd, SB_VERT, &si);
3378 ok( !ret, "GetScrollInfo returns %d (should be zero)\n", ret);
3379 ok( si.nPage == 0xdeadbeef, "unexpected value for nPage is %d\n", si.nPage);
3380 /* clean up */
3381 DestroyWindow( hwnd);
3382 }
3383
3384 static void test_scrolldc( HWND parent)
3385 {
3386 HDC hdc;
3387 HRGN exprgn, tmprgn, hrgn;
3388 RECT rc, rc2, rcu, cliprc;
3389 HWND hwnd1;
3390 COLORREF colr;
3391
3392 hrgn = CreateRectRgn(0,0,0,0);
3393 tmprgn = CreateRectRgn(0,0,0,0);
3394 exprgn = CreateRectRgn(0,0,0,0);
3395
3396 hwnd1 = CreateWindowExA(0, "static", NULL,
3397 WS_CHILD| WS_VISIBLE,
3398 25, 50, 100, 100, parent, 0, 0, NULL);
3399 ShowWindow( parent, SW_SHOW);
3400 UpdateWindow( parent);
3401 flush_events( TRUE );
3402 GetClientRect( hwnd1, &rc);
3403 hdc = GetDC( hwnd1);
3404 /* paint the upper half of the window black */
3405 rc2 = rc;
3406 rc2.bottom = ( rc.top + rc.bottom) /2;
3407 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3408 /* clip region is the lower half */
3409 cliprc=rc;
3410 cliprc.top = (rc.top + rc.bottom) /2;
3411 /* test whether scrolled pixels are properly clipped */
3412 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3413 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3414 /* this scroll should not cause any visible changes */
3415 ScrollDC( hdc, 5, -20, &rc, &cliprc, hrgn, &rcu);
3416 colr = GetPixel( hdc, (rc.left+rc.right)/2, ( rc.top + rc.bottom) /2 - 1);
3417 ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
3418 /* test with NULL clip rect */
3419 ScrollDC( hdc, 20, -20, &rc, NULL, hrgn, &rcu);
3420 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3421 trace("update rect: %d,%d - %d,%d\n",
3422 rcu.left, rcu.top, rcu.right, rcu.bottom);
3423 if (winetest_debug > 0) dump_region(hrgn);
3424 SetRect(&rc2, 0, 0, 100, 100);
3425 ok(EqualRect(&rcu, &rc2), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3426 rcu.left, rcu.top, rcu.right, rcu.bottom, rc2.left, rc2.top, rc2.right, rc2.bottom);
3427
3428 SetRectRgn( exprgn, 0, 0, 20, 80);
3429 SetRectRgn( tmprgn, 0, 80, 100, 100);
3430 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3431 if (winetest_debug > 0) dump_region(exprgn);
3432 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3433 /* test clip rect > scroll rect */
3434 FillRect( hdc, &rc, GetStockObject(WHITE_BRUSH));
3435 rc2=rc;
3436 InflateRect( &rc2, -(rc.right-rc.left)/4, -(rc.bottom-rc.top)/4);
3437 FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
3438 ScrollDC( hdc, 10, 10, &rc2, &rc, hrgn, &rcu);
3439 SetRectRgn( exprgn, 25, 25, 75, 35);
3440 SetRectRgn( tmprgn, 25, 35, 35, 75);
3441 CombineRgn(exprgn, exprgn, tmprgn, RGN_OR);
3442 ok(EqualRgn(exprgn, hrgn), "wrong update region\n");
3443 trace("update rect: %d,%d - %d,%d\n",
3444 rcu.left, rcu.top, rcu.right, rcu.bottom);
3445 if (winetest_debug > 0) dump_region(hrgn);
3446
3447 /* clean up */
3448 DeleteObject(hrgn);
3449 DeleteObject(exprgn);
3450 DeleteObject(tmprgn);
3451 DestroyWindow(hwnd1);
3452 }
3453
3454 static void test_params(void)
3455 {
3456 HWND hwnd;
3457 INT rc;
3458
3459 /* Just a param check */
3460 if (pGetMonitorInfoA)
3461 {
3462 SetLastError(0xdeadbeef);
3463 rc = GetWindowText(hwndMain2, NULL, 1024);
3464 ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
3465 }
3466 else
3467 {
3468 /* Skips actually on Win95 and NT4 */
3469 win_skip("Test would crash on Win95\n");
3470 }
3471
3472 SetLastError(0xdeadbeef);
3473 hwnd=CreateWindow("LISTBOX", "TestList",
3474 (LBS_STANDARD & ~LBS_SORT),
3475 0, 0, 100, 100,
3476 NULL, (HMENU)1, NULL, 0);
3477
3478 ok(!hwnd || broken(hwnd != NULL), /* w2k3 sp2 */
3479 "CreateWindow with invalid menu handle should fail\n");
3480 if (!hwnd)
3481 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE || /* NT */
3482 GetLastError() == 0xdeadbeef, /* Win9x */
3483 "wrong last error value %d\n", GetLastError());
3484 }
3485
3486 static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
3487 {
3488 HWND hwnd = 0;
3489
3490 hwnd = CreateWindowEx(exStyle, class, class, style,
3491 110, 100,
3492 225, 200,
3493 0,
3494 menu ? hmenu : 0,
3495 0, 0);
3496 if (!hwnd) {
3497 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style, exStyle);
3498 return;
3499 }
3500 ShowWindow(hwnd, SW_SHOW);
3501
3502 test_nonclient_area(hwnd);
3503
3504 SetMenu(hwnd, 0);
3505 DestroyWindow(hwnd);
3506 }
3507
3508 static BOOL AWR_init(void)
3509 {
3510 WNDCLASS class;
3511
3512 class.style = CS_HREDRAW | CS_VREDRAW;
3513 class.lpfnWndProc = DefWindowProcA;
3514 class.cbClsExtra = 0;
3515 class.cbWndExtra = 0;
3516 class.hInstance = 0;
3517 class.hIcon = LoadIcon (0, IDI_APPLICATION);
3518 class.hCursor = LoadCursor (0, IDC_ARROW);
3519 class.hbrBackground = 0;
3520 class.lpszMenuName = 0;
3521 class.lpszClassName = szAWRClass;
3522
3523 if (!RegisterClass (&class)) {
3524 ok(FALSE, "RegisterClass failed\n");
3525 return FALSE;
3526 }
3527
3528 hmenu = CreateMenu();
3529 if (!hmenu)
3530 return FALSE;
3531 ok(hmenu != 0, "Failed to create menu\n");
3532 ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
3533
3534 return TRUE;
3535 }
3536
3537
3538 static void test_AWR_window_size(BOOL menu)
3539 {
3540 LONG styles[] = {
3541 WS_POPUP,
3542 WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME,
3543 WS_SYSMENU,
3544 WS_THICKFRAME,
3545 WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
3546 WS_HSCROLL, WS_VSCROLL
3547 };
3548 LONG exStyles[] = {
3549 WS_EX_CLIENTEDGE,
3550 WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
3551 WS_EX_APPWINDOW,
3552 #if 0
3553 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3554 WS_EX_DLGMODALFRAME,
3555 WS_EX_STATICEDGE,
3556 #endif
3557 };
3558
3559 int i;
3560
3561 /* A exhaustive check of all the styles takes too long
3562 * so just do a (hopefully representative) sample
3563 */
3564 for (i = 0; i < COUNTOF(styles); ++i)
3565 test_AWRwindow(szAWRClass, styles[i], 0, menu);
3566 for (i = 0; i < COUNTOF(exStyles); ++i) {
3567 test_AWRwindow(szAWRClass, WS_POPUP, exStyles[i], menu);
3568 test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
3569 }
3570 }
3571 #undef COUNTOF
3572
3573 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3574
3575 static void test_AdjustWindowRect(void)
3576 {
3577 if (!AWR_init())
3578 return;
3579
3580 SHOWSYSMETRIC(SM_CYCAPTION);
3581 SHOWSYSMETRIC(SM_CYSMCAPTION);
3582 SHOWSYSMETRIC(SM_CYMENU);
3583 SHOWSYSMETRIC(SM_CXEDGE);
3584 SHOWSYSMETRIC(SM_CYEDGE);
3585 SHOWSYSMETRIC(SM_CXVSCROLL);
3586 SHOWSYSMETRIC(SM_CYHSCROLL);
3587 SHOWSYSMETRIC(SM_CXFRAME);
3588 SHOWSYSMETRIC(SM_CYFRAME);
3589 SHOWSYSMETRIC(SM_CXDLGFRAME);
3590 SHOWSYSMETRIC(SM_CYDLGFRAME);
3591 SHOWSYSMETRIC(SM_CXBORDER);
3592 SHOWSYSMETRIC(SM_CYBORDER);
3593
3594 test_AWR_window_size(FALSE);
3595 test_AWR_window_size(TRUE);
3596
3597 DestroyMenu(hmenu);
3598 }
3599 #undef SHOWSYSMETRIC
3600
3601
3602 /* Global variables to trigger exit from loop */
3603 static int redrawComplete, WMPAINT_count;
3604
3605 static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3606 {
3607 switch (msg)
3608 {
3609 case WM_PAINT:
3610 trace("doing WM_PAINT %d\n", WMPAINT_count);
3611 WMPAINT_count++;
3612 if (WMPAINT_count > 10 && redrawComplete == 0) {
3613 PAINTSTRUCT ps;
3614 BeginPaint(hwnd, &ps);
3615 EndPaint(hwnd, &ps);
3616 return 1;
3617 }
3618 return 0;
3619 }
3620 return DefWindowProc(hwnd, msg, wparam, lparam);
3621 }
3622
3623 /* Ensure we exit from RedrawNow regardless of invalidated area */
3624 static void test_redrawnow(void)
3625 {
3626 WNDCLASSA cls;
3627 HWND hwndMain;
3628
3629 cls.style = CS_DBLCLKS;
3630 cls.lpfnWndProc = redraw_window_procA;
3631 cls.cbClsExtra = 0;
3632 cls.cbWndExtra = 0;
3633 cls.hInstance = GetModuleHandleA(0);
3634 cls.hIcon = 0;
3635 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3636 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3637 cls.lpszMenuName = NULL;
3638 cls.lpszClassName = "RedrawWindowClass";
3639
3640 if(!RegisterClassA(&cls)) {
3641 trace("Register failed %d\n", GetLastError());
3642 return;
3643 }
3644
3645 hwndMain = CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3646 CW_USEDEFAULT, 0, 100, 100, NULL, NULL, 0, NULL);
3647
3648 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3649 ShowWindow(hwndMain, SW_SHOW);
3650 ok( WMPAINT_count == 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3651 RedrawWindow(hwndMain, NULL,NULL,RDW_UPDATENOW | RDW_ALLCHILDREN);
3652 ok( WMPAINT_count == 1 || broken(WMPAINT_count == 0), /* sometimes on win9x */
3653 "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count);
3654 redrawComplete = TRUE;
3655 ok( WMPAINT_count < 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count);
3656
3657 /* clean up */
3658 DestroyWindow( hwndMain);
3659 }
3660
3661 struct parentdc_stat {
3662 RECT client;
3663 RECT clip;
3664 RECT paint;
3665 };
3666
3667 struct parentdc_test {
3668 struct parentdc_stat main, main_todo;
3669 struct parentdc_stat child1, child1_todo;
3670 struct parentdc_stat child2, child2_todo;
3671 };
3672
3673 static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3674 {
3675 RECT rc;
3676 PAINTSTRUCT ps;
3677
3678 struct parentdc_stat *t = (struct parentdc_stat *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
3679
3680 switch (msg)
3681 {
3682 case WM_PAINT:
3683 GetClientRect(hwnd, &rc);
3684 CopyRect(&t->client, &rc);
3685 GetWindowRect(hwnd, &rc);
3686 trace("WM_PAINT: hwnd %p, client rect (%d,%d)-(%d,%d), window rect (%d,%d)-(%d,%d)\n", hwnd,
3687 t->client.left, t->client.top, t->client.right, t->client.bottom,
3688 rc.left, rc.top, rc.right, rc.bottom);
3689 BeginPaint(hwnd, &ps);
3690 CopyRect(&t->paint, &ps.rcPaint);
3691 GetClipBox(ps.hdc, &rc);
3692 CopyRect(&t->clip, &rc);
3693 trace("clip rect (%d,%d)-(%d,%d), paint rect (%d,%d)-(%d,%d)\n",
3694 rc.left, rc.top, rc.right, rc.bottom,
3695 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
3696 EndPaint(hwnd, &ps);
3697 return 0;
3698 }
3699 return DefWindowProc(hwnd, msg, wparam, lparam);
3700 }
3701
3702 static void zero_parentdc_stat(struct parentdc_stat *t)
3703 {
3704 SetRectEmpty(&t->client);
3705 SetRectEmpty(&t->clip);
3706 SetRectEmpty(&t->paint);
3707 }
3708
3709 static void zero_parentdc_test(struct parentdc_test *t)
3710 {
3711 zero_parentdc_stat(&t->main);
3712 zero_parentdc_stat(&t->child1);
3713 zero_parentdc_stat(&t->child2);
3714 }
3715
3716 #define parentdc_field_ok(t, w, r, f, got) \
3717 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3718 ": expected %d, got %d\n", \
3719 t.w.r.f, got.w.r.f)
3720
3721 #define parentdc_todo_field_ok(t, w, r, f, got) \
3722 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3723 else parentdc_field_ok(t, w, r, f, got)
3724
3725 #define parentdc_rect_ok(t, w, r, got) \
3726 parentdc_todo_field_ok(t, w, r, left, got); \
3727 parentdc_todo_field_ok(t, w, r, top, got); \
3728 parentdc_todo_field_ok(t, w, r, right, got); \
3729 parentdc_todo_field_ok(t, w, r, bottom, got);
3730
3731 #define parentdc_win_ok(t, w, got) \
3732 parentdc_rect_ok(t, w, client, got); \
3733 parentdc_rect_ok(t, w, clip, got); \
3734 parentdc_rect_ok(t, w, paint, got);
3735
3736 #define parentdc_ok(t, got) \
3737 parentdc_win_ok(t, main, got); \
3738 parentdc_win_ok(t, child1, got); \
3739 parentdc_win_ok(t, child2, got);
3740
3741 static void test_csparentdc(void)
3742 {
3743 WNDCLASSA clsMain, cls;
3744 HWND hwndMain, hwnd1, hwnd2;
3745 RECT rc;
3746
3747 struct parentdc_test test_answer;
3748
3749 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3750 const struct parentdc_test test1 =
3751 {
3752 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo,
3753 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3754 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3755 };
3756
3757 const struct parentdc_test test2 =
3758 {
3759 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo,
3760 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3761 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3762 };
3763
3764 const struct parentdc_test test3 =
3765 {
3766 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3767 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3768 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3769 };
3770
3771 const struct parentdc_test test4 =
3772 {
3773 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo,
3774 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo,
3775 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3776 };
3777
3778 const struct parentdc_test test5 =
3779 {
3780 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo,
3781 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3782 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3783 };
3784
3785 const struct parentdc_test test6 =
3786 {
3787 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3788 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo,
3789 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3790 };
3791
3792 const struct parentdc_test test7 =
3793 {
3794 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3795 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3796 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo,
3797 };
3798 #undef nothing_todo
3799
3800 clsMain.style = CS_DBLCLKS;
3801 clsMain.lpfnWndProc = parentdc_window_procA;
3802 clsMain.cbClsExtra = 0;
3803 clsMain.cbWndExtra = 0;
3804 clsMain.hInstance = GetModuleHandleA(0);
3805 clsMain.hIcon = 0;
3806 clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
3807 clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
3808 clsMain.lpszMenuName = NULL;
3809 clsMain.lpszClassName = "ParentDcMainWindowClass";
3810
3811 if(!RegisterClassA(&clsMain)) {
3812 trace("Register failed %d\n", GetLastError());
3813 return;
3814 }
3815
3816 cls.style = CS_DBLCLKS | CS_PARENTDC;
3817 cls.lpfnWndProc = parentdc_window_procA;
3818 cls.cbClsExtra = 0;
3819 cls.cbWndExtra = 0;
3820 cls.hInstance = GetModuleHandleA(0);
3821 cls.hIcon = 0;
3822 cls.hCursor = LoadCursorA(0, IDC_ARROW);
3823 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
3824 cls.lpszMenuName = NULL;
3825 cls.lpszClassName = "ParentDcWindowClass";
3826
3827 if(!RegisterClassA(&cls)) {
3828 trace("Register failed %d\n", GetLastError());
3829 return;
3830 }
3831
3832 SetRect(&rc, 0, 0, 150, 150);
3833 AdjustWindowRectEx(&rc, WS_OVERLAPPEDWINDOW, FALSE, 0);
3834 hwndMain = CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW,
3835 CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, 0, NULL);
3836 SetWindowLongPtrA(hwndMain, GWLP_USERDATA, (DWORD_PTR)&test_answer.main);
3837 hwnd1 = CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD,
3838 20, 20, 40, 40, hwndMain, NULL, 0, NULL);
3839 SetWindowLongPtrA(hwnd1, GWLP_USERDATA, (DWORD_PTR)&test_answer.child1);
3840 hwnd2 = CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD,
3841 40, 40, 40, 40, hwndMain, NULL, 0, NULL);
3842 SetWindowLongPtrA(hwnd2, GWLP_USERDATA, (DWORD_PTR)&test_answer.child2);
3843 ShowWindow(hwndMain, SW_SHOW);
3844 ShowWindow(hwnd1, SW_SHOW);
3845 ShowWindow(hwnd2, SW_SHOW);
3846 SetWindowPos(hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
3847 flush_events( TRUE );
3848
3849 zero_parentdc_test(&test_answer);
3850 InvalidateRect(hwndMain, NULL, TRUE);
3851 flush_events( TRUE );
3852 parentdc_ok(test1, test_answer);
3853
3854 zero_parentdc_test(&test_answer);
3855 SetRect(&rc, 0, 0, 50, 50);
3856 InvalidateRect(hwndMain, &rc, TRUE);
3857 flush_events( TRUE );
3858 parentdc_ok(test2, test_answer);
3859
3860 zero_parentdc_test(&test_answer);
3861 SetRect(&rc, 0, 0, 10, 10);
3862 InvalidateRect(hwndMain, &rc, TRUE);
3863 flush_events( TRUE );
3864 parentdc_ok(test3, test_answer);
3865
3866 zero_parentdc_test(&test_answer);
3867 SetRect(&rc, 40, 40, 50, 50);
3868 InvalidateRect(hwndMain, &rc, TRUE);
3869 flush_events( TRUE );
3870 parentdc_ok(test4, test_answer);
3871
3872 zero_parentdc_test(&test_answer);
3873 SetRect(&rc, 20, 20, 60, 60);
3874 InvalidateRect(hwndMain, &rc, TRUE);
3875 flush_events( TRUE );
3876 parentdc_ok(test5, test_answer);
3877
3878 zero_parentdc_test(&test_answer);
3879 SetRect(&rc, 0, 0, 10, 10);
3880 InvalidateRect(hwnd1, &rc, TRUE);
3881 flush_events( TRUE );
3882 parentdc_ok(test6, test_answer);
3883
3884 zero_parentdc_test(&test_answer);
3885 SetRect(&rc, -5, -5, 65, 65);
3886 InvalidateRect(hwnd1, &rc, TRUE);
3887 flush_events( TRUE );
3888 parentdc_ok(test7, test_answer);
3889
3890 DestroyWindow(hwndMain);
3891 DestroyWindow(hwnd1);
3892 DestroyWindow(hwnd2);
3893 }
3894
3895 static LRESULT WINAPI def_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3896 {
3897 return DefWindowProcA(hwnd, msg, wparam, lparam);
3898 }
3899
3900 static LRESULT WINAPI def_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
3901 {
3902 return DefWindowProcW(hwnd, msg, wparam, lparam);
3903 }
3904
3905 static void test_IsWindowUnicode(void)
3906 {
3907 static const char ansi_class_nameA[] = "ansi class name";
3908 static const WCHAR ansi_class_nameW[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3909 static const char unicode_class_nameA[] = "unicode class name";
3910 static const WCHAR unicode_class_nameW[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3911 WNDCLASSA classA;
3912 WNDCLASSW classW;
3913 HWND hwnd;
3914
3915 memset(&classW, 0, sizeof(classW));
3916 classW.hInstance = GetModuleHandleA(0);
3917 classW.lpfnWndProc = def_window_procW;
3918 classW.lpszClassName = unicode_class_nameW;
3919 if (!RegisterClassW(&classW)) return; /* this catches Win9x as well */
3920
3921 memset(&classA, 0, sizeof(classA));
3922 classA.hInstance = GetModuleHandleA(0);
3923 classA.lpfnWndProc = def_window_procA;
3924 classA.lpszClassName = ansi_class_nameA;
3925 assert(RegisterClassA(&classA));
3926
3927 /* unicode class: window proc */
3928 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3929 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3930 assert(hwnd);
3931
3932 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3933 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3934 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3935 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3936 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3937
3938 DestroyWindow(hwnd);
3939
3940 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3941 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3942 assert(hwnd);
3943
3944 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3945 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3946 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3947 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3948 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3949
3950 DestroyWindow(hwnd);
3951
3952 /* ansi class: window proc */
3953 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
3954 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3955 assert(hwnd);
3956
3957 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3958 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3959 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3960 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3961 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3962
3963 DestroyWindow(hwnd);
3964
3965 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
3966 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3967 assert(hwnd);
3968
3969 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3970 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procW);
3971 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3972 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (ULONG_PTR)def_window_procA);
3973 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3974
3975 DestroyWindow(hwnd);
3976
3977 /* unicode class: class proc */
3978 hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
3979 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3980 assert(hwnd);
3981
3982 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3983 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
3984 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
3985 /* do not restore class window proc back to unicode */
3986
3987 DestroyWindow(hwnd);
3988
3989 hwnd = CreateWindowExA(0, unicode_class_nameA, NULL, WS_POPUP,
3990 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
3991 assert(hwnd);
3992
3993 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3994 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
3995 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
3996
3997 DestroyWindow(hwnd);
3998
3999 /* ansi class: class proc */
4000 hwnd = CreateWindowExW(0, ansi_class_nameW, NULL, WS_POPUP,
4001 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4002 assert(hwnd);
4003
4004 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4005 SetClassLongPtrW(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procW);
4006 ok(!IsWindowUnicode(hwnd), "IsWindowUnicode expected to return FALSE\n");
4007 /* do not restore class window proc back to ansi */
4008
4009 DestroyWindow(hwnd);
4010
4011 hwnd = CreateWindowExA(0, ansi_class_nameA, NULL, WS_POPUP,
4012 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL);
4013 assert(hwnd);
4014
4015 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4016 SetClassLongPtrA(hwnd, GCLP_WNDPROC, (ULONG_PTR)def_window_procA);
4017 ok(IsWindowUnicode(hwnd), "IsWindowUnicode expected to return TRUE\n");
4018
4019 DestroyWindow(hwnd);
4020 }
4021
4022 static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4023 {
4024 MINMAXINFO *minmax;
4025
4026 if (msg != WM_GETMINMAXINFO)
4027 return DefWindowProc(hwnd, msg, wp, lp);
4028
4029 minmax = (MINMAXINFO *)lp;
4030
4031 if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
4032 {
4033 minmax->ptReserved.x = 0;
4034 minmax->ptReserved.y = 0;
4035 minmax->ptMaxSize.x = 400;
4036 minmax->ptMaxSize.y = 400;
4037 minmax->ptMaxPosition.x = 300;
4038 minmax->ptMaxPosition.y = 300;
4039 minmax->ptMaxTrackSize.x = 200;
4040 minmax->ptMaxTrackSize.y = 200;
4041 minmax->ptMinTrackSize.x = 100;
4042 minmax->ptMinTrackSize.y = 100;
4043 }
4044 else
4045 DefWindowProc(hwnd, msg, wp, lp);
4046 return 1;
4047 }
4048
4049 static int expected_cx, expected_cy;
4050 static RECT expected_rect, broken_rect;
4051
4052 static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
4053 {
4054 switch(msg)
4055 {
4056 case WM_GETMINMAXINFO:
4057 {
4058 RECT rect;
4059 GetWindowRect( hwnd, &rect );
4060 ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
4061 "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4062 return DefWindowProc(hwnd, msg, wp, lp);
4063 }
4064 case WM_NCCREATE:
4065 case WM_CREATE:
4066 {
4067 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
4068 RECT rect;
4069 GetWindowRect( hwnd, &rect );
4070 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
4071 hwnd, msg, cs->cx, cs->cy, rect.left, rect.top, rect.right, rect.bottom );
4072 ok( cs->cx == expected_cx || broken(cs->cx == (short)expected_cx),
4073 "wrong x size %d/%d\n", cs->cx, expected_cx );
4074 ok( cs->cy == expected_cy || broken(cs->cy == (short)expected_cy),
4075 "wrong y size %d/%d\n", cs->cy, expected_cy );
4076 ok( (rect.right - rect.left == expected_rect.right - expected_rect.left &&
4077 rect.bottom - rect.top == expected_rect.bottom - expected_rect.top) ||
4078 broken( rect.right - rect.left == broken_rect.right - broken_rect.left &&
4079 rect.bottom - rect.top == broken_rect.bottom - broken_rect.top) ||
4080 broken( rect.right - rect.left == (short)broken_rect.right - (short)broken_rect.left &&
4081 rect.bottom - rect.top == (short)broken_rect.bottom - (short)broken_rect.top),
4082 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
4083 rect.left, rect.top, rect.right, rect.bottom,
4084 expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
4085 return DefWindowProc(hwnd, msg, wp, lp);
4086 }
4087 case WM_NCCALCSIZE:
4088 {
4089 RECT rect, *r = (RECT *)lp;
4090 GetWindowRect( hwnd, &rect );
4091 ok( !memcmp( &rect, r, sizeof(rect) ),
4092 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
4093 r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
4094 return DefWindowProc(hwnd, msg, wp, lp);
4095 }
4096 default:
4097 return DefWindowProc(hwnd, msg, wp, lp);
4098 }
4099 }
4100
4101 static void test_CreateWindow(void)
4102 {
4103 WNDCLASS cls;
4104 HWND hwnd, parent;
4105 HMENU hmenu;
4106 RECT rc, rc_minmax;
4107 MINMAXINFO minmax;
4108
4109 #define expect_menu(window, menu) \
4110 SetLastError(0xdeadbeef); \
4111 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
4112
4113 #define expect_style(window, style)\
4114 ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
4115
4116 #define expect_ex_style(window, ex_style)\
4117 ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
4118
4119 #define expect_gle_broken_9x(gle)\
4120 ok(GetLastError() == gle ||\
4121 broken(GetLastError() == 0xdeadbeef),\
4122 "IsMenu set error %d\n", GetLastError())
4123
4124 hmenu = CreateMenu();
4125 assert(hmenu != 0);
4126 parent = GetDesktopWindow();
4127 assert(parent != 0);
4128
4129 SetLastError(0xdeadbeef);
4130 ok(IsMenu(hmenu), "IsMenu error %d\n", GetLastError());
4131
4132 /* WS_CHILD */
4133 SetLastError(0xdeadbeef);
4134 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
4135 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4136 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4137 expect_menu(hwnd, 1);
4138 expect_style(hwnd, WS_CHILD);
4139 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4140 DestroyWindow(hwnd);
4141
4142 SetLastError(0xdeadbeef);
4143 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
4144 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4145 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4146 expect_menu(hwnd, 1);
4147 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4148 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4149 DestroyWindow(hwnd);
4150
4151 SetLastError(0xdeadbeef);
4152 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
4153 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4154 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4155 expect_menu(hwnd, 1);
4156 expect_style(hwnd, WS_CHILD);
4157 expect_ex_style(hwnd, 0);
4158 DestroyWindow(hwnd);
4159
4160 SetLastError(0xdeadbeef);
4161 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
4162 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4163 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4164 expect_menu(hwnd, 1);
4165 expect_style(hwnd, WS_CHILD | WS_CAPTION);
4166 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4167 DestroyWindow(hwnd);
4168
4169 /* WS_POPUP */
4170 SetLastError(0xdeadbeef);
4171 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
4172 0, 0, 100, 100, parent, hmenu, 0, NULL);
4173 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4174 expect_menu(hwnd, hmenu);
4175 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4176 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4177 DestroyWindow(hwnd);
4178 SetLastError(0xdeadbeef);
4179 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4180 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4181
4182 hmenu = CreateMenu();
4183 assert(hmenu != 0);
4184 SetLastError(0xdeadbeef);
4185 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
4186 0, 0, 100, 100, parent, hmenu, 0, NULL);
4187 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4188 expect_menu(hwnd, hmenu);
4189 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4190 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4191 DestroyWindow(hwnd);
4192 SetLastError(0xdeadbeef);
4193 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4194 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4195
4196 hmenu = CreateMenu();
4197 assert(hmenu != 0);
4198 SetLastError(0xdeadbeef);
4199 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
4200 0, 0, 100, 100, parent, hmenu, 0, NULL);
4201 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4202 expect_menu(hwnd, hmenu);
4203 expect_style(hwnd, WS_POPUP | WS_CLIPSIBLINGS);
4204 expect_ex_style(hwnd, 0);
4205 DestroyWindow(hwnd);
4206 SetLastError(0xdeadbeef);
4207 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4208 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4209
4210 hmenu = CreateMenu();
4211 assert(hmenu != 0);
4212 SetLastError(0xdeadbeef);
4213 hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
4214 0, 0, 100, 100, parent, hmenu, 0, NULL);
4215 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4216 expect_menu(hwnd, hmenu);
4217 expect_style(hwnd, WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4218 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4219 DestroyWindow(hwnd);
4220 SetLastError(0xdeadbeef);
4221 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4222 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4223
4224 /* WS_CHILD | WS_POPUP */
4225 SetLastError(0xdeadbeef);
4226 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4227 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4228 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4229 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4230 if (hwnd)
4231 DestroyWindow(hwnd);
4232
4233 hmenu = CreateMenu();
4234 assert(hmenu != 0);
4235 SetLastError(0xdeadbeef);
4236 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
4237 0, 0, 100, 100, parent, hmenu, 0, NULL);
4238 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4239 expect_menu(hwnd, hmenu);
4240 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4241 expect_ex_style(hwnd, WS_EX_APPWINDOW);
4242 DestroyWindow(hwnd);
4243 SetLastError(0xdeadbeef);
4244 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4245 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4246
4247 SetLastError(0xdeadbeef);
4248 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4249 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4250 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4251 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4252 if (hwnd)
4253 DestroyWindow(hwnd);
4254
4255 hmenu = CreateMenu();
4256 assert(hmenu != 0);
4257 SetLastError(0xdeadbeef);
4258 hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4259 0, 0, 100, 100, parent, hmenu, 0, NULL);
4260 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4261 expect_menu(hwnd, hmenu);
4262 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4263 expect_ex_style(hwnd, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
4264 DestroyWindow(hwnd);
4265 SetLastError(0xdeadbeef);
4266 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4267 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4268
4269 SetLastError(0xdeadbeef);
4270 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4271 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4272 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4273 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4274 if (hwnd)
4275 DestroyWindow(hwnd);
4276
4277 hmenu = CreateMenu();
4278 assert(hmenu != 0);
4279 SetLastError(0xdeadbeef);
4280 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
4281 0, 0, 100, 100, parent, hmenu, 0, NULL);
4282 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4283 expect_menu(hwnd, hmenu);
4284 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CLIPSIBLINGS);
4285 expect_ex_style(hwnd, 0);
4286 DestroyWindow(hwnd);
4287 SetLastError(0xdeadbeef);
4288 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4289 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4290
4291 SetLastError(0xdeadbeef);
4292 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4293 0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
4294 ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
4295 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4296 if (hwnd)
4297 DestroyWindow(hwnd);
4298
4299 hmenu = CreateMenu();
4300 assert(hmenu != 0);
4301 SetLastError(0xdeadbeef);
4302 hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
4303 0, 0, 100, 100, parent, hmenu, 0, NULL);
4304 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4305 expect_menu(hwnd, hmenu);
4306 expect_style(hwnd, WS_CHILD | WS_POPUP | WS_CAPTION | WS_CLIPSIBLINGS);
4307 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4308 DestroyWindow(hwnd);
4309 SetLastError(0xdeadbeef);
4310 ok(!IsMenu(hmenu), "IsMenu should fail\n");
4311 expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
4312
4313 /* test child window sizing */
4314 cls.style = 0;
4315 cls.lpfnWndProc = minmax_wnd_proc;
4316 cls.cbClsExtra = 0;
4317 cls.cbWndExtra = 0;
4318 cls.hInstance = GetModuleHandle(0);
4319 cls.hIcon = 0;
4320 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4321 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4322 cls.lpszMenuName = NULL;
4323 cls.lpszClassName = "MinMax_WndClass";
4324 RegisterClass(&cls);
4325
4326 SetLastError(0xdeadbeef);
4327 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4328 0, 0, 100, 100, 0, 0, 0, NULL);
4329 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4330 expect_menu(parent, 0);
4331 expect_style(parent, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPSIBLINGS);
4332 expect_ex_style(parent, WS_EX_WINDOWEDGE);
4333
4334 memset(&minmax, 0, sizeof(minmax));
4335 SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4336 SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
4337 ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
4338 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4339 ok(IsRectEmpty(&rc_minmax), "ptMaxTrackSize is not empty\n");
4340
4341 GetWindowRect(parent, &rc);
4342 ok(!IsRectEmpty(&rc), "parent window rect is empty\n");
4343 GetClientRect(parent, &rc);
4344 ok(!IsRectEmpty(&rc), "parent client rect is empty\n");
4345
4346 InflateRect(&rc, 200, 200);
4347 trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
4348
4349 SetLastError(0xdeadbeef);
4350 hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
4351 rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
4352 parent, (HMENU)1, 0, NULL);
4353 ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
4354 expect_menu(hwnd, 1);
4355 expect_style(hwnd, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
4356 expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
4357
4358 memset(&minmax, 0, sizeof(minmax));
4359 SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
4360 SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
4361
4362 GetWindowRect(hwnd, &rc);
4363 OffsetRect(&rc, -rc.left, -rc.top);
4364 ok(EqualRect(&rc, &rc_minmax), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4365 rc.left, rc.top, rc.right, rc.bottom,
4366 rc_minmax.left, rc_minmax.top, rc_minmax.right, rc_minmax.bottom);
4367 DestroyWindow(hwnd);
4368
4369 cls.lpfnWndProc = winsizes_wnd_proc;
4370 cls.lpszClassName = "Sizes_WndClass";
4371 RegisterClass(&cls);
4372
4373 expected_cx = expected_cy = 200000;
4374 SetRect( &expected_rect, 0, 0, 200000, 200000 );
4375 broken_rect = expected_rect;
4376 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 300000, 300000, 200000, 200000, parent, 0, 0, NULL);
4377 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4378 GetClientRect( hwnd, &rc );
4379 ok( rc.right == 200000 || broken(rc.right == (short)200000), "invalid rect right %u\n", rc.right );
4380 ok( rc.bottom == 200000 || broken(rc.bottom == (short)200000), "invalid rect bottom %u\n", rc.bottom );
4381 DestroyWindow(hwnd);
4382
4383 expected_cx = expected_cy = -10;
4384 SetRect( &expected_rect, 0, 0, 0, 0 );
4385 SetRect( &broken_rect, 0, 0, -10, -10 );
4386 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
4387 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4388 GetClientRect( hwnd, &rc );
4389 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4390 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4391 DestroyWindow(hwnd);
4392
4393 expected_cx = expected_cy = -200000;
4394 SetRect( &expected_rect, 0, 0, 0, 0 );
4395 SetRect( &broken_rect, 0, 0, -200000, -200000 );
4396 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
4397 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4398 GetClientRect( hwnd, &rc );
4399 ok( rc.right == 0, "invalid rect right %u\n", rc.right );
4400 ok( rc.bottom == 0, "invalid rect bottom %u\n", rc.bottom );
4401 DestroyWindow(hwnd);
4402
4403 /* we need a parent at 0,0 so that child coordinates match */
4404 DestroyWindow(parent);
4405 parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
4406 ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
4407
4408 expected_cx = 100;
4409 expected_cy = 0x7fffffff;
4410 SetRect( &expected_rect, 10, 10, 110, 0x7fffffff );
4411 SetRect( &broken_rect, 10, 10, 110, 0x7fffffffU + 10 );
4412 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 10, 10, 100, 0x7fffffff, parent, 0, 0, NULL);
4413 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4414 GetClientRect( hwnd, &rc );
4415 ok( rc.right == 100, "invalid rect right %u\n", rc.right );
4416 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4417 DestroyWindow(hwnd);
4418
4419 expected_cx = 0x7fffffff;
4420 expected_cy = 0x7fffffff;
4421 SetRect( &expected_rect, 20, 10, 0x7fffffff, 0x7fffffff );
4422 SetRect( &broken_rect, 20, 10, 0x7fffffffU + 20, 0x7fffffffU + 10 );
4423 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, 20, 10, 0x7fffffff, 0x7fffffff, parent, 0, 0, NULL);
4424 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4425 GetClientRect( hwnd, &rc );
4426 ok( rc.right == 0x7fffffff - 20 || broken(rc.right == 0), "invalid rect right %u\n", rc.right );
4427 ok( rc.bottom == 0x7fffffff - 10 || broken(rc.bottom == 0), "invalid rect bottom %u\n", rc.bottom );
4428 DestroyWindow(hwnd);
4429
4430 /* top level window */
4431 expected_cx = expected_cy = 200000;
4432 SetRect( &expected_rect, 0, 0, GetSystemMetrics(SM_CXMAXTRACK), GetSystemMetrics(SM_CYMAXTRACK) );
4433 hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_OVERLAPPEDWINDOW, 300000, 300000, 200000, 200000, 0, 0, 0, NULL);
4434 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
4435 GetClientRect( hwnd, &rc );
4436 ok( rc.right <= expected_cx, "invalid rect right %u\n", rc.right );
4437 ok( rc.bottom <= expected_cy, "invalid rect bottom %u\n", rc.bottom );
4438 DestroyWindow(hwnd);
4439
4440 DestroyWindow(parent);
4441
4442 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4443 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4444
4445 #undef expect_gle_broken_9x
4446 #undef expect_menu
4447 #undef expect_style
4448 #undef expect_ex_style
4449 }
4450
4451 /* function that remembers whether the system the test is running on sets the
4452 * last error for user32 functions to make the tests stricter */
4453 static int check_error(DWORD actual, DWORD expected)
4454 {
4455 static int sets_last_error = -1;
4456 if (sets_last_error == -1)
4457 sets_last_error = (actual != 0xdeadbeef);
4458 return (!sets_last_error && (actual == 0xdeadbeef)) || (actual == expected);
4459 }
4460
4461 static void test_SetWindowLong(void)
4462 {
4463 LONG_PTR retval;
4464 WNDPROC old_window_procW;
4465
4466 SetLastError(0xdeadbeef);
4467 retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
4468 ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
4469 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
4470 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4471
4472 SetLastError(0xdeadbeef);
4473 retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
4474 ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
4475 ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
4476 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4477
4478 SetLastError(0xdeadbeef);
4479 retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4480 ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
4481 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
4482 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4483 retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
4484 ok((WNDPROC)retval == main_window_procA,
4485 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4486 ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
4487
4488 old_window_procW = (WNDPROC)GetWindowLongPtrW(hwndMain, GWLP_WNDPROC);
4489 SetLastError(0xdeadbeef);
4490 retval = SetWindowLongPtrW(hwndMain, GWLP_WNDPROC, 0);
4491 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
4492 {
4493 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4494 ok(retval != 0, "SetWindowLongPtr error %d\n", GetLastError());
4495 ok((WNDPROC)retval == old_window_procW,
4496 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
4497 ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
4498
4499 /* set it back to ANSI */
4500 SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
4501 }
4502 }
4503
4504 static void test_ShowWindow(void)
4505 {
4506 HWND hwnd;
4507 DWORD style;
4508 RECT rcMain, rc;
4509 LPARAM ret;
4510
4511 SetRect(&rcMain, 120, 120, 210, 210);
4512
4513 hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
4514 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
4515 WS_MAXIMIZEBOX | WS_POPUP,
4516 rcMain.left, rcMain.top,
4517 rcMain.right - rcMain.left, rcMain.bottom - rcMain.top,
4518 0, 0, 0, NULL);
4519 assert(hwnd);
4520
4521 style = GetWindowLong(hwnd, GWL_STYLE);
4522 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4523 ok(!(style & WS_VISIBLE), "window should not be visible\n");
4524 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4525 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4526 GetWindowRect(hwnd, &rc);
4527 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4528 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4529 rc.left, rc.top, rc.right, rc.bottom);
4530
4531 ret = ShowWindow(hwnd, SW_SHOW);
4532 ok(!ret, "not expected ret: %lu\n", ret);
4533 style = GetWindowLong(hwnd, GWL_STYLE);
4534 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4535 ok(style & WS_VISIBLE, "window should be visible\n");
4536 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4537 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4538 GetWindowRect(hwnd, &rc);
4539 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4540 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4541 rc.left, rc.top, rc.right, rc.bottom);
4542
4543 ret = ShowWindow(hwnd, SW_MINIMIZE);
4544 ok(ret, "not expected ret: %lu\n", ret);
4545 style = GetWindowLong(hwnd, GWL_STYLE);
4546 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4547 ok(style & WS_VISIBLE, "window should be visible\n");
4548 ok(style & WS_MINIMIZE, "window should be minimized\n");
4549 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4550 GetWindowRect(hwnd, &rc);
4551 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4552
4553 ShowWindow(hwnd, SW_RESTORE);
4554 ok(ret, "not expected ret: %lu\n", ret);
4555 style = GetWindowLong(hwnd, GWL_STYLE);
4556 ok(!(style & WS_DISABLED), "window should not be disabled\n");
4557 ok(style & WS_VISIBLE, "window should be visible\n");
4558 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4559 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4560 GetWindowRect(hwnd, &rc);
4561 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4562 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4563 rc.left, rc.top, rc.right, rc.bottom);
4564
4565 ret = EnableWindow(hwnd, FALSE);
4566 ok(!ret, "not expected ret: %lu\n", ret);
4567 style = GetWindowLong(hwnd, GWL_STYLE);
4568 ok(style & WS_DISABLED, "window should be disabled\n");
4569
4570 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
4571 ok(!ret, "not expected ret: %lu\n", ret);
4572 style = GetWindowLong(hwnd, GWL_STYLE);
4573 ok(style & WS_DISABLED, "window should be disabled\n");
4574 ok(style & WS_VISIBLE, "window should be visible\n");
4575 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4576 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4577 GetWindowRect(hwnd, &rc);
4578 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4579 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4580 rc.left, rc.top, rc.right, rc.bottom);
4581
4582 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
4583 ok(!ret, "not expected ret: %lu\n", ret);
4584 style = GetWindowLong(hwnd, GWL_STYLE);
4585 ok(style & WS_DISABLED, "window should be disabled\n");
4586 ok(style & WS_VISIBLE, "window should be visible\n");
4587 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4588 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4589 GetWindowRect(hwnd, &rc);
4590 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4591 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4592 rc.left, rc.top, rc.right, rc.bottom);
4593
4594 ret = ShowWindow(hwnd, SW_MINIMIZE);
4595 ok(ret, "not expected ret: %lu\n", ret);
4596 style = GetWindowLong(hwnd, GWL_STYLE);
4597 ok(style & WS_DISABLED, "window should be disabled\n");
4598 ok(style & WS_VISIBLE, "window should be visible\n");
4599 ok(style & WS_MINIMIZE, "window should be minimized\n");
4600 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4601 GetWindowRect(hwnd, &rc);
4602 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4603
4604 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
4605 ok(!ret, "not expected ret: %lu\n", ret);
4606 style = GetWindowLong(hwnd, GWL_STYLE);
4607 ok(style & WS_DISABLED, "window should be disabled\n");
4608 ok(style & WS_VISIBLE, "window should be visible\n");
4609 ok(style & WS_MINIMIZE, "window should be minimized\n");
4610 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4611 GetWindowRect(hwnd, &rc);
4612 ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
4613
4614 ret = ShowWindow(hwnd, SW_RESTORE);
4615 ok(ret, "not expected ret: %lu\n", ret);
4616 style = GetWindowLong(hwnd, GWL_STYLE);
4617 ok(style & WS_DISABLED, "window should be disabled\n");
4618 ok(style & WS_VISIBLE, "window should be visible\n");
4619 ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
4620 ok(!(style & WS_MAXIMIZE), "window should not be maximized\n");
4621 GetWindowRect(hwnd, &rc);
4622 ok(EqualRect(&rcMain, &rc), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4623 rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
4624 rc.left, rc.top, rc.right, rc.bottom);
4625
4626 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4627 ok(!ret, "not expected ret: %lu\n", ret);
4628 ok(IsWindow(hwnd), "window should exist\n");
4629
4630 ret = EnableWindow(hwnd, TRUE);
4631 ok(ret, "not expected ret: %lu\n", ret);
4632
4633 ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
4634 ok(!ret, "not expected ret: %lu\n", ret);
4635 ok(!IsWindow(hwnd), "window should not exist\n");
4636 }
4637
4638 static void test_gettext(void)
4639 {
4640 WNDCLASS cls;
4641 LPCSTR clsname = "gettexttest";
4642 HWND hwnd;
4643 LRESULT r;
4644
4645 memset( &cls, 0, sizeof cls );
4646 cls.lpfnWndProc = DefWindowProc;
4647 cls.lpszClassName = clsname;
4648 cls.hInstance = GetModuleHandle(NULL);
4649
4650 if (!RegisterClass( &cls )) return;
4651
4652 hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
4653 ok( hwnd != NULL, "window was null\n");
4654
4655 r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
4656 ok( r == 0, "settext should return zero\n");
4657
4658 r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
4659 ok( r == 0, "settext should return zero (%ld)\n", r);
4660
4661 r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
4662 ok( r == 0, "settext should return zero (%ld)\n", r);
4663
4664 r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
4665 ok( r == 0, "settext should return zero (%ld)\n", r);
4666
4667 DestroyWindow(hwnd);
4668 UnregisterClass( clsname, NULL );
4669 }
4670
4671
4672 static void test_GetUpdateRect(void)
4673 {
4674 MSG msg;
4675 BOOL ret, parent_wm_paint, grandparent_wm_paint;
4676 RECT rc1, rc2;
4677 HWND hgrandparent, hparent, hchild;
4678 WNDCLASSA cls;
4679 static const char classNameA[] = "GetUpdateRectClass";
4680
4681 hgrandparent = CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW,
4682 0, 0, 100, 100, NULL, NULL, 0, NULL);
4683
4684 hparent = CreateWindowA("static", "parent", WS_CHILD|WS_VISIBLE,
4685 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4686
4687 hchild = CreateWindowA("static", "child", WS_CHILD|WS_VISIBLE,
4688 10, 10, 30, 30, hparent, NULL, 0, NULL);
4689
4690 ShowWindow(hgrandparent, SW_SHOW);
4691 UpdateWindow(hgrandparent);
4692 flush_events( TRUE );
4693
4694 ShowWindow(hchild, SW_HIDE);
4695 SetRect(&rc2, 0, 0, 0, 0);
4696 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4697 ok(!ret, "GetUpdateRect returned not empty region\n");
4698 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4699 rc1.left, rc1.top, rc1.right, rc1.bottom,
4700 rc2.left, rc2.top, rc2.right, rc2.bottom);
4701
4702 SetRect(&rc2, 10, 10, 40, 40);
4703 ret = GetUpdateRect(hparent, &rc1, FALSE);
4704 ok(ret, "GetUpdateRect returned empty region\n");
4705 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4706 rc1.left, rc1.top, rc1.right, rc1.bottom,
4707 rc2.left, rc2.top, rc2.right, rc2.bottom);
4708
4709 parent_wm_paint = FALSE;
4710 grandparent_wm_paint = FALSE;
4711 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4712 {
4713 if (msg.message == WM_PAINT)
4714 {
4715 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4716 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4717 }
4718 DispatchMessage(&msg);
4719 }
4720 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4721 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4722
4723 DestroyWindow(hgrandparent);
4724
4725 cls.style = 0;
4726 cls.lpfnWndProc = DefWindowProcA;
4727 cls.cbClsExtra = 0;
4728 cls.cbWndExtra = 0;
4729 cls.hInstance = GetModuleHandleA(0);
4730 cls.hIcon = 0;
4731 cls.hCursor = LoadCursorA(0, IDC_ARROW);
4732 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4733 cls.lpszMenuName = NULL;
4734 cls.lpszClassName = classNameA;
4735
4736 if(!RegisterClassA(&cls)) {
4737 trace("Register failed %d\n", GetLastError());
4738 return;
4739 }
4740
4741 hgrandparent = CreateWindowA(classNameA, "grandparent", WS_OVERLAPPEDWINDOW,
4742 0, 0, 100, 100, NULL, NULL, 0, NULL);
4743
4744 hparent = CreateWindowA(classNameA, "parent", WS_CHILD|WS_VISIBLE,
4745 0, 0, 100, 100, hgrandparent, NULL, 0, NULL);
4746
4747 hchild = CreateWindowA(classNameA, "child", WS_CHILD|WS_VISIBLE,
4748 10, 10, 30, 30, hparent, NULL, 0, NULL);
4749
4750 ShowWindow(hgrandparent, SW_SHOW);
4751 UpdateWindow(hgrandparent);
4752 flush_events( TRUE );
4753
4754 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4755 ok(!ret, "GetUpdateRect returned not empty region\n");
4756
4757 ShowWindow(hchild, SW_HIDE);
4758
4759 SetRect(&rc2, 0, 0, 0, 0);
4760 ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
4761 ok(!ret, "GetUpdateRect returned not empty region\n");
4762 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4763 rc1.left, rc1.top, rc1.right, rc1.bottom,
4764 rc2.left, rc2.top, rc2.right, rc2.bottom);
4765
4766 SetRect(&rc2, 10, 10, 40, 40);
4767 ret = GetUpdateRect(hparent, &rc1, FALSE);
4768 ok(ret, "GetUpdateRect returned empty region\n");
4769 ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4770 rc1.left, rc1.top, rc1.right, rc1.bottom,
4771 rc2.left, rc2.top, rc2.right, rc2.bottom);
4772
4773 parent_wm_paint = FALSE;
4774 grandparent_wm_paint = FALSE;
4775 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
4776 {
4777 if (msg.message == WM_PAINT)
4778 {
4779 if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
4780 if (msg.hwnd == hparent) parent_wm_paint = TRUE;
4781 }
4782 DispatchMessage(&msg);
4783 }
4784 ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
4785 ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
4786
4787 DestroyWindow(hgrandparent);
4788 }
4789
4790
4791 static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4792 {
4793 if(msg == WM_PAINT)
4794 {
4795 PAINTSTRUCT ps;
4796 RECT updateRect;
4797 DWORD waitResult;
4798 HWND win;
4799 const int waitTime = 2000;
4800
4801 BeginPaint(hwnd, &ps);
4802
4803 /* create and destroy window to create an exposed region on this window */
4804 win = CreateWindowA("static", "win", WS_VISIBLE,
4805 10,10,50,50, NULL, NULL, 0, NULL);
4806 DestroyWindow(win);
4807
4808 waitResult = MsgWaitForMultipleObjects( 0, NULL, FALSE, waitTime, QS_PAINT );
4809
4810 ValidateRect(hwnd, NULL);
4811 EndPaint(hwnd, &ps);
4812
4813 if(waitResult != WAIT_TIMEOUT)
4814 {
4815 GetUpdateRect(hwnd, &updateRect, FALSE);
4816 ok(IsRectEmpty(&updateRect), "Exposed rect should be empty\n");
4817 }
4818
4819 return 1;
4820 }
4821 return DefWindowProc(hwnd, msg, wParam, lParam);
4822 }
4823
4824 static void test_Expose(void)
4825 {
4826 ATOM atom;
4827 WNDCLASSA cls;
4828 HWND mw;
4829 memset(&cls, 0, sizeof(WNDCLASSA));
4830 cls.lpfnWndProc = TestExposedRegion_WndProc;
4831 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
4832 cls.lpszClassName = "TestExposeClass";
4833 atom = RegisterClassA(&cls);
4834
4835 mw = CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
4836 0, 0, 200, 100, NULL, NULL, 0, NULL);
4837
4838 UpdateWindow(mw);
4839 DestroyWindow(mw);
4840 }
4841
4842 static void test_GetWindowModuleFileName(void)
4843 {
4844 HWND hwnd;
4845 HINSTANCE hinst;
4846 UINT ret1, ret2;
4847 char buf1[MAX_PATH], buf2[MAX_PATH];
4848
4849 if (!pGetWindowModuleFileNameA)
4850 {
4851 win_skip("GetWindowModuleFileNameA is not available\n");
4852 return;
4853 }
4854
4855 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
4856 assert(hwnd);
4857
4858 hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
4859 ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
4860
4861 buf1[0] = 0;
4862 SetLastError(0xdeadbeef);
4863 ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
4864 ok(ret1, "GetModuleFileName error %u\n", GetLastError());
4865
4866 buf2[0] = 0;
4867 SetLastError(0xdeadbeef);
4868 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4869 ok(ret2 || broken(!ret2), /* nt4 sp 3 */
4870 "GetWindowModuleFileNameA error %u\n", GetLastError());
4871
4872 if (ret2)
4873 {
4874 ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
4875 ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
4876 }
4877 hinst = GetModuleHandle(0);
4878
4879 SetLastError(0xdeadbeef);
4880 ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
4881 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
4882 "expected %u, got %u\n", ret1 - 2, ret2);
4883 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4884 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4885 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4886
4887 SetLastError(0xdeadbeef);
4888 ret2 = GetModuleFileName(hinst, buf2, 0);
4889 ok(!ret2, "GetModuleFileName should return 0\n");
4890 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4891 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4892 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4893
4894 SetLastError(0xdeadbeef);
4895 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, ret1 - 2);
4896 ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3) /* win98 */ || broken(!ret2), /* nt4 sp3 */
4897 "expected %u, got %u\n", ret1 - 2, ret2);
4898 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4899 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4900 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4901
4902 SetLastError(0xdeadbeef);
4903 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, 0);
4904 ok(!ret2, "expected 0, got %u\n", ret2);
4905 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4906 GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
4907 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4908
4909 DestroyWindow(hwnd);
4910
4911 buf2[0] = 0;
4912 hwnd = (HWND)0xdeadbeef;
4913 SetLastError(0xdeadbeef);
4914 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4915 ok(!ret1, "expected 0, got %u\n", ret1);
4916 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
4917 "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4918
4919 hwnd = FindWindow("Shell_TrayWnd", NULL);
4920 ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
4921 SetLastError(0xdeadbeef);
4922 ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
4923 ok(!ret1 || broken(ret1), /* win98 */ "expected 0, got %u\n", ret1);
4924
4925 if (!ret1) /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
4926 {
4927 ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
4928 hwnd = GetDesktopWindow();
4929 ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
4930 SetLastError(0xdeadbeef);
4931 ret2 = pGetWindowModuleFileNameA(hwnd, buf2, sizeof(buf2));
4932 ok(!ret2 || ret1 == ret2 /* vista */, "expected 0 or %u, got %u %s\n", ret1, ret2, buf2);
4933 }
4934 }
4935
4936 static void test_hwnd_message(void)
4937 {
4938 static const WCHAR mainwindowclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s',0};
4939 static const WCHAR message_windowW[] = {'m','e','s','s','a','g','e',' ','w','i','n','d','o','w',0};
4940
4941 HWND parent = 0, hwnd, found;
4942 RECT rect;
4943
4944 /* HWND_MESSAGE is not supported below w2k, but win9x return != 0
4945 on CreateWindowExA and crash later in the test.
4946 Use UNICODE here to fail on win9x */
4947 hwnd = CreateWindowExW(0, mainwindowclassW, message_windowW, WS_CAPTION | WS_VISIBLE,
4948 100, 100, 200, 200, HWND_MESSAGE, 0, 0, NULL);
4949 if (!hwnd)
4950 {
4951 win_skip("CreateWindowExW with parent HWND_MESSAGE failed\n");
4952 return;
4953 }
4954
4955 ok( !GetParent(hwnd), "GetParent should return 0 for message only windows\n" );
4956 if (pGetAncestor)
4957 {
4958 char buffer[100];
4959 HWND root, desktop = GetDesktopWindow();
4960
4961 parent = pGetAncestor(hwnd, GA_PARENT);
4962 ok(parent != 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4963 ok(parent != desktop, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4964 root = pGetAncestor(hwnd, GA_ROOT);
4965 ok(root == hwnd, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4966 ok( !pGetAncestor(parent, GA_PARENT) || broken(pGetAncestor(parent, GA_PARENT) != 0), /* win2k */
4967 "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
4968 trace("parent %p root %p desktop %p\n", parent, root, desktop);
4969 if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
4970 ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
4971 GetWindowRect( parent, &rect );
4972 ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
4973 "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4974 }
4975 GetWindowRect( hwnd, &rect );
4976 ok( rect.left == 100 && rect.right == 300 && rect.top == 100 && rect.bottom == 300,
4977 "wrong window rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
4978
4979 /* test FindWindow behavior */
4980
4981 found = FindWindowExA( 0, 0, 0, "message window" );
4982 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4983 SetLastError(0xdeadbeef);
4984 found = FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4985 ok( found == 0, "found message window %p/%p\n", found, hwnd );
4986 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4987 if (parent)
4988 {
4989 found = FindWindowExA( parent, 0, 0, "message window" );
4990 ok( found == hwnd, "didn't find message window %p/%p\n", found, hwnd );
4991 }
4992
4993 /* test IsChild behavior */
4994
4995 if (parent) ok( !IsChild( parent, hwnd ), "HWND_MESSAGE is child of top window\n" );
4996
4997 /* test IsWindowVisible behavior */
4998
4999 ok( !IsWindowVisible( hwnd ), "HWND_MESSAGE window is visible\n" );
5000 if (parent) ok( !IsWindowVisible( parent ), "HWND_MESSAGE parent is visible\n" );
5001
5002 DestroyWindow(hwnd);
5003 }
5004
5005 static void test_layered_window(void)
5006 {
5007 HWND hwnd;
5008 COLORREF key = 0;
5009 BYTE alpha = 0;
5010 DWORD flags = 0;
5011 BOOL ret;
5012
5013 if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
5014 {
5015 win_skip( "layered windows not supported\n" );
5016 return;
5017 }
5018 hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
5019 100, 100, 200, 200, 0, 0, 0, NULL);
5020 assert( hwnd );
5021 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5022 ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
5023 ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
5024 ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
5025 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5026 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5027 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5028 ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
5029 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5030 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5031 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5032 ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
5033 ok( alpha == 44, "wrong alpha %u\n", alpha );
5034 ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
5035
5036 /* clearing WS_EX_LAYERED resets attributes */
5037 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5038 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5039 ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
5040 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5041 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5042 ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
5043 ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
5044 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5045 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5046 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5047 ok( key == 0x654321, "wrong color key %x\n", key );
5048 ok( alpha == 22, "wrong alpha %u\n", alpha );
5049 ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
5050
5051 ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
5052 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5053 alpha = 0;
5054 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5055 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5056 ok( key == 0x888888, "wrong color key %x\n", key );
5057 /* alpha not changed on vista if LWA_ALPHA is not set */
5058 ok( alpha == 22 || alpha == 33, "wrong alpha %u\n", alpha );
5059 ok( flags == LWA_COLORKEY, "wrong flags %x\n", flags );
5060
5061 /* color key may or may not be changed without LWA_COLORKEY */
5062 ret = pSetLayeredWindowAttributes( hwnd, 0x999999, 44, 0 );
5063 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5064 alpha = 0;
5065 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5066 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5067 ok( key == 0x888888 || key == 0x999999, "wrong color key %x\n", key );
5068 ok( alpha == 22 || alpha == 44, "wrong alpha %u\n", alpha );
5069 ok( flags == 0, "wrong flags %x\n", flags );
5070
5071 /* default alpha and color key is 0 */
5072 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
5073 SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
5074 ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
5075 ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
5076 ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
5077 ok( ret, "GetLayeredWindowAttributes should succeed on layered window\n" );
5078 ok( key == 0 || key == 0x222222, "wrong color key %x\n", key );
5079 ok( alpha == 0 || alpha == 55, "wrong alpha %u\n", alpha );
5080 ok( flags == 0, "wrong flags %x\n", flags );
5081
5082 DestroyWindow( hwnd );
5083 }
5084
5085 static MONITORINFO mi;
5086
5087 static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
5088 {
5089 switch (msg)
5090 {
5091 case WM_NCCREATE:
5092 {
5093 CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
5094 trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
5095 ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
5096 cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
5097 "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
5098 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5099 cs->x, cs->y, cs->cx, cs->cy);
5100 break;
5101 }
5102 case WM_GETMINMAXINFO:
5103 {
5104 MINMAXINFO *minmax = (MINMAXINFO *)lp;
5105 dump_minmax_info(minmax);
5106 ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
5107 ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
5108 ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
5109 ok(minmax->ptMaxSize.y >= mi.rcMonitor.bottom, "%d >= %d\n", minmax->ptMaxSize.y, mi.rcMonitor.bottom);
5110 break;
5111 }
5112 }
5113 return DefWindowProc(hwnd, msg, wp, lp);
5114 }
5115
5116 static void test_fullscreen(void)
5117 {
5118 static const DWORD t_style[] = {
5119 WS_OVERLAPPED, WS_POPUP, WS_CHILD, WS_THICKFRAME, WS_DLGFRAME
5120 };
5121 static const DWORD t_ex_style[] = {
5122 0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
5123 };
5124 WNDCLASS cls;
5125 HWND hwnd;
5126 int i, j;
5127 POINT pt;
5128 RECT rc;
5129 HMONITOR hmon;
5130 LRESULT ret;
5131
5132 if (!pGetMonitorInfoA || !pMonitorFromPoint)
5133 {
5134 win_skip("GetMonitorInfoA or MonitorFromPoint are not available on this platform\n");
5135 return;
5136 }
5137
5138 pt.x = pt.y = 0;
5139 SetLastError(0xdeadbeef);
5140 hmon = pMonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
5141 ok(hmon != 0, "MonitorFromPoint error %u\n", GetLastError());
5142
5143 mi.cbSize = sizeof(mi);
5144 SetLastError(0xdeadbeef);
5145 ret = pGetMonitorInfoA(hmon, &mi);
5146 ok(ret, "GetMonitorInfo error %u\n", GetLastError());
5147 trace("monitor (%d,%d-%d,%d), work (%d,%d-%d,%d)\n",
5148 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5149 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5150
5151 cls.style = 0;
5152 cls.lpfnWndProc = fullscreen_wnd_proc;
5153 cls.cbClsExtra = 0;
5154 cls.cbWndExtra = 0;
5155 cls.hInstance = GetModuleHandle(0);
5156 cls.hIcon = 0;
5157 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5158 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5159 cls.lpszMenuName = NULL;
5160 cls.lpszClassName = "fullscreen_class";
5161 RegisterClass(&cls);
5162
5163 for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
5164 {
5165 DWORD style, ex_style;
5166
5167 /* avoid a WM interaction */
5168 assert(!(t_style[i] & WS_VISIBLE));
5169
5170 for (j = 0; j < sizeof(t_ex_style)/sizeof(t_ex_style[0]); j++)
5171 {
5172 int fixup;
5173
5174 style = t_style[i];
5175 ex_style = t_ex_style[j];
5176
5177 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5178 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5179 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5180 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5181 GetWindowRect(hwnd, &rc);
5182 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5183 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5184 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5185 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5186 DestroyWindow(hwnd);
5187
5188 style = t_style[i] | WS_MAXIMIZE;
5189 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5190 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5191 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5192 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5193 GetWindowRect(hwnd, &rc);
5194 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5195 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5196 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5197 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5198 DestroyWindow(hwnd);
5199
5200 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
5201 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5202 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5203 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5204 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5205 GetWindowRect(hwnd, &rc);
5206 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5207 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5208 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5209 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5210 DestroyWindow(hwnd);
5211
5212 style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
5213 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5214 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5215 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5216 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5217 GetWindowRect(hwnd, &rc);
5218 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5219 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5220 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5221 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5222 DestroyWindow(hwnd);
5223
5224 style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
5225 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5226 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5227 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5228 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5229 GetWindowRect(hwnd, &rc);
5230 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5231 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5232 fixup = min(abs(rc.left), abs(rc.top));
5233 InflateRect(&rc, -fixup, -fixup);
5234 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5235 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5236 "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
5237 ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
5238 mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
5239 DestroyWindow(hwnd);
5240
5241 style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
5242 hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
5243 mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
5244 GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
5245 ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
5246 GetWindowRect(hwnd, &rc);
5247 trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5248 /* Windows makes a maximized window slightly larger (to hide the borders?) */
5249 fixup = min(abs(rc.left), abs(rc.top));
5250 InflateRect(&rc, -fixup, -fixup);
5251 if (style & (WS_CHILD | WS_POPUP))
5252 ok(rc.left <= mi.rcMonitor.left && rc.top <= mi.rcMonitor.top &&
5253 rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
5254 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5255 else
5256 ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
5257 rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
5258 "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
5259 DestroyWindow(hwnd);
5260 }
5261 }
5262
5263 UnregisterClass("fullscreen_class", GetModuleHandle(0));
5264 }
5265
5266 static BOOL test_thick_child_got_minmax;
5267 static const char * test_thick_child_name;
5268 static LONG test_thick_child_style;
5269 static LONG test_thick_child_exStyle;
5270
5271 static LRESULT WINAPI test_thick_child_size_winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
5272 {
5273 MINMAXINFO* minmax;
5274 int expectedMinTrackX;
5275 int expectedMinTrackY;
5276 int actualMinTrackX;
5277 int actualMinTrackY;
5278 int expectedMaxTrackX;
5279 int expectedMaxTrackY;
5280 int actualMaxTrackX;
5281 int actualMaxTrackY;
5282 int expectedMaxSizeX;
5283 int expectedMaxSizeY;
5284 int actualMaxSizeX;
5285 int actualMaxSizeY;
5286 int expectedPosX;
5287 int expectedPosY;
5288 int actualPosX;
5289 int actualPosY;
5290 LONG adjustedStyle;
5291 RECT rect;
5292 switch (msg)
5293 {
5294 case WM_GETMINMAXINFO:
5295 {
5296 minmax = (MINMAXINFO *)lparam;
5297 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
5298 dump_minmax_info( minmax );
5299
5300 test_thick_child_got_minmax = TRUE;
5301
5302
5303 adjustedStyle = test_thick_child_style;
5304 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5305 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5306 GetClientRect(GetParent(hwnd), &rect);
5307 AdjustWindowRectEx(&rect, adjustedStyle, FALSE, test_thick_child_exStyle);
5308
5309 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5310 {
5311 expectedMinTrackX = GetSystemMetrics(SM_CXMINTRACK);
5312 expectedMinTrackY = GetSystemMetrics(SM_CYMINTRACK);
5313 }
5314 else
5315 {
5316 expectedMinTrackX = -2 * rect.left;
5317 expectedMinTrackY = -2 * rect.top;
5318 }
5319 actualMinTrackX = minmax->ptMinTrackSize.x;
5320 actualMinTrackY = minmax->ptMinTrackSize.y;
5321
5322 ok(actualMinTrackX == expectedMinTrackX && actualMinTrackY == expectedMinTrackY,
5323 "expected minTrack %dx%d, actual minTrack %dx%d for %s\n",
5324 expectedMinTrackX, expectedMinTrackY, actualMinTrackX, actualMinTrackY,
5325 test_thick_child_name);
5326
5327 actualMaxTrackX = minmax->ptMaxTrackSize.x;
5328 actualMaxTrackY = minmax->ptMaxTrackSize.y;
5329 expectedMaxTrackX = GetSystemMetrics(SM_CXMAXTRACK);
5330 expectedMaxTrackY = GetSystemMetrics(SM_CYMAXTRACK);
5331 ok(actualMaxTrackX == expectedMaxTrackX && actualMaxTrackY == expectedMaxTrackY,
5332 "expected maxTrack %dx%d, actual maxTrack %dx%d for %s\n",
5333 expectedMaxTrackX, expectedMaxTrackY, actualMaxTrackX, actualMaxTrackY,
5334 test_thick_child_name);
5335
5336 expectedMaxSizeX = rect.right - rect.left;
5337 expectedMaxSizeY = rect.bottom - rect.top;
5338 actualMaxSizeX = minmax->ptMaxSize.x;
5339 actualMaxSizeY = minmax->ptMaxSize.y;
5340
5341 ok(actualMaxSizeX == expectedMaxSizeX && actualMaxSizeY == expectedMaxSizeY,
5342 "expected maxSize %dx%d, actual maxSize %dx%d for %s\n",
5343 expectedMaxSizeX, expectedMaxSizeY, actualMaxSizeX, actualMaxSizeY,
5344 test_thick_child_name);
5345
5346
5347 expectedPosX = rect.left;
5348 expectedPosY = rect.top;
5349 actualPosX = minmax->ptMaxPosition.x;
5350 actualPosY = minmax->ptMaxPosition.y;
5351 ok(actualPosX == expectedPosX && actualPosY == expectedPosY,
5352 "expected maxPosition (%d/%d), actual maxPosition (%d/%d) for %s\n",
5353 expectedPosX, expectedPosY, actualPosX, actualPosY, test_thick_child_name);
5354
5355 break;
5356 }
5357 }
5358
5359 return DefWindowProcA(hwnd, msg, wparam, lparam);
5360 }
5361
5362 #define NUMBER_OF_THICK_CHILD_TESTS 16
5363 static void test_thick_child_size(HWND parentWindow)
5364 {
5365 BOOL success;
5366 RECT childRect;
5367 RECT adjustedParentRect;
5368 HWND childWindow;
5369 LONG childWidth;
5370 LONG childHeight;
5371 LONG expectedWidth;
5372 LONG expectedHeight;
5373 WNDCLASSA cls;
5374 LPCTSTR className = "THICK_CHILD_CLASS";
5375 int i;
5376 LONG adjustedStyle;
5377 static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
5378 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5379 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5380 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5381 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5382 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5383 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5384 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5385 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5386 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5387 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5388 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5389 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5390 WS_CHILD | WS_VISIBLE | WS_THICKFRAME,
5391 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME,
5392 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER,
5393 WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER,
5394 };
5395
5396 static const LONG exStyles[NUMBER_OF_THICK_CHILD_TESTS] = {
5397 0,
5398 0,
5399 0,
5400 0,
5401 WS_EX_DLGMODALFRAME,
5402 WS_EX_DLGMODALFRAME,
5403 WS_EX_DLGMODALFRAME,
5404 WS_EX_DLGMODALFRAME,
5405 WS_EX_STATICEDGE,
5406 WS_EX_STATICEDGE,
5407 WS_EX_STATICEDGE,
5408 WS_EX_STATICEDGE,
5409 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5410 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5411 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5412 WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME,
5413 };
5414 static const char *styleName[NUMBER_OF_THICK_CHILD_TESTS] = {
5415 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME",
5416 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME",
5417 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER",
5418 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER",
5419 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_DLGMODALFRAME",
5420 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_DLGMODALFRAME",
5421 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5422 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_DLGMODALFRAME",
5423 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME exstyle= WS_EX_STATICEDGE",
5424 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE",
5425 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5426 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE",
5427 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME, exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5428 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5429 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_DLGFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5430 "style=WS_CHILD | WS_VISIBLE | WS_THICKFRAME | WS_BORDER exstyle= WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME",
5431 };
5432
5433 cls.style = 0;
5434 cls.lpfnWndProc = test_thick_child_size_winproc;
5435 cls.cbClsExtra = 0;
5436 cls.cbWndExtra = 0;
5437 cls.hInstance = GetModuleHandleA(0);
5438 cls.hIcon = 0;
5439 cls.hCursor = LoadCursorA(0, IDC_ARROW);
5440 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
5441 cls.lpszMenuName = NULL;
5442 cls.lpszClassName = className;
5443 SetLastError(0xdeadbeef);
5444 ok(RegisterClassA(&cls),"RegisterClassA failed, error: %u\n", GetLastError());
5445
5446 for(i = 0; i < NUMBER_OF_THICK_CHILD_TESTS; i++)
5447 {
5448 test_thick_child_name = styleName[i];
5449 test_thick_child_style = styles[i];
5450 test_thick_child_exStyle = exStyles[i];
5451 test_thick_child_got_minmax = FALSE;
5452
5453 SetLastError(0xdeadbeef);
5454 childWindow = CreateWindowEx( exStyles[i], className, "", styles[i], 0, 0, 0, 0, parentWindow, 0, GetModuleHandleA(0), NULL );
5455 ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
5456
5457 ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
5458
5459 SetLastError(0xdeadbeef);
5460 success = GetWindowRect(childWindow, &childRect);
5461 ok(success,"GetWindowRect call failed, error: %u\n", GetLastError());
5462 childWidth = childRect.right - childRect.left;
5463 childHeight = childRect.bottom - childRect.top;
5464
5465 adjustedStyle = styles[i];
5466 if ((adjustedStyle & WS_CAPTION) == WS_CAPTION)
5467 adjustedStyle &= ~WS_BORDER; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
5468 GetClientRect(GetParent(childWindow), &adjustedParentRect);
5469 AdjustWindowRectEx(&adjustedParentRect, adjustedStyle, FALSE, test_thick_child_exStyle);
5470
5471
5472 if (test_thick_child_style & (WS_DLGFRAME | WS_BORDER))
5473 {
5474 expectedWidth = GetSystemMetrics(SM_CXMINTRACK);
5475 expectedHeight = GetSystemMetrics(SM_CYMINTRACK);
5476 }
5477 else
5478 {
5479 expectedWidth = -2 * adjustedParentRect.left;
5480 expectedHeight = -2 * adjustedParentRect.top;
5481 }
5482
5483 ok((childWidth == expectedWidth) && (childHeight == expectedHeight),
5484 "size of window (%s) is wrong: expected size %dx%d != actual size %dx%d\n",
5485 test_thick_child_name, expectedWidth, expectedHeight, childWidth, childHeight);
5486
5487 SetLastError(0xdeadbeef);
5488 success = DestroyWindow(childWindow);
5489 ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
5490 }
5491 ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
5492 }
5493
5494 static void test_handles( HWND full_hwnd )
5495 {
5496 HWND hwnd = full_hwnd;
5497 BOOL ret;
5498 RECT rect;
5499
5500 SetLastError( 0xdeadbeef );
5501 ret = GetWindowRect( hwnd, &rect );
5502 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5503
5504 #ifdef _WIN64
5505 if ((ULONG_PTR)full_hwnd >> 32)
5506 hwnd = (HWND)((ULONG_PTR)full_hwnd & ~0u);
5507 else
5508 hwnd = (HWND)((ULONG_PTR)full_hwnd | ((ULONG_PTR)~0u << 32));
5509 SetLastError( 0xdeadbeef );
5510 ret = GetWindowRect( hwnd, &rect );
5511 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5512
5513 hwnd = (HWND)(((ULONG_PTR)full_hwnd & ~0u) | ((ULONG_PTR)0x1234 << 32));
5514 SetLastError( 0xdeadbeef );
5515 ret = GetWindowRect( hwnd, &rect );
5516 ok( ret, "GetWindowRect failed for %p err %u\n", hwnd, GetLastError() );
5517
5518 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x9876 << 16));
5519 SetLastError( 0xdeadbeef );
5520 ret = GetWindowRect( hwnd, &rect );
5521 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5522 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5523
5524 hwnd = (HWND)(((ULONG_PTR)full_hwnd & 0xffff) | ((ULONG_PTR)0x12345678 << 16));
5525 SetLastError( 0xdeadbeef );
5526 ret = GetWindowRect( hwnd, &rect );
5527 ok( !ret, "GetWindowRect succeeded for %p\n", hwnd );
5528 ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() );
5529 #endif
5530 }
5531
5532 START_TEST(win)
5533 {
5534 HMODULE user32 = GetModuleHandleA( "user32.dll" );
5535 pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
5536 pGetWindowInfo = (void *)GetProcAddress( user32, "GetWindowInfo" );
5537 pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
5538 pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
5539 pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
5540 pGetMonitorInfoA = (void *)GetProcAddress( user32, "GetMonitorInfoA" );
5541 pMonitorFromPoint = (void *)GetProcAddress( user32, "MonitorFromPoint" );
5542
5543 if (!RegisterWindowClasses()) assert(0);
5544
5545 hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
5546 if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
5547
5548 hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
5549 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5550 WS_MAXIMIZEBOX | WS_POPUP,
5551 100, 100, 200, 200,
5552 0, 0, GetModuleHandle(0), NULL);
5553 hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
5554 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
5555 WS_MAXIMIZEBOX | WS_POPUP,
5556 100, 100, 200, 200,
5557 0, 0, GetModuleHandle(0), NULL);
5558 assert( hwndMain );
5559 assert( hwndMain2 );
5560
5561 our_pid = GetWindowThreadProcessId(hwndMain, NULL);
5562
5563 /* Add the tests below this line */
5564 test_thick_child_size(hwndMain);
5565 test_fullscreen();
5566 test_hwnd_message();
5567 test_nonclient_area(hwndMain);
5568 test_params();
5569 test_GetWindowModuleFileName();
5570 test_capture_1();
5571 test_capture_2();
5572 test_capture_3(hwndMain, hwndMain2);
5573
5574 test_CreateWindow();
5575 test_parent_owner();
5576 test_SetParent();
5577
5578 test_mdi();
5579 test_icons();
5580 test_SetWindowPos(hwndMain);
5581 test_SetMenu(hwndMain);
5582 test_SetFocus(hwndMain);
5583 test_SetActiveWindow(hwndMain);
5584
5585 test_children_zorder(hwndMain);
5586 test_popup_zorder(hwndMain2, hwndMain);
5587 test_keyboard_input(hwndMain);
5588 test_mouse_input(hwndMain);
5589 test_validatergn(hwndMain);
5590 test_nccalcscroll( hwndMain);
5591 test_scrollvalidate( hwndMain);
5592 test_scrolldc( hwndMain);
5593 test_scroll();
5594 test_IsWindowUnicode();
5595 test_vis_rgn(hwndMain);
5596
5597 test_AdjustWindowRect();
5598 test_window_styles();
5599 test_redrawnow();
5600 test_csparentdc();
5601 test_SetWindowLong();
5602 test_ShowWindow();
5603 if (0) test_gettext(); /* crashes on NT4 */
5604 test_GetUpdateRect();
5605 test_Expose();
5606 test_layered_window();
5607
5608 test_SetForegroundWindow(hwndMain);
5609 test_shell_window();
5610 test_handles( hwndMain );
5611
5612 /* add the tests above this line */
5613 if (hhook) UnhookWindowsHookEx(hhook);
5614
5615 DestroyWindow(hwndMain2);
5616 DestroyWindow(hwndMain);
5617 }