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