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