2 * Unit tests for window handling
4 * Copyright 2002 Bill Medland
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2003 Dmitry Timoshkov
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
39 #include "wine/test.h"
41 #ifndef SPI_GETDESKWALLPAPER
42 #define SPI_GETDESKWALLPAPER 0x0073
45 #define LONG_PTR INT_PTR
46 #define ULONG_PTR UINT_PTR
48 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
49 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
51 static HWND hwndMessage
;
52 static HWND hwndMain
, hwndMain2
;
55 /* check the values returned by the various parent/owner functions on a given window */
56 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
57 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
63 res
= pGetAncestor( hwnd
, GA_PARENT
);
64 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
66 res
= (HWND
)GetWindowLongA( hwnd
, GWL_HWNDPARENT
);
67 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
68 res
= GetParent( hwnd
);
69 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
70 res
= GetWindow( hwnd
, GW_OWNER
);
71 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
74 res
= pGetAncestor( hwnd
, GA_ROOT
);
75 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
76 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
77 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
82 static HWND
create_tool_window( LONG style
, HWND parent
)
84 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
85 0, 0, 100, 100, parent
, 0, 0, NULL
);
86 ok( ret
!= 0, "Creation failed\n" );
90 /* test parent and owner values for various combinations */
91 static void test_parent_owner(void)
94 HWND test
, owner
, ret
;
95 HWND desktop
= GetDesktopWindow();
96 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
98 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
100 /* child without parent, should fail */
101 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
102 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
103 ok( !test
, "WS_CHILD without parent created\n" );
106 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
107 style
= GetWindowLongA( desktop
, GWL_STYLE
);
108 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
109 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
110 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
112 /* normal child window */
113 test
= create_tool_window( WS_CHILD
, hwndMain
);
114 trace( "created child %p\n", test
);
115 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
116 SetWindowLongA( test
, GWL_STYLE
, 0 );
117 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
118 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
119 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
120 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
121 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
122 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
123 DestroyWindow( test
);
125 /* normal child window with WS_MAXIMIZE */
126 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
127 DestroyWindow( test
);
129 /* normal child window with WS_THICKFRAME */
130 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
131 DestroyWindow( test
);
133 /* popup window with WS_THICKFRAME */
134 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
135 DestroyWindow( test
);
137 /* child of desktop */
138 test
= create_tool_window( WS_CHILD
, desktop
);
139 trace( "created child of desktop %p\n", test
);
140 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
141 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
142 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
143 SetWindowLongA( test
, GWL_STYLE
, 0 );
144 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
145 DestroyWindow( test
);
147 /* child of desktop with WS_MAXIMIZE */
148 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
149 DestroyWindow( test
);
151 /* child of desktop with WS_MINIMIZE */
152 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
153 DestroyWindow( test
);
156 test
= create_tool_window( WS_CHILD
, child
);
157 trace( "created child of child %p\n", test
);
158 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
159 SetWindowLongA( test
, GWL_STYLE
, 0 );
160 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
161 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
162 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
163 DestroyWindow( test
);
165 /* child of child with WS_MAXIMIZE */
166 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
167 DestroyWindow( test
);
169 /* child of child with WS_MINIMIZE */
170 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
171 DestroyWindow( test
);
173 /* not owned top-level window */
174 test
= create_tool_window( 0, 0 );
175 trace( "created top-level %p\n", test
);
176 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
177 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
178 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
179 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
180 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
181 DestroyWindow( test
);
183 /* not owned top-level window with WS_MAXIMIZE */
184 test
= create_tool_window( WS_MAXIMIZE
, 0 );
185 DestroyWindow( test
);
187 /* owned top-level window */
188 test
= create_tool_window( 0, hwndMain
);
189 trace( "created owned top-level %p\n", test
);
190 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
191 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
192 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
193 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
194 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
195 DestroyWindow( test
);
197 /* owned top-level window with WS_MAXIMIZE */
198 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
199 DestroyWindow( test
);
201 /* not owned popup */
202 test
= create_tool_window( WS_POPUP
, 0 );
203 trace( "created popup %p\n", test
);
204 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
205 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
206 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
207 SetWindowLongA( test
, GWL_STYLE
, 0 );
208 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
209 DestroyWindow( test
);
211 /* not owned popup with WS_MAXIMIZE */
212 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
213 DestroyWindow( test
);
216 test
= create_tool_window( WS_POPUP
, hwndMain
);
217 trace( "created owned popup %p\n", test
);
218 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
219 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
220 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
221 SetWindowLongA( test
, GWL_STYLE
, 0 );
222 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
223 DestroyWindow( test
);
225 /* owned popup with WS_MAXIMIZE */
226 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
227 DestroyWindow( test
);
229 /* top-level window owned by child (same as owned by top-level) */
230 test
= create_tool_window( 0, child
);
231 trace( "created top-level owned by child %p\n", test
);
232 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
233 DestroyWindow( test
);
235 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
236 test
= create_tool_window( WS_MAXIMIZE
, child
);
237 DestroyWindow( test
);
239 /* popup owned by desktop (same as not owned) */
240 test
= create_tool_window( WS_POPUP
, desktop
);
241 trace( "created popup owned by desktop %p\n", test
);
242 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
243 DestroyWindow( test
);
245 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
246 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
247 DestroyWindow( test
);
249 /* popup owned by child (same as owned by top-level) */
250 test
= create_tool_window( WS_POPUP
, child
);
251 trace( "created popup owned by child %p\n", test
);
252 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
253 DestroyWindow( test
);
255 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
256 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
257 DestroyWindow( test
);
259 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
260 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
261 trace( "created WS_CHILD popup %p\n", test
);
262 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
263 DestroyWindow( test
);
265 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
266 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
267 DestroyWindow( test
);
269 /* owned popup with WS_CHILD (same as WS_POPUP only) */
270 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
271 trace( "created owned WS_CHILD popup %p\n", test
);
272 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
273 DestroyWindow( test
);
275 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
276 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
277 DestroyWindow( test
);
279 /******************** parent changes *************************/
280 trace( "testing parent changes\n" );
283 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
284 #if 0 /* this test succeeds on NT but crashes on win9x systems */
285 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
286 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
287 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
288 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
289 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
291 /* normal child window */
292 test
= create_tool_window( WS_CHILD
, hwndMain
);
293 trace( "created child %p\n", test
);
295 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
296 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
297 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
299 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
300 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
301 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
303 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)desktop
);
304 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
305 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
307 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
308 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
309 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
310 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
312 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
313 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
314 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
315 DestroyWindow( test
);
317 /* not owned top-level window */
318 test
= create_tool_window( 0, 0 );
319 trace( "created top-level %p\n", test
);
321 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
322 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
323 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
325 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
326 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
327 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
329 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
330 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
331 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
332 DestroyWindow( test
);
334 /* not owned popup */
335 test
= create_tool_window( WS_POPUP
, 0 );
336 trace( "created popup %p\n", test
);
338 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
339 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
340 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
342 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
343 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
344 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
346 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
347 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
348 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
349 DestroyWindow( test
);
351 /* normal child window */
352 test
= create_tool_window( WS_CHILD
, hwndMain
);
353 trace( "created child %p\n", test
);
355 ret
= SetParent( test
, desktop
);
356 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
357 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
359 ret
= SetParent( test
, child
);
360 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
361 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
363 ret
= SetParent( test
, hwndMain2
);
364 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
365 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
366 DestroyWindow( test
);
368 /* not owned top-level window */
369 test
= create_tool_window( 0, 0 );
370 trace( "created top-level %p\n", test
);
372 ret
= SetParent( test
, child
);
373 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
374 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
375 DestroyWindow( test
);
378 test
= create_tool_window( WS_POPUP
, hwndMain2
);
379 trace( "created owned popup %p\n", test
);
381 ret
= SetParent( test
, child
);
382 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
383 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
385 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
386 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
387 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
388 DestroyWindow( test
);
390 /**************** test owner destruction *******************/
392 /* owned child popup */
393 owner
= create_tool_window( 0, 0 );
394 test
= create_tool_window( WS_POPUP
, owner
);
395 trace( "created owner %p and popup %p\n", owner
, test
);
396 ret
= SetParent( test
, child
);
397 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
398 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
399 /* window is now child of 'child' but owned by 'owner' */
400 DestroyWindow( owner
);
401 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
402 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
403 * while Win95, Win2k, WinXP do.
405 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
406 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
409 /* owned top-level popup */
410 owner
= create_tool_window( 0, 0 );
411 test
= create_tool_window( WS_POPUP
, owner
);
412 trace( "created owner %p and popup %p\n", owner
, test
);
413 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
414 DestroyWindow( owner
);
415 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
417 /* top-level popup owned by child */
418 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
419 test
= create_tool_window( WS_POPUP
, 0 );
420 trace( "created owner %p and popup %p\n", owner
, test
);
421 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (ULONG_PTR
)owner
);
422 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
423 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
424 DestroyWindow( owner
);
425 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
426 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
427 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
428 * while Win95, Win2k, WinXP do.
430 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
434 DestroyWindow(child
);
438 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
442 case WM_GETMINMAXINFO
:
444 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
446 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd
, wparam
, lparam
);
447 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
448 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
449 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
450 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
451 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
452 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
453 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
454 SetWindowLongA(hwnd
, GWL_USERDATA
, 0x20031021);
457 case WM_WINDOWPOSCHANGING
:
459 BOOL is_win9x
= GetWindowLongW(hwnd
, GWL_WNDPROC
) == 0;
460 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
461 trace("main: WM_WINDOWPOSCHANGING\n");
462 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
463 winpos
->hwnd
, winpos
->hwndInsertAfter
,
464 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
465 if (!(winpos
->flags
& SWP_NOMOVE
))
467 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
468 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
470 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
471 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
473 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
474 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
478 case WM_WINDOWPOSCHANGED
:
481 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
482 trace("main: WM_WINDOWPOSCHANGED\n");
483 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
484 winpos
->hwnd
, winpos
->hwndInsertAfter
,
485 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
486 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
487 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
489 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
490 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
492 GetWindowRect(hwnd
, &rc1
);
493 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
494 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
495 /* note: winpos coordinates are relative to parent */
496 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
497 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
498 #if 0 /* Uncomment this once the test succeeds in all cases */
499 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
502 GetClientRect(hwnd
, &rc2
);
503 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
504 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
505 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
510 BOOL got_getminmaxinfo
= GetWindowLongA(hwnd
, GWL_USERDATA
) == 0x20031021;
511 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
513 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd
, cs
->hwndParent
, cs
->style
);
514 if (got_getminmaxinfo
)
515 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
517 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
518 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
520 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
525 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
528 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
532 case WM_GETMINMAXINFO
:
534 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
536 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd
, wparam
, lparam
);
537 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
538 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
539 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
540 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
541 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
542 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
543 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
544 SetWindowLongA(hwnd
, GWL_USERDATA
, 0x20031021);
549 BOOL got_getminmaxinfo
= GetWindowLongA(hwnd
, GWL_USERDATA
) == 0x20031021;
550 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
552 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd
, cs
->hwndParent
, cs
->style
);
553 if (got_getminmaxinfo
)
554 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
556 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
557 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
559 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
564 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
567 static BOOL
RegisterWindowClasses(void)
572 cls
.lpfnWndProc
= main_window_procA
;
575 cls
.hInstance
= GetModuleHandleA(0);
577 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
578 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
579 cls
.lpszMenuName
= NULL
;
580 cls
.lpszClassName
= "MainWindowClass";
582 if(!RegisterClassA(&cls
)) return FALSE
;
585 cls
.lpfnWndProc
= tool_window_procA
;
588 cls
.hInstance
= GetModuleHandleA(0);
590 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
591 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
592 cls
.lpszMenuName
= NULL
;
593 cls
.lpszClassName
= "ToolWindowClass";
595 if(!RegisterClassA(&cls
)) return FALSE
;
600 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
, BOOL test_borders
)
602 RECT rcWindow
, rcClient
;
606 ok(IsWindow(hwnd
), "bad window handle\n");
608 GetWindowRect(hwnd
, &rcWindow
);
609 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
611 GetClientRect(hwnd
, &rcClient
);
612 /* translate to screen coordinates */
613 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
614 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
616 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
), "wrong dwStyle\n");
617 ok(info
->dwExStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
), "wrong dwExStyle\n");
618 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
619 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus\n");
621 if (test_borders
&& !IsRectEmpty(&rcWindow
))
623 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
624 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
626 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
627 "wrong cxWindowBorders %d != %ld\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
628 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
629 ok(info
->cyWindowBorders
== border
,
630 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
633 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
634 ok(info
->wCreatorVersion
== 0x0400, "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
637 static void test_nonclient_area(HWND hwnd
)
639 DWORD style
, exstyle
;
640 RECT rc_window
, rc_client
, rc
;
643 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
644 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
645 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
647 GetWindowRect(hwnd
, &rc_window
);
648 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
649 GetClientRect(hwnd
, &rc_client
);
650 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
652 /* avoid some cases when things go wrong */
653 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
654 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
656 CopyRect(&rc
, &rc_client
);
657 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
658 AdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
659 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
660 #if 0 /* Uncomment this once the test succeeds in all cases */
661 ok(EqualRect(&rc
, &rc_window
), "window rect does not match\n");
664 CopyRect(&rc
, &rc_window
);
665 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
666 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
667 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
668 #if 0 /* Uncomment this once the test succeeds in all cases */
669 ok(EqualRect(&rc
, &rc_client
), "client rect does not match\n");
672 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
673 SetRect(&rc_client
, 0, 0, 250, 150);
674 CopyRect(&rc_window
, &rc_client
);
675 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
676 AdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
677 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
678 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
680 CopyRect(&rc
, &rc_window
);
681 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
682 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
683 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
684 #if 0 /* Uncomment this once the test succeeds in all cases */
685 ok(EqualRect(&rc
, &rc_client
), "client rect does not match\n");
689 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
691 static const char *CBT_code_name
[10] = {
702 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
704 trace("CBT: %d (%s), %08x, %08lx\n", nCode
, code_name
, wParam
, lParam
);
706 /* on HCBT_DESTROYWND window state is undefined */
707 if (nCode
!= HCBT_DESTROYWND
&& wParam
)
709 BOOL is_win9x
= GetWindowLongW((HWND
)wParam
, GWL_WNDPROC
) == 0;
710 if (is_win9x
&& nCode
== HCBT_CREATEWND
)
711 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
713 test_nonclient_area((HWND
)wParam
);
719 /* Win98 actually does check the info.cbSize and doesn't allow
720 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
721 * WinXP do not check it at all.
723 info
.cbSize
= sizeof(WINDOWINFO
);
724 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
725 /* win2k SP4 returns broken border info if GetWindowInfo
726 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
728 verify_window_info((HWND
)wParam
, &info
, nCode
!= HCBT_MINMAX
);
736 #if 0 /* Uncomment this once the test succeeds in all cases */
737 static const RECT rc_null
;
741 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
742 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
743 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
744 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
746 /* WS_VISIBLE should be turned off yet */
747 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
748 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
749 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
750 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
752 #if 0 /* Uncomment this once the test succeeds in all cases */
753 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
755 ok(GetParent((HWND
)wParam
) == hwndMessage
,
756 "wrong result from GetParent %p: message window %p\n",
757 GetParent((HWND
)wParam
), hwndMessage
);
760 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
762 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
764 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
765 * Win9x still has them set to 0.
767 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
768 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
770 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
771 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
773 #if 0 /* Uncomment this once the test succeeds in all cases */
776 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
777 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
778 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
780 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
781 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
782 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
784 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
785 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
788 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
789 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
790 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
791 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
797 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
800 static void test_shell_window(void)
804 HMODULE hinst
, hUser32
;
805 BOOL (WINAPI
*SetShellWindow
)(HWND
);
806 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
807 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
808 HWND shellWindow
, nextWnd
;
810 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
812 trace("Skipping shell window test on Win9x\n");
816 shellWindow
= GetShellWindow();
817 hinst
= GetModuleHandle(0);
818 hUser32
= GetModuleHandleA("user32");
820 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
821 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
823 trace("previous shell window: %p\n", shellWindow
);
829 ret
= DestroyWindow(shellWindow
);
830 error
= GetLastError();
832 ok(!ret
, "DestroyWindow(shellWindow)\n");
833 /* passes on Win XP, but not on Win98 */
834 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
836 /* close old shell instance */
837 GetWindowThreadProcessId(shellWindow
, &pid
);
838 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
839 ret
= TerminateProcess(hProcess
, 0);
840 ok(ret
, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
841 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
842 CloseHandle(hProcess
);
845 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
846 trace("created window 1: %p\n", hwnd1
);
848 ret
= SetShellWindow(hwnd1
);
849 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
850 shellWindow
= GetShellWindow();
851 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
853 ret
= SetShellWindow(hwnd1
);
854 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
856 ret
= SetShellWindow(0);
857 error
= GetLastError();
858 /* passes on Win XP, but not on Win98
859 ok(!ret, "reset shell window by SetShellWindow(0)\n");
860 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
862 ret
= SetShellWindow(hwnd1
);
863 /* passes on Win XP, but not on Win98
864 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
868 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
869 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
870 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
873 ret
= DestroyWindow(hwnd1
);
874 ok(ret
, "DestroyWindow(hwnd1)\n");
876 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
877 trace("created window 2: %p\n", hwnd2
);
878 ret
= SetShellWindow(hwnd2
);
879 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
881 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
882 trace("created window 3: %p\n", hwnd3
);
884 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
885 trace("created window 4: %p\n", hwnd4
);
887 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
888 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
890 ret
= SetShellWindow(hwnd4
);
891 ok(ret
, "SetShellWindow(hwnd4)\n");
892 shellWindow
= GetShellWindow();
893 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
895 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
896 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
898 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
899 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
901 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
902 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
904 ret
= SetShellWindow(hwnd3
);
905 ok(!ret
, "SetShellWindow(hwnd3)\n");
906 shellWindow
= GetShellWindow();
907 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
909 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
910 trace("created window 5: %p\n", hwnd5
);
911 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
912 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
916 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
917 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
920 /* destroy test windows */
921 DestroyWindow(hwnd2
);
922 DestroyWindow(hwnd3
);
923 DestroyWindow(hwnd4
);
924 DestroyWindow(hwnd5
);
927 /************** MDI test ****************/
929 static const char mdi_lParam_test_message
[] = "just a test string";
931 static void test_MDI_create(HWND parent
, HWND mdi_client
)
933 MDICREATESTRUCTA mdi_cs
;
935 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
936 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
937 BOOL isWin9x
= FALSE
;
939 mdi_cs
.szClass
= "MDI_child_Class_1";
940 mdi_cs
.szTitle
= "MDI child";
941 mdi_cs
.hOwner
= GetModuleHandle(0);
942 mdi_cs
.x
= CW_USEDEFAULT
;
943 mdi_cs
.y
= CW_USEDEFAULT
;
944 mdi_cs
.cx
= CW_USEDEFAULT
;
945 mdi_cs
.cy
= CW_USEDEFAULT
;
947 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
948 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
949 ok(mdi_child
!= 0, "MDI child creation failed\n");
950 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
951 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
953 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
954 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
955 ok(mdi_child
!= 0, "MDI child creation failed\n");
956 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
957 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
959 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
960 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
961 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
963 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
967 ok(mdi_child
!= 0, "MDI child creation failed\n");
968 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
969 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
972 /* test MDICREATESTRUCT A<->W mapping */
973 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
975 mdi_cs
.szClass
= (LPCSTR
)classW
;
976 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
977 SetLastError(0xdeadbeef);
978 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
981 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
984 ok(mdi_child
!= 0, "MDI child creation failed\n");
988 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
989 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
992 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
994 CW_USEDEFAULT
, CW_USEDEFAULT
,
995 CW_USEDEFAULT
, CW_USEDEFAULT
,
996 mdi_client
, GetModuleHandle(0),
997 (LPARAM
)mdi_lParam_test_message
);
998 ok(mdi_child
!= 0, "MDI child creation failed\n");
999 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1000 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1002 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1003 0x7fffffff, /* without WS_POPUP */
1004 CW_USEDEFAULT
, CW_USEDEFAULT
,
1005 CW_USEDEFAULT
, CW_USEDEFAULT
,
1006 mdi_client
, GetModuleHandle(0),
1007 (LPARAM
)mdi_lParam_test_message
);
1008 ok(mdi_child
!= 0, "MDI child creation failed\n");
1009 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1010 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1012 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1013 0xffffffff, /* with WS_POPUP */
1014 CW_USEDEFAULT
, CW_USEDEFAULT
,
1015 CW_USEDEFAULT
, CW_USEDEFAULT
,
1016 mdi_client
, GetModuleHandle(0),
1017 (LPARAM
)mdi_lParam_test_message
);
1018 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1020 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1024 ok(mdi_child
!= 0, "MDI child creation failed\n");
1025 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1026 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1029 /* test MDICREATESTRUCT A<->W mapping */
1030 SetLastError(0xdeadbeef);
1031 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1033 CW_USEDEFAULT
, CW_USEDEFAULT
,
1034 CW_USEDEFAULT
, CW_USEDEFAULT
,
1035 mdi_client
, GetModuleHandle(0),
1036 (LPARAM
)mdi_lParam_test_message
);
1039 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1042 ok(mdi_child
!= 0, "MDI child creation failed\n");
1046 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1047 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1050 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1052 CW_USEDEFAULT
, CW_USEDEFAULT
,
1053 CW_USEDEFAULT
, CW_USEDEFAULT
,
1054 mdi_client
, 0, GetModuleHandle(0),
1055 (LPVOID
)mdi_lParam_test_message
);
1056 ok(mdi_child
!= 0, "MDI child creation failed\n");
1057 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1058 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1060 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1061 0x7fffffff, /* without WS_POPUP */
1062 CW_USEDEFAULT
, CW_USEDEFAULT
,
1063 CW_USEDEFAULT
, CW_USEDEFAULT
,
1064 mdi_client
, 0, GetModuleHandle(0),
1065 (LPVOID
)mdi_lParam_test_message
);
1066 ok(mdi_child
!= 0, "MDI child creation failed\n");
1067 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1068 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1070 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1071 0xffffffff, /* with WS_POPUP */
1072 CW_USEDEFAULT
, CW_USEDEFAULT
,
1073 CW_USEDEFAULT
, CW_USEDEFAULT
,
1074 mdi_client
, 0, GetModuleHandle(0),
1075 (LPVOID
)mdi_lParam_test_message
);
1076 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1078 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1082 ok(mdi_child
!= 0, "MDI child creation failed\n");
1083 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1084 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1087 /* test MDICREATESTRUCT A<->W mapping */
1088 SetLastError(0xdeadbeef);
1089 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1091 CW_USEDEFAULT
, CW_USEDEFAULT
,
1092 CW_USEDEFAULT
, CW_USEDEFAULT
,
1093 mdi_client
, 0, GetModuleHandle(0),
1094 (LPVOID
)mdi_lParam_test_message
);
1097 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1100 ok(mdi_child
!= 0, "MDI child creation failed\n");
1104 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1105 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1108 /* This test fails on Win9x */
1111 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1113 CW_USEDEFAULT
, CW_USEDEFAULT
,
1114 CW_USEDEFAULT
, CW_USEDEFAULT
,
1115 parent
, 0, GetModuleHandle(0),
1116 (LPVOID
)mdi_lParam_test_message
);
1117 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1120 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1121 WS_CHILD
, /* without WS_POPUP */
1122 CW_USEDEFAULT
, CW_USEDEFAULT
,
1123 CW_USEDEFAULT
, CW_USEDEFAULT
,
1124 mdi_client
, 0, GetModuleHandle(0),
1125 (LPVOID
)mdi_lParam_test_message
);
1126 ok(mdi_child
!= 0, "MDI child creation failed\n");
1127 DestroyWindow(mdi_child
);
1129 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1130 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1131 CW_USEDEFAULT
, CW_USEDEFAULT
,
1132 CW_USEDEFAULT
, CW_USEDEFAULT
,
1133 mdi_client
, 0, GetModuleHandle(0),
1134 (LPVOID
)mdi_lParam_test_message
);
1135 ok(mdi_child
!= 0, "MDI child creation failed\n");
1136 DestroyWindow(mdi_child
);
1138 /* maximized child */
1139 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1140 WS_CHILD
| WS_MAXIMIZE
,
1141 CW_USEDEFAULT
, CW_USEDEFAULT
,
1142 CW_USEDEFAULT
, CW_USEDEFAULT
,
1143 mdi_client
, 0, GetModuleHandle(0),
1144 (LPVOID
)mdi_lParam_test_message
);
1145 ok(mdi_child
!= 0, "MDI child creation failed\n");
1146 DestroyWindow(mdi_child
);
1148 trace("Creating maximized child with a caption\n");
1149 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1150 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1151 CW_USEDEFAULT
, CW_USEDEFAULT
,
1152 CW_USEDEFAULT
, CW_USEDEFAULT
,
1153 mdi_client
, 0, GetModuleHandle(0),
1154 (LPVOID
)mdi_lParam_test_message
);
1155 ok(mdi_child
!= 0, "MDI child creation failed\n");
1156 DestroyWindow(mdi_child
);
1158 trace("Creating maximized child with a caption and a thick frame\n");
1159 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1160 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1161 CW_USEDEFAULT
, CW_USEDEFAULT
,
1162 CW_USEDEFAULT
, CW_USEDEFAULT
,
1163 mdi_client
, 0, GetModuleHandle(0),
1164 (LPVOID
)mdi_lParam_test_message
);
1165 ok(mdi_child
!= 0, "MDI child creation failed\n");
1166 DestroyWindow(mdi_child
);
1169 /**********************************************************************
1170 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1172 * Note: The rule here is that client rect of the maximized MDI child
1173 * is equal to the client rect of the MDI client window.
1175 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1179 GetClientRect( client
, &rect
);
1180 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1181 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1183 rect
.right
-= rect
.left
;
1184 rect
.bottom
-= rect
.top
;
1185 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1186 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1188 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1189 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1191 trace("max rect (%ld,%ld - %ld, %ld)\n",
1192 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1195 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1202 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1203 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1205 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1206 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1208 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1209 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1210 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1211 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1212 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1214 /* MDICREATESTRUCT should have original values */
1215 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1216 "mdi_cs->style does not match (%08lx)\n", mdi_cs
->style
);
1217 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1218 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1219 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1220 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1222 /* CREATESTRUCT should have fixed values */
1223 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1224 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1226 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1227 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1228 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1230 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1232 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1234 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1235 ok(cs
->style
== style
,
1236 "cs->style does not match (%08lx)\n", cs
->style
);
1240 LONG style
= mdi_cs
->style
;
1242 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1243 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1244 ok(cs
->style
== style
,
1245 "cs->style does not match (%08lx)\n", cs
->style
);
1250 case WM_GETMINMAXINFO
:
1252 HWND client
= GetParent(hwnd
);
1254 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1255 MINMAXINFO my_minmax
;
1256 LONG style
, exstyle
;
1258 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1259 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1261 GetWindowRect(client
, &rc
);
1262 trace("MDI client %p window size = (%ld x %ld)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1263 GetClientRect(client
, &rc
);
1264 trace("MDI client %p client size = (%ld x %ld)\n", client
, rc
.right
, rc
.bottom
);
1265 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1266 GetSystemMetrics(SM_CYSCREEN
));
1268 GetClientRect(client
, &rc
);
1269 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1270 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1271 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1272 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1274 trace("ptReserved = (%ld,%ld)\n"
1275 "ptMaxSize = (%ld,%ld)\n"
1276 "ptMaxPosition = (%ld,%ld)\n"
1277 "ptMinTrackSize = (%ld,%ld)\n"
1278 "ptMaxTrackSize = (%ld,%ld)\n",
1279 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1280 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1281 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1282 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1283 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1285 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %ld != %ld\n",
1286 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1287 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %ld != %ld\n",
1288 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1290 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1292 trace("DefMDIChildProc returned:\n"
1293 "ptReserved = (%ld,%ld)\n"
1294 "ptMaxSize = (%ld,%ld)\n"
1295 "ptMaxPosition = (%ld,%ld)\n"
1296 "ptMinTrackSize = (%ld,%ld)\n"
1297 "ptMaxTrackSize = (%ld,%ld)\n",
1298 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1299 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1300 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1301 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1302 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1304 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1305 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %ld != %ld\n",
1306 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1307 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %ld != %ld\n",
1308 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1313 case WM_MDIACTIVATE
:
1315 HWND active
, client
= GetParent(hwnd
);
1316 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1317 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1318 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1319 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1321 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1325 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1328 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1335 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1337 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1338 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1340 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1341 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1343 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1344 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1346 /* CREATESTRUCT should have fixed values */
1347 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1349 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1350 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1352 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1353 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1354 while Win95, Win2k, WinXP do. */
1355 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1356 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1360 case WM_GETMINMAXINFO
:
1362 HWND parent
= GetParent(hwnd
);
1364 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1365 LONG style
, exstyle
;
1367 trace("WM_GETMINMAXINFO\n");
1369 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1370 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1372 GetClientRect(parent
, &rc
);
1373 trace("parent %p client size = (%ld x %ld)\n", parent
, rc
.right
, rc
.bottom
);
1375 GetClientRect(parent
, &rc
);
1376 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1377 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1378 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1379 trace("calculated max child window size = (%ld x %ld)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1381 trace("ptReserved = (%ld,%ld)\n"
1382 "ptMaxSize = (%ld,%ld)\n"
1383 "ptMaxPosition = (%ld,%ld)\n"
1384 "ptMinTrackSize = (%ld,%ld)\n"
1385 "ptMaxTrackSize = (%ld,%ld)\n",
1386 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1387 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1388 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1389 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1390 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1392 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %ld != %ld\n",
1393 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1394 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %ld != %ld\n",
1395 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1399 case WM_WINDOWPOSCHANGED
:
1401 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1404 GetWindowRect(hwnd
, &rc1
);
1405 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1406 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1407 /* note: winpos coordinates are relative to parent */
1408 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1409 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1410 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1412 GetWindowRect(hwnd
, &rc1
);
1413 GetClientRect(hwnd
, &rc2
);
1414 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1415 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1416 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1419 case WM_WINDOWPOSCHANGING
:
1421 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1422 WINDOWPOS my_winpos
= *winpos
;
1424 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1425 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1426 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1427 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1429 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1431 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1432 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1433 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1435 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1436 "DefWindowProc should not change WINDOWPOS values\n");
1441 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1444 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1446 static HWND mdi_client
;
1452 CLIENTCREATESTRUCT client_cs
;
1455 GetClientRect(hwnd
, &rc
);
1457 client_cs
.hWindowMenu
= 0;
1458 client_cs
.idFirstChild
= 1;
1460 /* MDIClient without MDIS_ALLCHILDSTYLES */
1461 mdi_client
= CreateWindowExA(0, "mdiclient",
1463 WS_CHILD
/*| WS_VISIBLE*/,
1464 /* tests depend on a not zero MDIClient size */
1465 0, 0, rc
.right
, rc
.bottom
,
1466 hwnd
, 0, GetModuleHandle(0),
1467 (LPVOID
)&client_cs
);
1469 test_MDI_create(hwnd
, mdi_client
);
1470 DestroyWindow(mdi_client
);
1472 /* MDIClient with MDIS_ALLCHILDSTYLES */
1473 mdi_client
= CreateWindowExA(0, "mdiclient",
1475 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1476 /* tests depend on a not zero MDIClient size */
1477 0, 0, rc
.right
, rc
.bottom
,
1478 hwnd
, 0, GetModuleHandle(0),
1479 (LPVOID
)&client_cs
);
1481 test_MDI_create(hwnd
, mdi_client
);
1482 DestroyWindow(mdi_client
);
1486 case WM_WINDOWPOSCHANGED
:
1488 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1491 GetWindowRect(hwnd
, &rc1
);
1492 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1493 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1494 /* note: winpos coordinates are relative to parent */
1495 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1496 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1497 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1499 GetWindowRect(hwnd
, &rc1
);
1500 GetClientRect(hwnd
, &rc2
);
1501 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1502 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1503 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1506 case WM_WINDOWPOSCHANGING
:
1508 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1509 WINDOWPOS my_winpos
= *winpos
;
1511 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1512 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1513 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1514 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1516 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1518 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1519 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1520 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1522 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1523 "DefWindowProc should not change WINDOWPOS values\n");
1532 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1535 static BOOL
mdi_RegisterWindowClasses(void)
1540 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1543 cls
.hInstance
= GetModuleHandleA(0);
1545 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1546 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1547 cls
.lpszMenuName
= NULL
;
1548 cls
.lpszClassName
= "MDI_parent_Class";
1549 if(!RegisterClassA(&cls
)) return FALSE
;
1551 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1552 cls
.lpszClassName
= "MDI_child_Class_1";
1553 if(!RegisterClassA(&cls
)) return FALSE
;
1555 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1556 cls
.lpszClassName
= "MDI_child_Class_2";
1557 if(!RegisterClassA(&cls
)) return FALSE
;
1562 static void test_mdi(void)
1567 if (!mdi_RegisterWindowClasses()) assert(0);
1569 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1570 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1571 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1572 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1573 GetDesktopWindow(), 0,
1574 GetModuleHandle(0), NULL
);
1575 assert(mdi_hwndMain
);
1577 while(GetMessage(&msg, 0, 0, 0))
1579 TranslateMessage(&msg);
1580 DispatchMessage(&msg);
1585 static void test_icons(void)
1589 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1590 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1591 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1592 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1595 cls
.cbSize
= sizeof(cls
);
1597 cls
.lpfnWndProc
= DefWindowProcA
;
1601 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1602 cls
.hIconSm
= small_icon
;
1603 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1604 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1605 cls
.lpszMenuName
= NULL
;
1606 cls
.lpszClassName
= "IconWindowClass";
1608 RegisterClassExA(&cls
);
1610 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1611 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1614 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1615 ok( res
== 0, "wrong big icon %p/0\n", res
);
1616 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1617 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1618 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1619 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1620 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1621 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1622 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1623 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1625 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1626 ok( res
== 0, "wrong small icon %p/0\n", res
);
1627 /* this test is XP specific */
1628 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1629 ok( res != 0, "wrong small icon %p\n", res );*/
1630 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1631 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1632 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1633 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1634 /* this test is XP specific */
1635 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1636 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1637 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1638 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1639 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1640 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1641 /* this test is XP specific */
1642 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1643 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1645 /* make sure the big icon hasn't changed */
1646 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1647 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1650 static void test_SetWindowPos(HWND hwnd
)
1653 BOOL is_win9x
= GetWindowLongW(hwnd
, GWL_WNDPROC
) == 0;
1655 /* Win9x truncates coordinates to 16-bit irrespectively */
1656 if (is_win9x
) return;
1658 GetWindowRect(hwnd
, &orig_win_rc
);
1660 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1661 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1663 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1664 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1666 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1667 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1670 static void test_SetMenu(HWND parent
)
1674 BOOL is_win9x
= GetWindowLongW(parent
, GWL_WNDPROC
) == 0;
1676 hMenu
= CreateMenu();
1679 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1680 test_nonclient_area(parent
);
1681 ret
= GetMenu(parent
);
1682 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1683 /* test whether we can destroy a menu assigned to a window */
1684 ok(DestroyMenu(hMenu
), "DestroyMenu error %ld\n", GetLastError());
1685 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1686 ret
= GetMenu(parent
);
1687 /* This test fails on Win9x */
1689 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1690 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1691 test_nonclient_area(parent
);
1693 hMenu
= CreateMenu();
1697 ret
= GetMenu(parent
);
1698 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1700 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1701 test_nonclient_area(parent
);
1702 ret
= GetMenu(parent
);
1703 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1705 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1706 test_nonclient_area(parent
);
1707 ret
= GetMenu(parent
);
1708 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1710 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1711 test_nonclient_area(parent
);
1712 ret
= GetMenu(parent
);
1713 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1716 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1719 ret
= GetMenu(child
);
1720 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1722 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1723 test_nonclient_area(child
);
1724 ret
= GetMenu(child
);
1725 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1727 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1728 test_nonclient_area(child
);
1729 ret
= GetMenu(child
);
1730 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1732 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1733 test_nonclient_area(child
);
1734 ret
= GetMenu(child
);
1735 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1737 DestroyWindow(child
);
1741 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1743 HWND child
[5], hwnd
;
1748 hwnd
= GetWindow(parent
, GW_CHILD
);
1749 ok(!hwnd
, "have to start without children to perform the test\n");
1751 for (i
= 0; i
< total
; i
++)
1753 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1754 parent
, 0, 0, NULL
);
1755 trace("child[%d] = %p\n", i
, child
[i
]);
1756 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1759 hwnd
= GetWindow(parent
, GW_CHILD
);
1760 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1761 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1762 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1764 for (i
= 0; i
< total
; i
++)
1766 trace("hwnd[%d] = %p\n", i
, hwnd
);
1767 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1769 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1772 for (i
= 0; i
< total
; i
++)
1773 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
1776 static void test_children_zorder(HWND parent
)
1778 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
1780 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
1782 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
1783 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
1784 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
1785 const int complex_order_1
[1] = { 0 };
1786 const int complex_order_2
[2] = { 1, 0 };
1787 const int complex_order_3
[3] = { 1, 0, 2 };
1788 const int complex_order_4
[4] = { 1, 0, 2, 3 };
1789 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
1791 /* simple WS_CHILD */
1792 test_window_tree(parent
, simple_style
, simple_order
, 5);
1794 /* complex children styles */
1795 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
1796 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
1797 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
1798 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
1799 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
1802 static void test_SetFocus(HWND hwnd
)
1806 /* check if we can set focus to non-visible windows */
1808 ShowWindow(hwnd
, SW_SHOW
);
1811 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
1812 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
1813 ShowWindow(hwnd
, SW_HIDE
);
1816 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
1817 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
1818 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1821 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
1822 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
1823 ShowWindow(child
, SW_SHOW
);
1824 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
1825 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
1826 ShowWindow(child
, SW_HIDE
);
1827 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
1828 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
1829 ShowWindow(child
, SW_SHOW
);
1831 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
1832 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
1833 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
1835 ShowWindow(child
, SW_HIDE
);
1837 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
1838 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
1839 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
1840 ShowWindow(child
, SW_HIDE
);
1841 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
1843 ShowWindow(hwnd
, SW_SHOW
);
1844 ShowWindow(child
, SW_SHOW
);
1846 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
1847 EnableWindow(hwnd
, FALSE
);
1848 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
1849 EnableWindow(hwnd
, TRUE
);
1851 DestroyWindow( child
);
1854 static void test_SetActiveWindow(HWND hwnd
)
1858 ShowWindow(hwnd
, SW_SHOW
);
1860 SetActiveWindow(hwnd
);
1861 ok( GetActiveWindow() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
1862 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
1863 ok( GetActiveWindow() == hwnd
, "Window %p no longer active\n", hwnd
);
1864 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
1865 ShowWindow(hwnd
, SW_HIDE
);
1866 ok( GetActiveWindow() != hwnd
, "Window %p is still active\n", hwnd
);
1867 ShowWindow(hwnd
, SW_SHOW
);
1869 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1870 ok( GetActiveWindow() == hwnd2
, "Window %p is not active\n", hwnd2
);
1871 DestroyWindow(hwnd2
);
1872 ok( GetActiveWindow() != hwnd2
, "Window %p is still active\n", hwnd2
);
1874 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1875 ok( GetActiveWindow() == hwnd2
, "Window %p is not active\n", hwnd2
);
1876 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
1877 ok( GetActiveWindow() == hwnd2
, "Window %p no longer active (%p)\n", hwnd2
, GetActiveWindow() );
1878 DestroyWindow(hwnd2
);
1879 ok( GetActiveWindow() != hwnd2
, "Window %p is still active\n", hwnd2
);
1882 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
1884 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1886 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1887 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
1888 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
1891 static WNDPROC old_button_proc
;
1893 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1898 key_state
= GetKeyState(VK_LBUTTON
);
1899 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
1901 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
1903 if (msg
== WM_LBUTTONDOWN
)
1907 check_wnd_state(button
, button
, button
, button
);
1909 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1911 trace("hwnd %p\n", hwnd
);
1913 check_wnd_state(button
, button
, button
, button
);
1915 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
1917 check_wnd_state(button
, button
, button
, button
);
1919 DestroyWindow(hwnd
);
1921 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1923 trace("hwnd %p\n", hwnd
);
1925 check_wnd_state(button
, button
, button
, button
);
1927 /* button wnd proc should release capture on WM_KILLFOCUS if it does
1928 * match internal button state.
1930 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
1931 check_wnd_state(button
, button
, button
, 0);
1933 ShowWindow(hwnd
, SW_SHOW
);
1934 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
1936 capture
= SetCapture(hwnd
);
1937 ok(capture
== 0, "SetCapture() = %p\n", capture
);
1939 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
1941 DestroyWindow(hwnd
);
1943 check_wnd_state(button
, 0, button
, 0);
1949 static void test_capture_1(void)
1951 HWND button
, capture
;
1953 capture
= GetCapture();
1954 ok(capture
== 0, "GetCapture() = %p\n", capture
);
1956 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1958 trace("button %p\n", button
);
1960 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
1962 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
1964 DestroyWindow(button
);
1967 static void test_capture_2(void)
1969 HWND button
, hwnd
, capture
;
1971 check_wnd_state(0, 0, 0, 0);
1973 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1975 trace("button %p\n", button
);
1977 check_wnd_state(button
, button
, button
, 0);
1979 capture
= SetCapture(button
);
1980 ok(capture
== 0, "SetCapture() = %p\n", capture
);
1982 check_wnd_state(button
, button
, button
, button
);
1984 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
1985 * internal button state.
1987 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
1988 check_wnd_state(button
, button
, button
, button
);
1990 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1992 trace("hwnd %p\n", hwnd
);
1994 check_wnd_state(button
, button
, button
, button
);
1996 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
1998 check_wnd_state(button
, button
, button
, button
);
2000 DestroyWindow(hwnd
);
2002 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2004 trace("hwnd %p\n", hwnd
);
2006 check_wnd_state(button
, button
, button
, button
);
2008 ShowWindow(hwnd
, SW_SHOW
);
2010 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2012 capture
= SetCapture(hwnd
);
2013 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2015 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2017 DestroyWindow(hwnd
);
2018 check_wnd_state(button
, button
, button
, 0);
2020 DestroyWindow(button
);
2021 check_wnd_state(0, 0, 0, 0);
2024 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2026 ShowWindow(hwnd1
, SW_HIDE
);
2027 ShowWindow(hwnd2
, SW_HIDE
);
2029 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2030 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2033 check_wnd_state(0, 0, 0, hwnd1
);
2036 check_wnd_state(0, 0, 0, hwnd2
);
2038 ShowWindow(hwnd1
, SW_SHOW
);
2039 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2044 static void test_keyboard_input(HWND hwnd
)
2048 ShowWindow(hwnd
, SW_SHOW
);
2051 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2054 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2056 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2058 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2059 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2060 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2061 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2063 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2065 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2066 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2067 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2068 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2070 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2072 keybd_event(VK_SPACE
, 0, 0, 0);
2073 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2074 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2075 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2078 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2080 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2082 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2083 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2084 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2085 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2087 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2089 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2090 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2091 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2092 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2094 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2096 keybd_event(VK_SPACE
, 0, 0, 0);
2097 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2098 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2099 ok(!PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "message %04x available\n", msg
.message
);
2104 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2105 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2107 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
2110 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
2113 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
2114 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2115 trace("hwndMessage %p\n", hwndMessage
);
2117 DestroyWindow(hwndMain
);
2120 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2122 if (!RegisterWindowClasses()) assert(0);
2124 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
2127 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2128 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2129 WS_MAXIMIZEBOX
| WS_POPUP
,
2132 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2133 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2134 WS_MAXIMIZEBOX
| WS_POPUP
,
2138 assert( hwndMain2
);
2142 test_capture_3(hwndMain
, hwndMain2
);
2144 test_parent_owner();
2145 test_shell_window();
2149 test_SetWindowPos(hwndMain
);
2150 test_SetMenu(hwndMain
);
2151 test_SetFocus(hwndMain
);
2152 test_SetActiveWindow(hwndMain
);
2154 test_children_zorder(hwndMain
);
2155 test_keyboard_input(hwndMain
);
2157 UnhookWindowsHookEx(hhook
);