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 BOOL test_lbuttondown_flag
;
52 static HWND hwndMessage
;
53 static HWND hwndMain
, hwndMain2
;
56 /* check the values returned by the various parent/owner functions on a given window */
57 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
58 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
64 res
= pGetAncestor( hwnd
, GA_PARENT
);
65 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
67 res
= (HWND
)GetWindowLongA( hwnd
, GWL_HWNDPARENT
);
68 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
69 res
= GetParent( hwnd
);
70 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
71 res
= GetWindow( hwnd
, GW_OWNER
);
72 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
75 res
= pGetAncestor( hwnd
, GA_ROOT
);
76 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
77 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
78 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
83 static HWND
create_tool_window( LONG style
, HWND parent
)
85 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
86 0, 0, 100, 100, parent
, 0, 0, NULL
);
87 ok( ret
!= 0, "Creation failed\n" );
91 /* test parent and owner values for various combinations */
92 static void test_parent_owner(void)
95 HWND test
, owner
, ret
;
96 HWND desktop
= GetDesktopWindow();
97 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
99 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
101 /* child without parent, should fail */
102 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
103 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
104 ok( !test
, "WS_CHILD without parent created\n" );
107 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
108 style
= GetWindowLongA( desktop
, GWL_STYLE
);
109 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
110 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
111 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
113 /* normal child window */
114 test
= create_tool_window( WS_CHILD
, hwndMain
);
115 trace( "created child %p\n", test
);
116 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
117 SetWindowLongA( test
, GWL_STYLE
, 0 );
118 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
119 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
120 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
121 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
122 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
123 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
124 DestroyWindow( test
);
126 /* normal child window with WS_MAXIMIZE */
127 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
128 DestroyWindow( test
);
130 /* normal child window with WS_THICKFRAME */
131 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
132 DestroyWindow( test
);
134 /* popup window with WS_THICKFRAME */
135 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
136 DestroyWindow( test
);
138 /* child of desktop */
139 test
= create_tool_window( WS_CHILD
, desktop
);
140 trace( "created child of desktop %p\n", test
);
141 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
142 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
143 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
144 SetWindowLongA( test
, GWL_STYLE
, 0 );
145 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
146 DestroyWindow( test
);
148 /* child of desktop with WS_MAXIMIZE */
149 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
150 DestroyWindow( test
);
152 /* child of desktop with WS_MINIMIZE */
153 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
154 DestroyWindow( test
);
157 test
= create_tool_window( WS_CHILD
, child
);
158 trace( "created child of child %p\n", test
);
159 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
160 SetWindowLongA( test
, GWL_STYLE
, 0 );
161 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
162 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
163 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
164 DestroyWindow( test
);
166 /* child of child with WS_MAXIMIZE */
167 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
168 DestroyWindow( test
);
170 /* child of child with WS_MINIMIZE */
171 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
172 DestroyWindow( test
);
174 /* not owned top-level window */
175 test
= create_tool_window( 0, 0 );
176 trace( "created top-level %p\n", test
);
177 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
178 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
179 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
180 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
181 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
182 DestroyWindow( test
);
184 /* not owned top-level window with WS_MAXIMIZE */
185 test
= create_tool_window( WS_MAXIMIZE
, 0 );
186 DestroyWindow( test
);
188 /* owned top-level window */
189 test
= create_tool_window( 0, hwndMain
);
190 trace( "created owned top-level %p\n", test
);
191 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
192 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
193 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
194 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
195 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
196 DestroyWindow( test
);
198 /* owned top-level window with WS_MAXIMIZE */
199 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
200 DestroyWindow( test
);
202 /* not owned popup */
203 test
= create_tool_window( WS_POPUP
, 0 );
204 trace( "created popup %p\n", test
);
205 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
206 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
207 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
208 SetWindowLongA( test
, GWL_STYLE
, 0 );
209 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
210 DestroyWindow( test
);
212 /* not owned popup with WS_MAXIMIZE */
213 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
214 DestroyWindow( test
);
217 test
= create_tool_window( WS_POPUP
, hwndMain
);
218 trace( "created owned popup %p\n", test
);
219 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
220 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
221 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
222 SetWindowLongA( test
, GWL_STYLE
, 0 );
223 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
224 DestroyWindow( test
);
226 /* owned popup with WS_MAXIMIZE */
227 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
228 DestroyWindow( test
);
230 /* top-level window owned by child (same as owned by top-level) */
231 test
= create_tool_window( 0, child
);
232 trace( "created top-level owned by child %p\n", test
);
233 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
234 DestroyWindow( test
);
236 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
237 test
= create_tool_window( WS_MAXIMIZE
, child
);
238 DestroyWindow( test
);
240 /* popup owned by desktop (same as not owned) */
241 test
= create_tool_window( WS_POPUP
, desktop
);
242 trace( "created popup owned by desktop %p\n", test
);
243 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
244 DestroyWindow( test
);
246 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
247 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
248 DestroyWindow( test
);
250 /* popup owned by child (same as owned by top-level) */
251 test
= create_tool_window( WS_POPUP
, child
);
252 trace( "created popup owned by child %p\n", test
);
253 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
254 DestroyWindow( test
);
256 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
257 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
258 DestroyWindow( test
);
260 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
261 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
262 trace( "created WS_CHILD popup %p\n", test
);
263 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
264 DestroyWindow( test
);
266 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
267 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
268 DestroyWindow( test
);
270 /* owned popup with WS_CHILD (same as WS_POPUP only) */
271 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
272 trace( "created owned WS_CHILD popup %p\n", test
);
273 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
274 DestroyWindow( test
);
276 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
277 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
278 DestroyWindow( test
);
280 /******************** parent changes *************************/
281 trace( "testing parent changes\n" );
284 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
285 #if 0 /* this test succeeds on NT but crashes on win9x systems */
286 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
287 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
288 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
289 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
290 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
292 /* normal child window */
293 test
= create_tool_window( WS_CHILD
, hwndMain
);
294 trace( "created child %p\n", test
);
296 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
297 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
298 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
300 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
301 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
302 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
304 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)desktop
);
305 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
306 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
308 /* window is now child of desktop so GWL_HWNDPARENT changes owner from now on */
309 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
310 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
311 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
313 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
314 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
315 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
316 DestroyWindow( test
);
318 /* not owned top-level window */
319 test
= create_tool_window( 0, 0 );
320 trace( "created top-level %p\n", test
);
322 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
323 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
324 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
326 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
327 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
328 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
330 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
331 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
332 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
333 DestroyWindow( test
);
335 /* not owned popup */
336 test
= create_tool_window( WS_POPUP
, 0 );
337 trace( "created popup %p\n", test
);
339 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
340 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
341 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
343 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (LONG_PTR
)child
);
344 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
345 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
347 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, 0 );
348 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
349 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
350 DestroyWindow( test
);
352 /* normal child window */
353 test
= create_tool_window( WS_CHILD
, hwndMain
);
354 trace( "created child %p\n", test
);
356 ret
= SetParent( test
, desktop
);
357 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
358 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
360 ret
= SetParent( test
, child
);
361 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
362 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
364 ret
= SetParent( test
, hwndMain2
);
365 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
366 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
367 DestroyWindow( test
);
369 /* not owned top-level window */
370 test
= create_tool_window( 0, 0 );
371 trace( "created top-level %p\n", test
);
373 ret
= SetParent( test
, child
);
374 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
375 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
376 DestroyWindow( test
);
379 test
= create_tool_window( WS_POPUP
, hwndMain2
);
380 trace( "created owned popup %p\n", test
);
382 ret
= SetParent( test
, child
);
383 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
384 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
386 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
387 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
388 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
389 DestroyWindow( test
);
391 /**************** test owner destruction *******************/
393 /* owned child popup */
394 owner
= create_tool_window( 0, 0 );
395 test
= create_tool_window( WS_POPUP
, owner
);
396 trace( "created owner %p and popup %p\n", owner
, test
);
397 ret
= SetParent( test
, child
);
398 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
399 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
400 /* window is now child of 'child' but owned by 'owner' */
401 DestroyWindow( owner
);
402 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
403 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
404 * while Win95, Win2k, WinXP do.
406 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
407 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
410 /* owned top-level popup */
411 owner
= create_tool_window( 0, 0 );
412 test
= create_tool_window( WS_POPUP
, owner
);
413 trace( "created owner %p and popup %p\n", owner
, test
);
414 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
415 DestroyWindow( owner
);
416 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
418 /* top-level popup owned by child */
419 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
420 test
= create_tool_window( WS_POPUP
, 0 );
421 trace( "created owner %p and popup %p\n", owner
, test
);
422 ret
= (HWND
)SetWindowLongA( test
, GWL_HWNDPARENT
, (ULONG_PTR
)owner
);
423 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
424 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
425 DestroyWindow( owner
);
426 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
427 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
428 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
429 * while Win95, Win2k, WinXP do.
431 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
435 DestroyWindow(child
);
439 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
443 case WM_GETMINMAXINFO
:
445 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
447 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd
, wparam
, lparam
);
448 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
449 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
450 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
451 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
452 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
453 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
454 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
455 SetWindowLongA(hwnd
, GWL_USERDATA
, 0x20031021);
458 case WM_WINDOWPOSCHANGING
:
460 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
461 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
462 trace("main: WM_WINDOWPOSCHANGING\n");
463 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
464 winpos
->hwnd
, winpos
->hwndInsertAfter
,
465 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
466 if (!(winpos
->flags
& SWP_NOMOVE
))
468 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
469 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
471 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
472 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
474 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
475 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
479 case WM_WINDOWPOSCHANGED
:
482 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
483 trace("main: WM_WINDOWPOSCHANGED\n");
484 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
485 winpos
->hwnd
, winpos
->hwndInsertAfter
,
486 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
487 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
488 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
490 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
491 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
493 GetWindowRect(hwnd
, &rc1
);
494 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
495 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
496 /* note: winpos coordinates are relative to parent */
497 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
498 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
499 #if 0 /* Uncomment this once the test succeeds in all cases */
500 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
503 GetClientRect(hwnd
, &rc2
);
504 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
505 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
506 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%ld,%ld-%ld,%ld) / (%ld,%ld-%ld,%ld)\n",
507 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
512 BOOL got_getminmaxinfo
= GetWindowLongA(hwnd
, GWL_USERDATA
) == 0x20031021;
513 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
515 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd
, cs
->hwndParent
, cs
->style
);
516 if (got_getminmaxinfo
)
517 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
519 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
520 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
522 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
526 if (test_lbuttondown_flag
)
527 ShowWindow((HWND
)wparam
, SW_SHOW
);
531 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
534 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
538 case WM_GETMINMAXINFO
:
540 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
542 trace("hwnd %p, WM_GETMINMAXINFO, %08x, %08lx\n", hwnd
, wparam
, lparam
);
543 trace("ptReserved (%ld,%ld), ptMaxSize (%ld,%ld), ptMaxPosition (%ld,%ld)\n"
544 " ptMinTrackSize (%ld,%ld), ptMaxTrackSize (%ld,%ld)\n",
545 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
546 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
547 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
548 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
549 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
550 SetWindowLongA(hwnd
, GWL_USERDATA
, 0x20031021);
555 BOOL got_getminmaxinfo
= GetWindowLongA(hwnd
, GWL_USERDATA
) == 0x20031021;
556 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
558 trace("WM_NCCREATE: hwnd %p, parent %p, style %08lx\n", hwnd
, cs
->hwndParent
, cs
->style
);
559 if (got_getminmaxinfo
)
560 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
562 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
563 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
565 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
570 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
573 static BOOL
RegisterWindowClasses(void)
577 cls
.style
= CS_DBLCLKS
;
578 cls
.lpfnWndProc
= main_window_procA
;
581 cls
.hInstance
= GetModuleHandleA(0);
583 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
584 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
585 cls
.lpszMenuName
= NULL
;
586 cls
.lpszClassName
= "MainWindowClass";
588 if(!RegisterClassA(&cls
)) return FALSE
;
591 cls
.lpfnWndProc
= tool_window_procA
;
594 cls
.hInstance
= GetModuleHandleA(0);
596 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
597 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
598 cls
.lpszMenuName
= NULL
;
599 cls
.lpszClassName
= "ToolWindowClass";
601 if(!RegisterClassA(&cls
)) return FALSE
;
606 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
, BOOL test_borders
)
608 RECT rcWindow
, rcClient
;
612 ok(IsWindow(hwnd
), "bad window handle\n");
614 GetWindowRect(hwnd
, &rcWindow
);
615 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
617 GetClientRect(hwnd
, &rcClient
);
618 /* translate to screen coordinates */
619 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
620 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
622 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
623 "wrong dwStyle: %08lx != %08lx\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
624 ok(info
->dwExStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
625 "wrong dwExStyle: %08lx != %08lx\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
626 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
627 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04lx != %04lx\n",
628 info
->dwWindowStatus
, status
);
630 if (test_borders
&& !IsRectEmpty(&rcWindow
))
632 trace("rcWindow: %ld,%ld - %ld,%ld\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
633 trace("rcClient: %ld,%ld - %ld,%ld\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
635 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
636 "wrong cxWindowBorders %d != %ld\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
637 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
638 ok(info
->cyWindowBorders
== border
,
639 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
642 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
643 ok(info
->wCreatorVersion
== 0x0400, "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
646 static void test_nonclient_area(HWND hwnd
)
648 DWORD style
, exstyle
;
649 RECT rc_window
, rc_client
, rc
;
652 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
653 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
654 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
656 GetWindowRect(hwnd
, &rc_window
);
657 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
658 GetClientRect(hwnd
, &rc_client
);
659 trace("client: (%ld,%ld)-(%ld,%ld)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
661 /* avoid some cases when things go wrong */
662 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
663 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
665 CopyRect(&rc
, &rc_client
);
666 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
667 AdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
668 trace("calc window: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
669 #if 0 /* Uncomment this once the test succeeds in all cases */
670 ok(EqualRect(&rc
, &rc_window
), "window rect does not match\n");
673 CopyRect(&rc
, &rc_window
);
674 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
675 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
676 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
677 #if 0 /* Uncomment this once the test succeeds in all cases */
678 ok(EqualRect(&rc
, &rc_client
), "client rect does not match\n");
681 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
682 SetRect(&rc_client
, 0, 0, 250, 150);
683 CopyRect(&rc_window
, &rc_client
);
684 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
685 AdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
686 trace("calc window: (%ld,%ld)-(%ld,%ld)\n",
687 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
689 CopyRect(&rc
, &rc_window
);
690 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
691 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
692 trace("calc client: (%ld,%ld)-(%ld,%ld)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
693 #if 0 /* Uncomment this once the test succeeds in all cases */
694 ok(EqualRect(&rc
, &rc_client
), "client rect does not match\n");
698 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
700 static const char *CBT_code_name
[10] = {
711 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
713 trace("CBT: %d (%s), %08x, %08lx\n", nCode
, code_name
, wParam
, lParam
);
715 /* on HCBT_DESTROYWND window state is undefined */
716 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
718 BOOL is_win9x
= GetWindowLongPtrW((HWND
)wParam
, GWLP_WNDPROC
) == 0;
719 if (is_win9x
&& nCode
== HCBT_CREATEWND
)
720 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
722 test_nonclient_area((HWND
)wParam
);
728 /* Win98 actually does check the info.cbSize and doesn't allow
729 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
730 * WinXP do not check it at all.
732 info
.cbSize
= sizeof(WINDOWINFO
);
733 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
734 /* win2k SP4 returns broken border info if GetWindowInfo
735 * is being called from HCBT_DESTROYWND or HCBT_MINMAX hook proc.
737 verify_window_info((HWND
)wParam
, &info
, nCode
!= HCBT_MINMAX
);
745 #if 0 /* Uncomment this once the test succeeds in all cases */
746 static const RECT rc_null
;
750 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
751 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08lx\n",
752 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
753 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
755 /* WS_VISIBLE should be turned off yet */
756 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
757 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
758 "style of hwnd and style in the CREATESTRUCT do not match: %08lx != %08lx\n",
759 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
761 #if 0 /* Uncomment this once the test succeeds in all cases */
762 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
764 ok(GetParent((HWND
)wParam
) == hwndMessage
,
765 "wrong result from GetParent %p: message window %p\n",
766 GetParent((HWND
)wParam
), hwndMessage
);
769 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
771 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
773 #if 0 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
774 * Win9x still has them set to 0.
776 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
777 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
779 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
780 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
782 #if 0 /* Uncomment this once the test succeeds in all cases */
785 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
786 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
787 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
789 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
790 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
791 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
793 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
794 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
797 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
798 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
799 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
800 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
806 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
809 static void test_shell_window(void)
813 HMODULE hinst
, hUser32
;
814 BOOL (WINAPI
*SetShellWindow
)(HWND
);
815 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
816 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
817 HWND shellWindow
, nextWnd
;
819 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
821 trace("Skipping shell window test on Win9x\n");
825 shellWindow
= GetShellWindow();
826 hinst
= GetModuleHandle(0);
827 hUser32
= GetModuleHandleA("user32");
829 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
830 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
832 trace("previous shell window: %p\n", shellWindow
);
838 ret
= DestroyWindow(shellWindow
);
839 error
= GetLastError();
841 ok(!ret
, "DestroyWindow(shellWindow)\n");
842 /* passes on Win XP, but not on Win98 */
843 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
845 /* close old shell instance */
846 GetWindowThreadProcessId(shellWindow
, &pid
);
847 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
848 ret
= TerminateProcess(hProcess
, 0);
849 ok(ret
, "termination of previous shell process failed: GetLastError()=%ld\n", GetLastError());
850 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
851 CloseHandle(hProcess
);
854 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
855 trace("created window 1: %p\n", hwnd1
);
857 ret
= SetShellWindow(hwnd1
);
858 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
859 shellWindow
= GetShellWindow();
860 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
862 ret
= SetShellWindow(hwnd1
);
863 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
865 ret
= SetShellWindow(0);
866 error
= GetLastError();
867 /* passes on Win XP, but not on Win98
868 ok(!ret, "reset shell window by SetShellWindow(0)\n");
869 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
871 ret
= SetShellWindow(hwnd1
);
872 /* passes on Win XP, but not on Win98
873 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
877 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
878 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
879 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
882 ret
= DestroyWindow(hwnd1
);
883 ok(ret
, "DestroyWindow(hwnd1)\n");
885 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
886 trace("created window 2: %p\n", hwnd2
);
887 ret
= SetShellWindow(hwnd2
);
888 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
890 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
891 trace("created window 3: %p\n", hwnd3
);
893 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
894 trace("created window 4: %p\n", hwnd4
);
896 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
897 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
899 ret
= SetShellWindow(hwnd4
);
900 ok(ret
, "SetShellWindow(hwnd4)\n");
901 shellWindow
= GetShellWindow();
902 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
904 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
905 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
907 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
908 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
910 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
911 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
913 ret
= SetShellWindow(hwnd3
);
914 ok(!ret
, "SetShellWindow(hwnd3)\n");
915 shellWindow
= GetShellWindow();
916 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
918 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
919 trace("created window 5: %p\n", hwnd5
);
920 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
921 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
925 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
926 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
929 /* destroy test windows */
930 DestroyWindow(hwnd2
);
931 DestroyWindow(hwnd3
);
932 DestroyWindow(hwnd4
);
933 DestroyWindow(hwnd5
);
936 /************** MDI test ****************/
938 static const char mdi_lParam_test_message
[] = "just a test string";
940 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
942 MDICREATESTRUCTA mdi_cs
;
944 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
945 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
946 BOOL isWin9x
= FALSE
;
948 mdi_cs
.szClass
= "MDI_child_Class_1";
949 mdi_cs
.szTitle
= "MDI child";
950 mdi_cs
.hOwner
= GetModuleHandle(0);
951 mdi_cs
.x
= CW_USEDEFAULT
;
952 mdi_cs
.y
= CW_USEDEFAULT
;
953 mdi_cs
.cx
= CW_USEDEFAULT
;
954 mdi_cs
.cy
= CW_USEDEFAULT
;
956 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
957 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
958 ok(mdi_child
!= 0, "MDI child creation failed\n");
959 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
960 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
961 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
963 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
964 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
965 ok(mdi_child
!= 0, "MDI child creation failed\n");
966 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
967 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
968 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
970 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
971 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
972 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
974 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
978 ok(mdi_child
!= 0, "MDI child creation failed\n");
979 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
980 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
981 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
984 /* test MDICREATESTRUCT A<->W mapping */
985 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
987 mdi_cs
.szClass
= (LPCSTR
)classW
;
988 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
989 SetLastError(0xdeadbeef);
990 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
993 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
996 ok(mdi_child
!= 0, "MDI child creation failed\n");
1000 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1001 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1002 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1005 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1007 CW_USEDEFAULT
, CW_USEDEFAULT
,
1008 CW_USEDEFAULT
, CW_USEDEFAULT
,
1009 mdi_client
, GetModuleHandle(0),
1010 (LPARAM
)mdi_lParam_test_message
);
1011 ok(mdi_child
!= 0, "MDI child creation failed\n");
1012 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1013 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1014 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1016 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1017 0x7fffffff, /* without WS_POPUP */
1018 CW_USEDEFAULT
, CW_USEDEFAULT
,
1019 CW_USEDEFAULT
, CW_USEDEFAULT
,
1020 mdi_client
, GetModuleHandle(0),
1021 (LPARAM
)mdi_lParam_test_message
);
1022 ok(mdi_child
!= 0, "MDI child creation failed\n");
1023 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1024 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1025 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1027 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1028 0xffffffff, /* with WS_POPUP */
1029 CW_USEDEFAULT
, CW_USEDEFAULT
,
1030 CW_USEDEFAULT
, CW_USEDEFAULT
,
1031 mdi_client
, GetModuleHandle(0),
1032 (LPARAM
)mdi_lParam_test_message
);
1033 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1035 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1039 ok(mdi_child
!= 0, "MDI child creation failed\n");
1040 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1041 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1042 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1045 /* test MDICREATESTRUCT A<->W mapping */
1046 SetLastError(0xdeadbeef);
1047 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1049 CW_USEDEFAULT
, CW_USEDEFAULT
,
1050 CW_USEDEFAULT
, CW_USEDEFAULT
,
1051 mdi_client
, GetModuleHandle(0),
1052 (LPARAM
)mdi_lParam_test_message
);
1055 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1058 ok(mdi_child
!= 0, "MDI child creation failed\n");
1062 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1063 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1064 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1067 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1069 CW_USEDEFAULT
, CW_USEDEFAULT
,
1070 CW_USEDEFAULT
, CW_USEDEFAULT
,
1071 mdi_client
, 0, GetModuleHandle(0),
1072 (LPVOID
)mdi_lParam_test_message
);
1073 ok(mdi_child
!= 0, "MDI child creation failed\n");
1074 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1075 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1076 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1078 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1079 0x7fffffff, /* without WS_POPUP */
1080 CW_USEDEFAULT
, CW_USEDEFAULT
,
1081 CW_USEDEFAULT
, CW_USEDEFAULT
,
1082 mdi_client
, 0, GetModuleHandle(0),
1083 (LPVOID
)mdi_lParam_test_message
);
1084 ok(mdi_child
!= 0, "MDI child creation failed\n");
1085 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1086 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1087 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1089 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1090 0xffffffff, /* with WS_POPUP */
1091 CW_USEDEFAULT
, CW_USEDEFAULT
,
1092 CW_USEDEFAULT
, CW_USEDEFAULT
,
1093 mdi_client
, 0, GetModuleHandle(0),
1094 (LPVOID
)mdi_lParam_test_message
);
1095 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1097 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1101 ok(mdi_child
!= 0, "MDI child creation failed\n");
1102 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1103 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1104 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1107 /* test MDICREATESTRUCT A<->W mapping */
1108 SetLastError(0xdeadbeef);
1109 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1111 CW_USEDEFAULT
, CW_USEDEFAULT
,
1112 CW_USEDEFAULT
, CW_USEDEFAULT
,
1113 mdi_client
, 0, GetModuleHandle(0),
1114 (LPVOID
)mdi_lParam_test_message
);
1117 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1120 ok(mdi_child
!= 0, "MDI child creation failed\n");
1124 ok(GetWindowLongA(mdi_child
, GWL_ID
) == first_id
, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1125 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1126 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1129 /* This test fails on Win9x */
1132 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1134 CW_USEDEFAULT
, CW_USEDEFAULT
,
1135 CW_USEDEFAULT
, CW_USEDEFAULT
,
1136 parent
, 0, GetModuleHandle(0),
1137 (LPVOID
)mdi_lParam_test_message
);
1138 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1141 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1142 WS_CHILD
, /* without WS_POPUP */
1143 CW_USEDEFAULT
, CW_USEDEFAULT
,
1144 CW_USEDEFAULT
, CW_USEDEFAULT
,
1145 mdi_client
, 0, GetModuleHandle(0),
1146 (LPVOID
)mdi_lParam_test_message
);
1147 ok(mdi_child
!= 0, "MDI child creation failed\n");
1148 ok(GetWindowLongA(mdi_child
, GWL_ID
) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1149 DestroyWindow(mdi_child
);
1151 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1152 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1153 CW_USEDEFAULT
, CW_USEDEFAULT
,
1154 CW_USEDEFAULT
, CW_USEDEFAULT
,
1155 mdi_client
, 0, GetModuleHandle(0),
1156 (LPVOID
)mdi_lParam_test_message
);
1157 ok(mdi_child
!= 0, "MDI child creation failed\n");
1158 ok(GetWindowLongA(mdi_child
, GWL_ID
) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1159 DestroyWindow(mdi_child
);
1161 /* maximized child */
1162 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1163 WS_CHILD
| WS_MAXIMIZE
,
1164 CW_USEDEFAULT
, CW_USEDEFAULT
,
1165 CW_USEDEFAULT
, CW_USEDEFAULT
,
1166 mdi_client
, 0, GetModuleHandle(0),
1167 (LPVOID
)mdi_lParam_test_message
);
1168 ok(mdi_child
!= 0, "MDI child creation failed\n");
1169 ok(GetWindowLongA(mdi_child
, GWL_ID
) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1170 DestroyWindow(mdi_child
);
1172 trace("Creating maximized child with a caption\n");
1173 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1174 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1175 CW_USEDEFAULT
, CW_USEDEFAULT
,
1176 CW_USEDEFAULT
, CW_USEDEFAULT
,
1177 mdi_client
, 0, GetModuleHandle(0),
1178 (LPVOID
)mdi_lParam_test_message
);
1179 ok(mdi_child
!= 0, "MDI child creation failed\n");
1180 ok(GetWindowLongA(mdi_child
, GWL_ID
) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1181 DestroyWindow(mdi_child
);
1183 trace("Creating maximized child with a caption and a thick frame\n");
1184 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1185 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1186 CW_USEDEFAULT
, CW_USEDEFAULT
,
1187 CW_USEDEFAULT
, CW_USEDEFAULT
,
1188 mdi_client
, 0, GetModuleHandle(0),
1189 (LPVOID
)mdi_lParam_test_message
);
1190 ok(mdi_child
!= 0, "MDI child creation failed\n");
1191 ok(GetWindowLongA(mdi_child
, GWL_ID
) == 0, "wrong child id %ld\n", GetWindowLongA(mdi_child
, GWL_ID
));
1192 DestroyWindow(mdi_child
);
1195 /**********************************************************************
1196 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1198 * Note: The rule here is that client rect of the maximized MDI child
1199 * is equal to the client rect of the MDI client window.
1201 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1205 GetClientRect( client
, &rect
);
1206 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1207 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1209 rect
.right
-= rect
.left
;
1210 rect
.bottom
-= rect
.top
;
1211 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1212 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1214 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1215 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1217 trace("max rect (%ld,%ld - %ld, %ld)\n",
1218 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1221 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1228 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1229 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1231 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1232 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1234 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1235 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1236 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1237 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1238 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1240 /* MDICREATESTRUCT should have original values */
1241 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1242 "mdi_cs->style does not match (%08lx)\n", mdi_cs
->style
);
1243 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1244 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1245 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1246 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1248 /* CREATESTRUCT should have fixed values */
1249 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1250 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1252 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1253 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1254 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1256 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1258 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1260 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1261 ok(cs
->style
== style
,
1262 "cs->style does not match (%08lx)\n", cs
->style
);
1266 LONG style
= mdi_cs
->style
;
1268 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1269 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1270 ok(cs
->style
== style
,
1271 "cs->style does not match (%08lx)\n", cs
->style
);
1276 case WM_GETMINMAXINFO
:
1278 HWND client
= GetParent(hwnd
);
1280 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1281 MINMAXINFO my_minmax
;
1282 LONG style
, exstyle
;
1284 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1285 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1287 GetWindowRect(client
, &rc
);
1288 trace("MDI client %p window size = (%ld x %ld)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1289 GetClientRect(client
, &rc
);
1290 trace("MDI client %p client size = (%ld x %ld)\n", client
, rc
.right
, rc
.bottom
);
1291 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1292 GetSystemMetrics(SM_CYSCREEN
));
1294 GetClientRect(client
, &rc
);
1295 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1296 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1297 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1298 trace("MDI child: calculated max window size = (%ld x %ld)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1300 trace("ptReserved = (%ld,%ld)\n"
1301 "ptMaxSize = (%ld,%ld)\n"
1302 "ptMaxPosition = (%ld,%ld)\n"
1303 "ptMinTrackSize = (%ld,%ld)\n"
1304 "ptMaxTrackSize = (%ld,%ld)\n",
1305 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1306 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1307 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1308 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1309 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1311 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %ld != %ld\n",
1312 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1313 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %ld != %ld\n",
1314 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1316 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1318 trace("DefMDIChildProc returned:\n"
1319 "ptReserved = (%ld,%ld)\n"
1320 "ptMaxSize = (%ld,%ld)\n"
1321 "ptMaxPosition = (%ld,%ld)\n"
1322 "ptMinTrackSize = (%ld,%ld)\n"
1323 "ptMaxTrackSize = (%ld,%ld)\n",
1324 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1325 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1326 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1327 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1328 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1330 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1331 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %ld != %ld\n",
1332 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1333 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %ld != %ld\n",
1334 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1339 case WM_MDIACTIVATE
:
1341 HWND active
, client
= GetParent(hwnd
);
1342 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1343 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1344 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1345 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1347 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1351 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1354 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1361 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1363 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1364 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1366 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1367 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1369 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1370 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1372 /* CREATESTRUCT should have fixed values */
1373 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1375 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1376 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1378 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1379 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1380 while Win95, Win2k, WinXP do. */
1381 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1382 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1386 case WM_GETMINMAXINFO
:
1388 HWND parent
= GetParent(hwnd
);
1390 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1391 LONG style
, exstyle
;
1393 trace("WM_GETMINMAXINFO\n");
1395 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1396 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1398 GetClientRect(parent
, &rc
);
1399 trace("parent %p client size = (%ld x %ld)\n", parent
, rc
.right
, rc
.bottom
);
1401 GetClientRect(parent
, &rc
);
1402 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1403 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1404 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1405 trace("calculated max child window size = (%ld x %ld)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1407 trace("ptReserved = (%ld,%ld)\n"
1408 "ptMaxSize = (%ld,%ld)\n"
1409 "ptMaxPosition = (%ld,%ld)\n"
1410 "ptMinTrackSize = (%ld,%ld)\n"
1411 "ptMaxTrackSize = (%ld,%ld)\n",
1412 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1413 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1414 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1415 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1416 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1418 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %ld != %ld\n",
1419 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1420 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %ld != %ld\n",
1421 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1425 case WM_WINDOWPOSCHANGED
:
1427 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1430 GetWindowRect(hwnd
, &rc1
);
1431 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1432 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1433 /* note: winpos coordinates are relative to parent */
1434 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1435 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1436 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1438 GetWindowRect(hwnd
, &rc1
);
1439 GetClientRect(hwnd
, &rc2
);
1440 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1441 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1442 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1445 case WM_WINDOWPOSCHANGING
:
1447 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1448 WINDOWPOS my_winpos
= *winpos
;
1450 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1451 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1452 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1453 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1455 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1457 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1458 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1459 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1461 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1462 "DefWindowProc should not change WINDOWPOS values\n");
1467 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1470 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1472 static HWND mdi_client
;
1478 CLIENTCREATESTRUCT client_cs
;
1481 GetClientRect(hwnd
, &rc
);
1483 client_cs
.hWindowMenu
= 0;
1484 client_cs
.idFirstChild
= 1;
1486 /* MDIClient without MDIS_ALLCHILDSTYLES */
1487 mdi_client
= CreateWindowExA(0, "mdiclient",
1489 WS_CHILD
/*| WS_VISIBLE*/,
1490 /* tests depend on a not zero MDIClient size */
1491 0, 0, rc
.right
, rc
.bottom
,
1492 hwnd
, 0, GetModuleHandle(0),
1493 (LPVOID
)&client_cs
);
1495 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1496 DestroyWindow(mdi_client
);
1498 /* MDIClient with MDIS_ALLCHILDSTYLES */
1499 mdi_client
= CreateWindowExA(0, "mdiclient",
1501 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1502 /* tests depend on a not zero MDIClient size */
1503 0, 0, rc
.right
, rc
.bottom
,
1504 hwnd
, 0, GetModuleHandle(0),
1505 (LPVOID
)&client_cs
);
1507 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1508 DestroyWindow(mdi_client
);
1512 case WM_WINDOWPOSCHANGED
:
1514 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1517 GetWindowRect(hwnd
, &rc1
);
1518 trace("window: (%ld,%ld)-(%ld,%ld)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1519 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1520 /* note: winpos coordinates are relative to parent */
1521 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1522 trace("pos: (%ld,%ld)-(%ld,%ld)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1523 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1525 GetWindowRect(hwnd
, &rc1
);
1526 GetClientRect(hwnd
, &rc2
);
1527 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1528 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1529 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1532 case WM_WINDOWPOSCHANGING
:
1534 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1535 WINDOWPOS my_winpos
= *winpos
;
1537 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1538 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1539 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1540 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1542 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1544 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1545 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1546 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1548 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1549 "DefWindowProc should not change WINDOWPOS values\n");
1558 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1561 static BOOL
mdi_RegisterWindowClasses(void)
1566 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1569 cls
.hInstance
= GetModuleHandleA(0);
1571 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1572 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1573 cls
.lpszMenuName
= NULL
;
1574 cls
.lpszClassName
= "MDI_parent_Class";
1575 if(!RegisterClassA(&cls
)) return FALSE
;
1577 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1578 cls
.lpszClassName
= "MDI_child_Class_1";
1579 if(!RegisterClassA(&cls
)) return FALSE
;
1581 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1582 cls
.lpszClassName
= "MDI_child_Class_2";
1583 if(!RegisterClassA(&cls
)) return FALSE
;
1588 static void test_mdi(void)
1593 if (!mdi_RegisterWindowClasses()) assert(0);
1595 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1596 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1597 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1598 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1599 GetDesktopWindow(), 0,
1600 GetModuleHandle(0), NULL
);
1601 assert(mdi_hwndMain
);
1603 while(GetMessage(&msg, 0, 0, 0))
1605 TranslateMessage(&msg);
1606 DispatchMessage(&msg);
1611 static void test_icons(void)
1615 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1616 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1617 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1618 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1621 cls
.cbSize
= sizeof(cls
);
1623 cls
.lpfnWndProc
= DefWindowProcA
;
1627 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1628 cls
.hIconSm
= small_icon
;
1629 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1630 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1631 cls
.lpszMenuName
= NULL
;
1632 cls
.lpszClassName
= "IconWindowClass";
1634 RegisterClassExA(&cls
);
1636 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1637 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1640 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1641 ok( res
== 0, "wrong big icon %p/0\n", res
);
1642 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1643 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1644 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1645 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1646 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1647 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1648 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1649 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1651 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1652 ok( res
== 0, "wrong small icon %p/0\n", res
);
1653 /* this test is XP specific */
1654 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1655 ok( res != 0, "wrong small icon %p\n", res );*/
1656 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1657 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1658 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1659 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1660 /* this test is XP specific */
1661 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1662 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1663 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1664 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1665 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1666 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1667 /* this test is XP specific */
1668 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1669 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1671 /* make sure the big icon hasn't changed */
1672 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1673 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1676 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1678 if (msg
== WM_NCCALCSIZE
)
1680 RECT
*rect
= (RECT
*)lparam
;
1681 /* first time around increase the rectangle, next time decrease it */
1682 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1683 else InflateRect( rect
, -10, -10 );
1686 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1689 static void test_SetWindowPos(HWND hwnd
)
1691 RECT orig_win_rc
, rect
;
1693 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1695 SetRect(&rect
, 111, 222, 333, 444);
1696 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1697 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1698 "wrong window rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1700 SetRect(&rect
, 111, 222, 333, 444);
1701 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1702 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1703 "wrong window rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1705 GetWindowRect(hwnd
, &orig_win_rc
);
1707 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1708 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1709 GetWindowRect( hwnd
, &rect
);
1710 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1711 "invalid window rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1712 GetClientRect( hwnd
, &rect
);
1713 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1714 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1715 "invalid client rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1717 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1718 GetWindowRect( hwnd
, &rect
);
1719 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1720 "invalid window rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1721 GetClientRect( hwnd
, &rect
);
1722 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1723 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1724 "invalid client rect %ld,%ld-%ld,%ld\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1726 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1727 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1728 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1730 /* Win9x truncates coordinates to 16-bit irrespectively */
1733 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1734 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1736 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1737 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1740 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1741 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1744 static void test_SetMenu(HWND parent
)
1748 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1751 hMenu
= CreateMenu();
1754 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1755 test_nonclient_area(parent
);
1756 ret
= GetMenu(parent
);
1757 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1758 /* test whether we can destroy a menu assigned to a window */
1759 retok
= DestroyMenu(hMenu
);
1760 ok( retok
, "DestroyMenu error %ld\n", GetLastError());
1761 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1762 ret
= GetMenu(parent
);
1763 /* This test fails on Win9x */
1765 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1766 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1767 test_nonclient_area(parent
);
1769 hMenu
= CreateMenu();
1773 ret
= GetMenu(parent
);
1774 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1776 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1777 test_nonclient_area(parent
);
1778 ret
= GetMenu(parent
);
1779 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1781 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1782 test_nonclient_area(parent
);
1783 ret
= GetMenu(parent
);
1784 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1786 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1787 test_nonclient_area(parent
);
1788 ret
= GetMenu(parent
);
1789 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1792 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1795 ret
= GetMenu(child
);
1796 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1798 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1799 test_nonclient_area(child
);
1800 ret
= GetMenu(child
);
1801 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1803 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1804 test_nonclient_area(child
);
1805 ret
= GetMenu(child
);
1806 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1808 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1809 test_nonclient_area(child
);
1810 ret
= GetMenu(child
);
1811 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1813 DestroyWindow(child
);
1817 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1819 HWND child
[5], hwnd
;
1824 hwnd
= GetWindow(parent
, GW_CHILD
);
1825 ok(!hwnd
, "have to start without children to perform the test\n");
1827 for (i
= 0; i
< total
; i
++)
1829 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1830 parent
, 0, 0, NULL
);
1831 trace("child[%d] = %p\n", i
, child
[i
]);
1832 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1835 hwnd
= GetWindow(parent
, GW_CHILD
);
1836 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1837 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1838 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1840 for (i
= 0; i
< total
; i
++)
1842 trace("hwnd[%d] = %p\n", i
, hwnd
);
1843 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1845 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1848 for (i
= 0; i
< total
; i
++)
1849 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
1852 static void test_children_zorder(HWND parent
)
1854 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
1856 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
1858 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
1859 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
1860 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
1861 const int complex_order_1
[1] = { 0 };
1862 const int complex_order_2
[2] = { 1, 0 };
1863 const int complex_order_3
[3] = { 1, 0, 2 };
1864 const int complex_order_4
[4] = { 1, 0, 2, 3 };
1865 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
1867 /* simple WS_CHILD */
1868 test_window_tree(parent
, simple_style
, simple_order
, 5);
1870 /* complex children styles */
1871 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
1872 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
1873 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
1874 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
1875 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
1878 static void test_SetFocus(HWND hwnd
)
1882 /* check if we can set focus to non-visible windows */
1884 ShowWindow(hwnd
, SW_SHOW
);
1887 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
1888 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
1889 ShowWindow(hwnd
, SW_HIDE
);
1892 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
1893 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
1894 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1897 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
1898 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
1899 ShowWindow(child
, SW_SHOW
);
1900 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
1901 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
1902 ShowWindow(child
, SW_HIDE
);
1903 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
1904 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
1905 ShowWindow(child
, SW_SHOW
);
1907 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
1908 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
1909 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
1911 ShowWindow(child
, SW_HIDE
);
1913 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
1914 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
1915 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
1916 ShowWindow(child
, SW_HIDE
);
1917 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
1919 ShowWindow(hwnd
, SW_SHOW
);
1920 ShowWindow(child
, SW_SHOW
);
1922 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
1923 EnableWindow(hwnd
, FALSE
);
1924 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
1925 EnableWindow(hwnd
, TRUE
);
1927 DestroyWindow( child
);
1930 static void test_SetActiveWindow(HWND hwnd
)
1934 ShowWindow(hwnd
, SW_SHOW
);
1936 SetActiveWindow(hwnd
);
1937 ok( GetActiveWindow() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
1938 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
1939 ok( GetActiveWindow() == hwnd
, "Window %p no longer active\n", hwnd
);
1940 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
1941 ShowWindow(hwnd
, SW_HIDE
);
1942 ok( GetActiveWindow() != hwnd
, "Window %p is still active\n", hwnd
);
1944 /* trace("**testing an invisible window now\n"); */
1945 SetActiveWindow(hwnd
);
1946 ok( GetActiveWindow() == hwnd
, "Window %p not active\n", hwnd
);
1947 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p is visible\n", hwnd
);
1949 ShowWindow(hwnd
, SW_SHOW
);
1951 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1952 ok( GetActiveWindow() == hwnd2
, "Window %p is not active\n", hwnd2
);
1953 DestroyWindow(hwnd2
);
1954 ok( GetActiveWindow() != hwnd2
, "Window %p is still active\n", hwnd2
);
1956 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
1957 ok( GetActiveWindow() == hwnd2
, "Window %p is not active\n", hwnd2
);
1958 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
1959 ok( GetActiveWindow() == hwnd2
, "Window %p no longer active (%p)\n", hwnd2
, GetActiveWindow() );
1960 DestroyWindow(hwnd2
);
1961 ok( GetActiveWindow() != hwnd2
, "Window %p is still active\n", hwnd2
);
1964 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
1966 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
1968 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
1969 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
1970 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
1973 static WNDPROC old_button_proc
;
1975 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1980 key_state
= GetKeyState(VK_LBUTTON
);
1981 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
1983 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
1985 if (msg
== WM_LBUTTONDOWN
)
1989 check_wnd_state(button
, button
, button
, button
);
1991 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
1993 trace("hwnd %p\n", hwnd
);
1995 check_wnd_state(button
, button
, button
, button
);
1997 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
1999 check_wnd_state(button
, button
, button
, button
);
2001 DestroyWindow(hwnd
);
2003 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2005 trace("hwnd %p\n", hwnd
);
2007 check_wnd_state(button
, button
, button
, button
);
2009 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2010 * match internal button state.
2012 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2013 check_wnd_state(button
, button
, button
, 0);
2015 ShowWindow(hwnd
, SW_SHOW
);
2016 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2018 capture
= SetCapture(hwnd
);
2019 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2021 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2023 DestroyWindow(hwnd
);
2025 check_wnd_state(button
, 0, button
, 0);
2031 static void test_capture_1(void)
2033 HWND button
, capture
;
2035 capture
= GetCapture();
2036 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2038 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2040 trace("button %p\n", button
);
2042 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2044 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2046 DestroyWindow(button
);
2049 static void test_capture_2(void)
2051 HWND button
, hwnd
, capture
;
2053 check_wnd_state(0, 0, 0, 0);
2055 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2057 trace("button %p\n", button
);
2059 check_wnd_state(button
, button
, button
, 0);
2061 capture
= SetCapture(button
);
2062 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2064 check_wnd_state(button
, button
, button
, button
);
2066 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2067 * internal button state.
2069 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2070 check_wnd_state(button
, button
, button
, button
);
2072 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2074 trace("hwnd %p\n", hwnd
);
2076 check_wnd_state(button
, button
, button
, button
);
2078 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2080 check_wnd_state(button
, button
, button
, button
);
2082 DestroyWindow(hwnd
);
2084 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2086 trace("hwnd %p\n", hwnd
);
2088 check_wnd_state(button
, button
, button
, button
);
2090 ShowWindow(hwnd
, SW_SHOW
);
2092 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2094 capture
= SetCapture(hwnd
);
2095 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2097 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2099 DestroyWindow(hwnd
);
2100 check_wnd_state(button
, button
, button
, 0);
2102 DestroyWindow(button
);
2103 check_wnd_state(0, 0, 0, 0);
2106 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2108 ShowWindow(hwnd1
, SW_HIDE
);
2109 ShowWindow(hwnd2
, SW_HIDE
);
2111 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2112 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2115 check_wnd_state(0, 0, 0, hwnd1
);
2118 check_wnd_state(0, 0, 0, hwnd2
);
2120 ShowWindow(hwnd1
, SW_SHOW
);
2121 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2126 static void test_keyboard_input(HWND hwnd
)
2131 ShowWindow(hwnd
, SW_SHOW
);
2134 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2137 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2139 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2141 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2142 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2143 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2144 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2145 ok( !ret
, "message %04x available\n", msg
.message
);
2147 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2149 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2150 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2151 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2152 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2153 ok( !ret
, "message %04x available\n", msg
.message
);
2155 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2157 keybd_event(VK_SPACE
, 0, 0, 0);
2158 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2159 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2160 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2161 ok( !ret
, "message %04x available\n", msg
.message
);
2164 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2166 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage(&msg
);
2168 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2169 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2170 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2171 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2172 ok( !ret
, "message %04x available\n", msg
.message
);
2174 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2176 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2177 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2178 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2179 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2180 ok( !ret
, "message %04x available\n", msg
.message
);
2182 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2184 keybd_event(VK_SPACE
, 0, 0, 0);
2185 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2186 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2187 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2188 ok( !ret
, "message %04x available\n", msg
.message
);
2191 static void test_mouse_input(HWND hwnd
)
2200 ShowWindow(hwnd
, SW_SHOW
);
2203 GetWindowRect(hwnd
, &rc
);
2204 trace("main window %p: (%ld,%ld)-(%ld,%ld)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2206 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2207 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2210 ShowWindow(popup
, SW_SHOW
);
2211 UpdateWindow(popup
);
2213 GetWindowRect(popup
, &rc
);
2214 trace("popup window %p: (%ld,%ld)-(%ld,%ld)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2216 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2217 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2218 trace("setting cursor to (%d,%d)\n", x
, y
);
2222 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%ld,%ld), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2224 /* force the system to update its internal queue mouse position,
2225 * otherwise it won't generate relative mouse movements below.
2227 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2228 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2231 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2232 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2233 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2234 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2235 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2236 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2237 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2238 ok( !ret
, "message %04x available\n", msg
.message
);
2240 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2241 ShowWindow(popup
, SW_HIDE
);
2242 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2243 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2244 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2246 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2247 ShowWindow(hwnd
, SW_HIDE
);
2248 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2249 ok( !ret
, "message %04x available\n", msg
.message
);
2251 /* test mouse clicks */
2253 ShowWindow(hwnd
, SW_SHOW
);
2254 ShowWindow(popup
, SW_SHOW
);
2256 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2258 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2259 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2260 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2261 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2263 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2264 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2265 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2266 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2267 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2268 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2269 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2270 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2272 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2273 ok(!ret
, "message %04x available\n", msg
.message
);
2275 ShowWindow(popup
, SW_HIDE
);
2276 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA(&msg
);
2278 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2279 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2280 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2281 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2283 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2284 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2285 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2286 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2288 test_lbuttondown_flag
= TRUE
;
2289 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2290 test_lbuttondown_flag
= FALSE
;
2292 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2293 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2294 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2295 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2296 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2298 DestroyWindow(popup
);
2301 static void test_validatergn(HWND hwnd
)
2307 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2308 ShowWindow(hwnd
, SW_SHOW
);
2309 UpdateWindow( hwnd
);
2310 /* test that ValidateRect validates children*/
2311 InvalidateRect( child
, NULL
, 1);
2312 GetWindowRect( child
, &rc
);
2313 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2314 ret
= GetUpdateRect( child
, &rc2
, 0);
2315 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2316 "Update rectangle is empty!\n");
2317 ValidateRect( hwnd
, &rc
);
2318 ret
= GetUpdateRect( child
, &rc2
, 0);
2319 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2320 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2
.left
, rc2
.top
,
2321 rc2
.right
, rc2
.bottom
);
2323 /* now test ValidateRgn */
2324 InvalidateRect( child
, NULL
, 1);
2325 GetWindowRect( child
, &rc
);
2326 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2327 rgn
= CreateRectRgnIndirect( &rc
);
2328 ValidateRgn( hwnd
, rgn
);
2329 ret
= GetUpdateRect( child
, &rc2
, 0);
2330 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2331 "Update rectangle %ld,%ld-%ld,%ld is not empty!\n", rc2
.left
, rc2
.top
,
2332 rc2
.right
, rc2
.bottom
);
2335 DestroyWindow( child
);
2338 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2340 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2341 GetWindowRect( hwnd
, prc
);
2342 trace("window rect is %ld,%ld - %ld,%ld\n",
2343 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2344 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2345 trace("nccalc rect is %ld,%ld - %ld,%ld\n",
2346 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2349 static void test_nccalcscroll(HWND parent
)
2352 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2353 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2354 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2355 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2356 10, 10, 200, 200, parent
, 0, 0, NULL
);
2357 ShowWindow( parent
, SW_SHOW
);
2358 UpdateWindow( parent
);
2360 /* test window too low for a horizontal scroll bar */
2361 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2362 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2363 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2365 /* test window just high enough for a horizontal scroll bar */
2366 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2367 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %ld,%ld - %ld,%ld\n",
2368 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2370 /* test window too narrow for a vertical scroll bar */
2371 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2372 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %ld,%ld - %ld,%ld\n",
2373 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2375 /* test window just wide enough for a vertical scroll bar */
2376 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2377 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %ld,%ld - %ld,%ld\n",
2378 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2380 /* same test, but with client edge: not enough width */
2381 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2382 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2383 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2384 "Width should be %d size is %ld,%ld - %ld,%ld\n",
2385 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2387 DestroyWindow( hwnd
);
2390 static void test_SetParent(void)
2392 HWND desktop
= GetDesktopWindow();
2393 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2394 HWND parent
, child1
, child2
, child3
, child4
;
2396 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2397 100, 100, 200, 200, 0, 0, 0, NULL
);
2398 assert(parent
!= 0);
2399 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2400 0, 0, 50, 50, parent
, 0, 0, NULL
);
2401 assert(child1
!= 0);
2402 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2403 0, 0, 50, 50, child1
, 0, 0, NULL
);
2404 assert(child2
!= 0);
2405 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2406 0, 0, 50, 50, child2
, 0, 0, NULL
);
2407 assert(child3
!= 0);
2408 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2409 0, 0, 50, 50, child3
, 0, 0, NULL
);
2410 assert(child4
!= 0);
2412 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2413 parent
, child1
, child2
, child3
, child4
);
2415 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2416 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2417 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2418 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2419 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2422 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2423 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2424 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2425 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2426 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2429 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2431 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2433 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2434 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2435 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2436 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2437 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2438 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2440 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2443 if (!is_win9x
) /* Win9x doesn't survive this test */
2445 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2446 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2447 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2448 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2449 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2450 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2451 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2453 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2454 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2455 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2456 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2457 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2460 ok(DestroyWindow(parent
), "DestroyWindow() error %ld\n", GetLastError());
2462 ok(!IsWindow(parent
), "parent still exists\n");
2463 ok(!IsWindow(child1
), "child1 still exists\n");
2464 ok(!IsWindow(child2
), "child2 still exists\n");
2465 ok(!IsWindow(child3
), "child3 still exists\n");
2466 ok(!IsWindow(child4
), "child4 still exists\n");
2471 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
2472 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
2474 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
2477 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
2480 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
2481 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
2482 trace("hwndMessage %p\n", hwndMessage
);
2484 DestroyWindow(hwndMain
);
2487 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
2489 if (!RegisterWindowClasses()) assert(0);
2491 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
2494 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
2495 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2496 WS_MAXIMIZEBOX
| WS_POPUP
,
2499 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
2500 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
2501 WS_MAXIMIZEBOX
| WS_POPUP
,
2505 assert( hwndMain2
);
2509 test_capture_3(hwndMain
, hwndMain2
);
2511 test_parent_owner();
2513 test_shell_window();
2517 test_SetWindowPos(hwndMain
);
2518 test_SetMenu(hwndMain
);
2519 test_SetFocus(hwndMain
);
2520 test_SetActiveWindow(hwndMain
);
2522 test_children_zorder(hwndMain
);
2523 test_keyboard_input(hwndMain
);
2524 test_mouse_input(hwndMain
);
2525 test_validatergn(hwndMain
);
2526 test_nccalcscroll( hwndMain
);
2528 UnhookWindowsHookEx(hhook
);