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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* To get ICON_SMALL2 with the MSVC headers */
24 #define _WIN32_WINNT 0x0501
36 #include "wine/test.h"
38 #ifndef SPI_GETDESKWALLPAPER
39 #define SPI_GETDESKWALLPAPER 0x0073
42 #define LONG_PTR INT_PTR
43 #define ULONG_PTR UINT_PTR
45 void dump_region(HRGN hrgn
);
47 static HWND (WINAPI
*pGetAncestor
)(HWND
,UINT
);
48 static BOOL (WINAPI
*pGetWindowInfo
)(HWND
,WINDOWINFO
*);
49 static UINT (WINAPI
*pGetWindowModuleFileNameA
)(HWND
,LPSTR
,UINT
);
50 static BOOL (WINAPI
*pGetLayeredWindowAttributes
)(HWND
,COLORREF
*,BYTE
*,DWORD
*);
51 static BOOL (WINAPI
*pSetLayeredWindowAttributes
)(HWND
,COLORREF
,BYTE
,DWORD
);
53 static BOOL test_lbuttondown_flag
;
54 static HWND hwndMessage
;
55 static HWND hwndMain
, hwndMain2
;
58 static const char* szAWRClass
= "Winsize";
62 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
64 static void dump_minmax_info( const MINMAXINFO
*minmax
)
66 trace("Reserved=%d,%d MaxSize=%d,%d MaxPos=%d,%d MinTrack=%d,%d MaxTrack=%d,%d\n",
67 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
68 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
69 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
70 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
71 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
74 /* try to make sure pending X events have been processed before continuing */
75 static void flush_events( BOOL remove_messages
)
80 DWORD time
= GetTickCount() + diff
;
84 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
86 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
87 diff
= time
- GetTickCount();
92 /* check the values returned by the various parent/owner functions on a given window */
93 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
94 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
100 res
= pGetAncestor( hwnd
, GA_PARENT
);
101 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
103 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
104 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
105 res
= GetParent( hwnd
);
106 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
107 res
= GetWindow( hwnd
, GW_OWNER
);
108 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
111 res
= pGetAncestor( hwnd
, GA_ROOT
);
112 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
113 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
114 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
118 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
121 trace("EnumChildProc on %p\n", hwndChild
);
122 if (*(LPINT
)lParam
> 1) return FALSE
;
126 /* will search for the given window */
127 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
129 trace("EnumChildProc1 on %p\n", hwndChild
);
130 if ((HWND
)lParam
== hwndChild
) return FALSE
;
134 static HWND
create_tool_window( LONG style
, HWND parent
)
136 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
137 0, 0, 100, 100, parent
, 0, 0, NULL
);
138 ok( ret
!= 0, "Creation failed\n" );
142 /* test parent and owner values for various combinations */
143 static void test_parent_owner(void)
146 HWND test
, owner
, ret
;
147 HWND desktop
= GetDesktopWindow();
148 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
151 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
153 /* child without parent, should fail */
154 SetLastError(0xdeadbeef);
155 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
156 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
157 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
158 ok( !test
, "WS_CHILD without parent created\n" );
161 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
162 style
= GetWindowLongA( desktop
, GWL_STYLE
);
163 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
164 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
165 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
167 /* normal child window */
168 test
= create_tool_window( WS_CHILD
, hwndMain
);
169 trace( "created child %p\n", test
);
170 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
171 SetWindowLongA( test
, GWL_STYLE
, 0 );
172 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
173 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
174 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
175 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
176 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
177 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
178 DestroyWindow( test
);
180 /* normal child window with WS_MAXIMIZE */
181 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
182 DestroyWindow( test
);
184 /* normal child window with WS_THICKFRAME */
185 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
186 DestroyWindow( test
);
188 /* popup window with WS_THICKFRAME */
189 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
190 DestroyWindow( test
);
192 /* child of desktop */
193 test
= create_tool_window( WS_CHILD
, desktop
);
194 trace( "created child of desktop %p\n", test
);
195 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
196 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
197 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
198 SetWindowLongA( test
, GWL_STYLE
, 0 );
199 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
200 DestroyWindow( test
);
202 /* child of desktop with WS_MAXIMIZE */
203 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
204 DestroyWindow( test
);
206 /* child of desktop with WS_MINIMIZE */
207 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
208 DestroyWindow( test
);
211 test
= create_tool_window( WS_CHILD
, child
);
212 trace( "created child of child %p\n", test
);
213 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
214 SetWindowLongA( test
, GWL_STYLE
, 0 );
215 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
216 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
217 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
218 DestroyWindow( test
);
220 /* child of child with WS_MAXIMIZE */
221 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
222 DestroyWindow( test
);
224 /* child of child with WS_MINIMIZE */
225 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
226 DestroyWindow( test
);
228 /* not owned top-level window */
229 test
= create_tool_window( 0, 0 );
230 trace( "created top-level %p\n", test
);
231 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
232 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
233 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
234 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
235 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
236 DestroyWindow( test
);
238 /* not owned top-level window with WS_MAXIMIZE */
239 test
= create_tool_window( WS_MAXIMIZE
, 0 );
240 DestroyWindow( test
);
242 /* owned top-level window */
243 test
= create_tool_window( 0, hwndMain
);
244 trace( "created owned top-level %p\n", test
);
245 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
246 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
247 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
248 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
249 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
250 DestroyWindow( test
);
252 /* owned top-level window with WS_MAXIMIZE */
253 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
254 DestroyWindow( test
);
256 /* not owned popup */
257 test
= create_tool_window( WS_POPUP
, 0 );
258 trace( "created popup %p\n", test
);
259 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
260 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
261 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
262 SetWindowLongA( test
, GWL_STYLE
, 0 );
263 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
264 DestroyWindow( test
);
266 /* not owned popup with WS_MAXIMIZE */
267 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
268 DestroyWindow( test
);
271 test
= create_tool_window( WS_POPUP
, hwndMain
);
272 trace( "created owned popup %p\n", test
);
273 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
274 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
275 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
276 SetWindowLongA( test
, GWL_STYLE
, 0 );
277 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
278 DestroyWindow( test
);
280 /* owned popup with WS_MAXIMIZE */
281 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
282 DestroyWindow( test
);
284 /* top-level window owned by child (same as owned by top-level) */
285 test
= create_tool_window( 0, child
);
286 trace( "created top-level owned by child %p\n", test
);
287 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
288 DestroyWindow( test
);
290 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
291 test
= create_tool_window( WS_MAXIMIZE
, child
);
292 DestroyWindow( test
);
294 /* popup owned by desktop (same as not owned) */
295 test
= create_tool_window( WS_POPUP
, desktop
);
296 trace( "created popup owned by desktop %p\n", test
);
297 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
298 DestroyWindow( test
);
300 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
301 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
302 DestroyWindow( test
);
304 /* popup owned by child (same as owned by top-level) */
305 test
= create_tool_window( WS_POPUP
, child
);
306 trace( "created popup owned by child %p\n", test
);
307 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
308 DestroyWindow( test
);
310 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
311 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
312 DestroyWindow( test
);
314 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
315 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
316 trace( "created WS_CHILD popup %p\n", test
);
317 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
318 DestroyWindow( test
);
320 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
321 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
322 DestroyWindow( test
);
324 /* owned popup with WS_CHILD (same as WS_POPUP only) */
325 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
326 trace( "created owned WS_CHILD popup %p\n", test
);
327 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
328 DestroyWindow( test
);
330 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
331 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
332 DestroyWindow( test
);
334 /******************** parent changes *************************/
335 trace( "testing parent changes\n" );
338 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
341 /* this test succeeds on NT but crashes on win9x systems */
342 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
343 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
344 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
345 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
346 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
348 /* normal child window */
349 test
= create_tool_window( WS_CHILD
, hwndMain
);
350 trace( "created child %p\n", test
);
352 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
353 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
354 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
356 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
357 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
358 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
360 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
361 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
362 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
364 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
365 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
366 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
367 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
369 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
370 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
371 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
372 DestroyWindow( test
);
374 /* not owned top-level window */
375 test
= create_tool_window( 0, 0 );
376 trace( "created top-level %p\n", test
);
378 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
379 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
380 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
382 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
383 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
384 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
386 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
387 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
388 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
389 DestroyWindow( test
);
391 /* not owned popup */
392 test
= create_tool_window( WS_POPUP
, 0 );
393 trace( "created popup %p\n", test
);
395 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
396 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
397 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
399 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
400 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
401 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
403 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
404 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
405 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
406 DestroyWindow( test
);
408 /* normal child window */
409 test
= create_tool_window( WS_CHILD
, hwndMain
);
410 trace( "created child %p\n", test
);
412 ret
= SetParent( test
, desktop
);
413 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
414 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
416 ret
= SetParent( test
, child
);
417 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
418 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
420 ret
= SetParent( test
, hwndMain2
);
421 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
422 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
423 DestroyWindow( test
);
425 /* not owned top-level window */
426 test
= create_tool_window( 0, 0 );
427 trace( "created top-level %p\n", test
);
429 ret
= SetParent( test
, child
);
430 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
431 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
432 DestroyWindow( test
);
435 test
= create_tool_window( WS_POPUP
, hwndMain2
);
436 trace( "created owned popup %p\n", test
);
438 ret
= SetParent( test
, child
);
439 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
440 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
442 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
443 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
444 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
445 DestroyWindow( test
);
447 /**************** test owner destruction *******************/
449 /* owned child popup */
450 owner
= create_tool_window( 0, 0 );
451 test
= create_tool_window( WS_POPUP
, owner
);
452 trace( "created owner %p and popup %p\n", owner
, test
);
453 ret
= SetParent( test
, child
);
454 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
455 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
456 /* window is now child of 'child' but owned by 'owner' */
457 DestroyWindow( owner
);
458 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
459 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
460 * while Win95, Win2k, WinXP do.
462 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
463 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
466 /* owned top-level popup */
467 owner
= create_tool_window( 0, 0 );
468 test
= create_tool_window( WS_POPUP
, owner
);
469 trace( "created owner %p and popup %p\n", owner
, test
);
470 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
471 DestroyWindow( owner
);
472 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
474 /* top-level popup owned by child */
475 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
476 test
= create_tool_window( WS_POPUP
, 0 );
477 trace( "created owner %p and popup %p\n", owner
, test
);
478 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
479 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
480 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
481 DestroyWindow( owner
);
482 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
483 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
484 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
485 * while Win95, Win2k, WinXP do.
487 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
491 DestroyWindow(child
);
494 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
495 test
= create_tool_window( WS_POPUP
, desktop
);
497 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
499 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
500 "EnumChildWindows should have returned FALSE\n" );
501 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
503 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
504 ret
= SetParent( test
, owner
);
505 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
508 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
509 "EnumChildWindows should have returned TRUE\n" );
510 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
512 child
= create_tool_window( WS_CHILD
, owner
);
514 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
515 "EnumChildWindows should have returned FALSE\n" );
516 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
517 DestroyWindow( child
);
519 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
520 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
522 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
523 "EnumChildWindows should have returned TRUE\n" );
524 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
526 ret
= SetParent( child
, owner
);
527 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
528 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
530 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
531 "EnumChildWindows should have returned FALSE\n" );
532 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
534 ret
= SetParent( child
, NULL
);
535 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
536 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
538 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
539 "EnumChildWindows should have returned TRUE\n" );
540 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
542 /* even GW_OWNER == owner it's still a desktop's child */
543 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
544 "EnumChildWindows should have found %p and returned FALSE\n", child
);
546 DestroyWindow( child
);
547 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
549 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
550 "EnumChildWindows should have found %p and returned FALSE\n", child
);
552 DestroyWindow( child
);
553 DestroyWindow( test
);
554 DestroyWindow( owner
);
558 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
562 case WM_GETMINMAXINFO
:
564 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
566 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
567 dump_minmax_info( minmax
);
568 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
571 case WM_WINDOWPOSCHANGING
:
573 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
574 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
575 trace("main: WM_WINDOWPOSCHANGING\n");
576 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
577 winpos
->hwnd
, winpos
->hwndInsertAfter
,
578 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
579 if (!(winpos
->flags
& SWP_NOMOVE
))
581 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
582 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
584 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
585 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
587 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
588 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
592 case WM_WINDOWPOSCHANGED
:
595 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
596 trace("main: WM_WINDOWPOSCHANGED\n");
597 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
598 winpos
->hwnd
, winpos
->hwndInsertAfter
,
599 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
600 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
601 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
603 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
604 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
606 GetWindowRect(hwnd
, &rc1
);
607 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
608 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
609 /* note: winpos coordinates are relative to parent */
610 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
611 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
614 /* Uncomment this once the test succeeds in all cases */
615 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
618 GetClientRect(hwnd
, &rc2
);
619 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
620 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
621 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
622 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
627 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
628 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
630 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
631 if (got_getminmaxinfo
)
632 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
634 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
635 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
637 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
641 if (test_lbuttondown_flag
)
643 ShowWindow((HWND
)wparam
, SW_SHOW
);
644 flush_events( FALSE
);
649 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
652 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
656 case WM_GETMINMAXINFO
:
658 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
660 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
661 dump_minmax_info( minmax
);
662 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
667 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
668 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
670 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
671 if (got_getminmaxinfo
)
672 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
674 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
675 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
677 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
682 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
685 static BOOL
RegisterWindowClasses(void)
689 cls
.style
= CS_DBLCLKS
;
690 cls
.lpfnWndProc
= main_window_procA
;
693 cls
.hInstance
= GetModuleHandleA(0);
695 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
696 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
697 cls
.lpszMenuName
= NULL
;
698 cls
.lpszClassName
= "MainWindowClass";
700 if(!RegisterClassA(&cls
)) return FALSE
;
703 cls
.lpfnWndProc
= tool_window_procA
;
706 cls
.hInstance
= GetModuleHandleA(0);
708 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
709 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
710 cls
.lpszMenuName
= NULL
;
711 cls
.lpszClassName
= "ToolWindowClass";
713 if(!RegisterClassA(&cls
)) return FALSE
;
718 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
720 RECT rcWindow
, rcClient
;
723 ok(IsWindow(hwnd
), "bad window handle\n");
725 GetWindowRect(hwnd
, &rcWindow
);
726 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
728 GetClientRect(hwnd
, &rcClient
);
729 /* translate to screen coordinates */
730 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
731 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
733 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
734 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
735 /* Windows reports some undocumented exstyles in WINDOWINFO, but
736 * doesn't return them in GetWindowLong(hwnd, GWL_EXSTYLE).
738 ok((info
->dwExStyle
& ~0xe0000800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
739 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
740 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
741 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
742 info
->dwWindowStatus
, status
);
744 /* win2k and XP return broken border info in GetWindowInfo most of
745 * the time, so there is no point in testing it.
749 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
750 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
751 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
752 ok(info
->cyWindowBorders
== border
,
753 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
755 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
756 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
757 info
->wCreatorVersion
== 0x0500 /* Vista */,
758 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
761 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
763 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
764 /* AdjustWindowRectEx does not include scroll bars */
765 if (style
& WS_VSCROLL
)
767 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
768 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
770 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
772 if (style
& WS_HSCROLL
)
773 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
776 static void test_nonclient_area(HWND hwnd
)
778 DWORD style
, exstyle
;
779 RECT rc_window
, rc_client
, rc
;
781 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
783 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
784 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
785 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
787 GetWindowRect(hwnd
, &rc_window
);
788 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
789 GetClientRect(hwnd
, &rc_client
);
790 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
792 /* avoid some cases when things go wrong */
793 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
794 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
796 CopyRect(&rc
, &rc_client
);
797 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
798 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
800 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
801 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
804 CopyRect(&rc
, &rc_window
);
805 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
806 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
807 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
808 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
810 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
814 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
815 SetRect(&rc_client
, 0, 0, 250, 150);
816 CopyRect(&rc_window
, &rc_client
);
817 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
818 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
819 trace("calc window: (%d,%d)-(%d,%d)\n",
820 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
822 CopyRect(&rc
, &rc_window
);
823 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
824 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
825 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
826 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
829 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
831 static const char *CBT_code_name
[10] = {
842 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
844 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
846 /* on HCBT_DESTROYWND window state is undefined */
847 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
853 /* Win98 actually does check the info.cbSize and doesn't allow
854 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
855 * WinXP do not check it at all.
857 info
.cbSize
= sizeof(WINDOWINFO
);
858 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
859 verify_window_info((HWND
)wParam
, &info
);
867 static const RECT rc_null
;
870 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
871 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
872 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
873 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
875 /* WS_VISIBLE should be turned off yet */
876 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
877 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
878 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
879 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
883 /* Uncomment this once the test succeeds in all cases */
884 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
886 ok(GetParent((HWND
)wParam
) == hwndMessage
,
887 "wrong result from GetParent %p: message window %p\n",
888 GetParent((HWND
)wParam
), hwndMessage
);
891 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
893 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
897 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
898 * Win9x still has them set to 0.
900 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
901 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
903 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
904 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
908 /* Uncomment this once the test succeeds in all cases */
911 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
912 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
913 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
915 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
916 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
917 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
919 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
920 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
923 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
924 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
925 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
926 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
932 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
935 static void test_shell_window(void)
939 HMODULE hinst
, hUser32
;
940 BOOL (WINAPI
*SetShellWindow
)(HWND
);
941 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
942 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
943 HWND shellWindow
, nextWnd
;
945 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
947 trace("Skipping shell window test on Win9x\n");
951 shellWindow
= GetShellWindow();
952 hinst
= GetModuleHandle(0);
953 hUser32
= GetModuleHandleA("user32");
955 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
956 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
958 trace("previous shell window: %p\n", shellWindow
);
964 ret
= DestroyWindow(shellWindow
);
965 error
= GetLastError();
967 ok(!ret
, "DestroyWindow(shellWindow)\n");
968 /* passes on Win XP, but not on Win98 */
969 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
971 /* close old shell instance */
972 GetWindowThreadProcessId(shellWindow
, &pid
);
973 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
974 ret
= TerminateProcess(hProcess
, 0);
975 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
976 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
977 CloseHandle(hProcess
);
980 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
981 trace("created window 1: %p\n", hwnd1
);
983 ret
= SetShellWindow(hwnd1
);
984 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
985 shellWindow
= GetShellWindow();
986 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
988 ret
= SetShellWindow(hwnd1
);
989 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
991 ret
= SetShellWindow(0);
992 error
= GetLastError();
993 /* passes on Win XP, but not on Win98
994 ok(!ret, "reset shell window by SetShellWindow(0)\n");
995 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
997 ret
= SetShellWindow(hwnd1
);
998 /* passes on Win XP, but not on Win98
999 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1001 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1002 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1003 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1005 ret
= DestroyWindow(hwnd1
);
1006 ok(ret
, "DestroyWindow(hwnd1)\n");
1008 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1009 trace("created window 2: %p\n", hwnd2
);
1010 ret
= SetShellWindow(hwnd2
);
1011 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1013 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1014 trace("created window 3: %p\n", hwnd3
);
1016 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1017 trace("created window 4: %p\n", hwnd4
);
1019 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1020 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1022 ret
= SetShellWindow(hwnd4
);
1023 ok(ret
, "SetShellWindow(hwnd4)\n");
1024 shellWindow
= GetShellWindow();
1025 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1027 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1028 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1030 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1031 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1033 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1034 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1036 ret
= SetShellWindow(hwnd3
);
1037 ok(!ret
, "SetShellWindow(hwnd3)\n");
1038 shellWindow
= GetShellWindow();
1039 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1041 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1042 trace("created window 5: %p\n", hwnd5
);
1043 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1044 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1048 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1049 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1052 /* destroy test windows */
1053 DestroyWindow(hwnd2
);
1054 DestroyWindow(hwnd3
);
1055 DestroyWindow(hwnd4
);
1056 DestroyWindow(hwnd5
);
1059 /************** MDI test ****************/
1061 static char mdi_lParam_test_message
[] = "just a test string";
1063 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1065 MDICREATESTRUCTA mdi_cs
;
1067 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1068 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1069 BOOL isWin9x
= FALSE
;
1071 mdi_cs
.szClass
= "MDI_child_Class_1";
1072 mdi_cs
.szTitle
= "MDI child";
1073 mdi_cs
.hOwner
= GetModuleHandle(0);
1074 mdi_cs
.x
= CW_USEDEFAULT
;
1075 mdi_cs
.y
= CW_USEDEFAULT
;
1076 mdi_cs
.cx
= CW_USEDEFAULT
;
1077 mdi_cs
.cy
= CW_USEDEFAULT
;
1079 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1080 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1081 ok(mdi_child
!= 0, "MDI child creation failed\n");
1082 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1083 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1084 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1086 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1087 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1088 ok(mdi_child
!= 0, "MDI child creation failed\n");
1089 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1090 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1091 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1093 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1094 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
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(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_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 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1110 mdi_cs
.szClass
= (LPCSTR
)classW
;
1111 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1112 SetLastError(0xdeadbeef);
1113 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1116 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1119 ok(mdi_child
!= 0, "MDI child creation failed\n");
1123 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1124 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1125 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1128 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1130 CW_USEDEFAULT
, CW_USEDEFAULT
,
1131 CW_USEDEFAULT
, CW_USEDEFAULT
,
1132 mdi_client
, GetModuleHandle(0),
1133 (LPARAM
)mdi_lParam_test_message
);
1134 ok(mdi_child
!= 0, "MDI child creation failed\n");
1135 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1136 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1137 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1139 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1140 0x7fffffff, /* without WS_POPUP */
1141 CW_USEDEFAULT
, CW_USEDEFAULT
,
1142 CW_USEDEFAULT
, CW_USEDEFAULT
,
1143 mdi_client
, GetModuleHandle(0),
1144 (LPARAM
)mdi_lParam_test_message
);
1145 ok(mdi_child
!= 0, "MDI child creation failed\n");
1146 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1147 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1148 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1150 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1151 0xffffffff, /* with WS_POPUP */
1152 CW_USEDEFAULT
, CW_USEDEFAULT
,
1153 CW_USEDEFAULT
, CW_USEDEFAULT
,
1154 mdi_client
, GetModuleHandle(0),
1155 (LPARAM
)mdi_lParam_test_message
);
1156 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1158 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1162 ok(mdi_child
!= 0, "MDI child creation failed\n");
1163 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1164 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1165 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1168 /* test MDICREATESTRUCT A<->W mapping */
1169 SetLastError(0xdeadbeef);
1170 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1172 CW_USEDEFAULT
, CW_USEDEFAULT
,
1173 CW_USEDEFAULT
, CW_USEDEFAULT
,
1174 mdi_client
, GetModuleHandle(0),
1175 (LPARAM
)mdi_lParam_test_message
);
1178 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1181 ok(mdi_child
!= 0, "MDI child creation failed\n");
1185 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1186 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1187 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1190 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1192 CW_USEDEFAULT
, CW_USEDEFAULT
,
1193 CW_USEDEFAULT
, CW_USEDEFAULT
,
1194 mdi_client
, 0, GetModuleHandle(0),
1195 (LPVOID
)mdi_lParam_test_message
);
1196 ok(mdi_child
!= 0, "MDI child creation failed\n");
1197 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1198 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1199 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1201 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1202 0x7fffffff, /* without WS_POPUP */
1203 CW_USEDEFAULT
, CW_USEDEFAULT
,
1204 CW_USEDEFAULT
, CW_USEDEFAULT
,
1205 mdi_client
, 0, GetModuleHandle(0),
1206 (LPVOID
)mdi_lParam_test_message
);
1207 ok(mdi_child
!= 0, "MDI child creation failed\n");
1208 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1209 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1210 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1212 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1213 0xffffffff, /* with WS_POPUP */
1214 CW_USEDEFAULT
, CW_USEDEFAULT
,
1215 CW_USEDEFAULT
, CW_USEDEFAULT
,
1216 mdi_client
, 0, GetModuleHandle(0),
1217 (LPVOID
)mdi_lParam_test_message
);
1218 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1220 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1224 ok(mdi_child
!= 0, "MDI child creation failed\n");
1225 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1226 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1227 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1230 /* test MDICREATESTRUCT A<->W mapping */
1231 SetLastError(0xdeadbeef);
1232 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1234 CW_USEDEFAULT
, CW_USEDEFAULT
,
1235 CW_USEDEFAULT
, CW_USEDEFAULT
,
1236 mdi_client
, 0, GetModuleHandle(0),
1237 (LPVOID
)mdi_lParam_test_message
);
1240 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1243 ok(mdi_child
!= 0, "MDI child creation failed\n");
1247 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1248 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1249 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1252 /* This test fails on Win9x */
1255 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1257 CW_USEDEFAULT
, CW_USEDEFAULT
,
1258 CW_USEDEFAULT
, CW_USEDEFAULT
,
1259 parent
, 0, GetModuleHandle(0),
1260 (LPVOID
)mdi_lParam_test_message
);
1261 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1264 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1265 WS_CHILD
, /* without WS_POPUP */
1266 CW_USEDEFAULT
, CW_USEDEFAULT
,
1267 CW_USEDEFAULT
, CW_USEDEFAULT
,
1268 mdi_client
, 0, GetModuleHandle(0),
1269 (LPVOID
)mdi_lParam_test_message
);
1270 ok(mdi_child
!= 0, "MDI child creation failed\n");
1271 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1272 DestroyWindow(mdi_child
);
1274 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1275 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1276 CW_USEDEFAULT
, CW_USEDEFAULT
,
1277 CW_USEDEFAULT
, CW_USEDEFAULT
,
1278 mdi_client
, 0, GetModuleHandle(0),
1279 (LPVOID
)mdi_lParam_test_message
);
1280 ok(mdi_child
!= 0, "MDI child creation failed\n");
1281 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1282 DestroyWindow(mdi_child
);
1284 /* maximized child */
1285 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1286 WS_CHILD
| WS_MAXIMIZE
,
1287 CW_USEDEFAULT
, CW_USEDEFAULT
,
1288 CW_USEDEFAULT
, CW_USEDEFAULT
,
1289 mdi_client
, 0, GetModuleHandle(0),
1290 (LPVOID
)mdi_lParam_test_message
);
1291 ok(mdi_child
!= 0, "MDI child creation failed\n");
1292 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1293 DestroyWindow(mdi_child
);
1295 trace("Creating maximized child with a caption\n");
1296 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1297 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1298 CW_USEDEFAULT
, CW_USEDEFAULT
,
1299 CW_USEDEFAULT
, CW_USEDEFAULT
,
1300 mdi_client
, 0, GetModuleHandle(0),
1301 (LPVOID
)mdi_lParam_test_message
);
1302 ok(mdi_child
!= 0, "MDI child creation failed\n");
1303 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1304 DestroyWindow(mdi_child
);
1306 trace("Creating maximized child with a caption and a thick frame\n");
1307 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1308 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1309 CW_USEDEFAULT
, CW_USEDEFAULT
,
1310 CW_USEDEFAULT
, CW_USEDEFAULT
,
1311 mdi_client
, 0, GetModuleHandle(0),
1312 (LPVOID
)mdi_lParam_test_message
);
1313 ok(mdi_child
!= 0, "MDI child creation failed\n");
1314 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1315 DestroyWindow(mdi_child
);
1318 /**********************************************************************
1319 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1321 * Note: The rule here is that client rect of the maximized MDI child
1322 * is equal to the client rect of the MDI client window.
1324 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1328 GetClientRect( client
, &rect
);
1329 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1330 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1332 rect
.right
-= rect
.left
;
1333 rect
.bottom
-= rect
.top
;
1334 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1335 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1337 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1338 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1340 trace("max rect (%d,%d - %d, %d)\n",
1341 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1344 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1351 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1352 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1354 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1355 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1357 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1358 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1359 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1360 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1361 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1363 /* MDICREATESTRUCT should have original values */
1364 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1365 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1366 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1367 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1368 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1369 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1371 /* CREATESTRUCT should have fixed values */
1372 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1373 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1375 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1376 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1377 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1379 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1381 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1383 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1384 ok(cs
->style
== style
,
1385 "cs->style does not match (%08x)\n", cs
->style
);
1389 LONG style
= mdi_cs
->style
;
1391 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1392 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1393 ok(cs
->style
== style
,
1394 "cs->style does not match (%08x)\n", cs
->style
);
1399 case WM_GETMINMAXINFO
:
1401 HWND client
= GetParent(hwnd
);
1403 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1404 MINMAXINFO my_minmax
;
1405 LONG style
, exstyle
;
1407 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1408 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1410 GetWindowRect(client
, &rc
);
1411 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1412 GetClientRect(client
, &rc
);
1413 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1414 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1415 GetSystemMetrics(SM_CYSCREEN
));
1417 GetClientRect(client
, &rc
);
1418 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1419 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1420 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1421 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1422 dump_minmax_info( minmax
);
1424 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1425 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1426 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1427 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1429 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1431 trace("DefMDIChildProc returned:\n");
1432 dump_minmax_info( minmax
);
1434 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1435 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1436 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1437 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1438 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1443 case WM_MDIACTIVATE
:
1445 HWND active
, client
= GetParent(hwnd
);
1446 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1447 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1448 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1449 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1451 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1455 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1458 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1465 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1467 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1468 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1470 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1471 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1473 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1474 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1476 /* CREATESTRUCT should have fixed values */
1477 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1479 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1480 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1482 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1483 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1484 while Win95, Win2k, WinXP do. */
1485 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1486 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1490 case WM_GETMINMAXINFO
:
1492 HWND parent
= GetParent(hwnd
);
1494 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1495 LONG style
, exstyle
;
1497 trace("WM_GETMINMAXINFO\n");
1499 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1500 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1502 GetClientRect(parent
, &rc
);
1503 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1505 GetClientRect(parent
, &rc
);
1506 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1507 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1508 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1509 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1510 dump_minmax_info( minmax
);
1512 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1513 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1514 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1515 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1519 case WM_WINDOWPOSCHANGED
:
1521 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1524 GetWindowRect(hwnd
, &rc1
);
1525 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1526 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1527 /* note: winpos coordinates are relative to parent */
1528 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1529 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1530 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1532 GetWindowRect(hwnd
, &rc1
);
1533 GetClientRect(hwnd
, &rc2
);
1534 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1535 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1536 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1539 case WM_WINDOWPOSCHANGING
:
1541 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1542 WINDOWPOS my_winpos
= *winpos
;
1544 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1545 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1546 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1547 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1549 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1551 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1552 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1553 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1555 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1556 "DefWindowProc should not change WINDOWPOS values\n");
1561 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1564 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1566 static HWND mdi_client
;
1572 CLIENTCREATESTRUCT client_cs
;
1575 GetClientRect(hwnd
, &rc
);
1577 client_cs
.hWindowMenu
= 0;
1578 client_cs
.idFirstChild
= 1;
1580 /* MDIClient without MDIS_ALLCHILDSTYLES */
1581 mdi_client
= CreateWindowExA(0, "mdiclient",
1583 WS_CHILD
/*| WS_VISIBLE*/,
1584 /* tests depend on a not zero MDIClient size */
1585 0, 0, rc
.right
, rc
.bottom
,
1586 hwnd
, 0, GetModuleHandle(0),
1587 (LPVOID
)&client_cs
);
1589 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1590 DestroyWindow(mdi_client
);
1592 /* MDIClient with MDIS_ALLCHILDSTYLES */
1593 mdi_client
= CreateWindowExA(0, "mdiclient",
1595 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1596 /* tests depend on a not zero MDIClient size */
1597 0, 0, rc
.right
, rc
.bottom
,
1598 hwnd
, 0, GetModuleHandle(0),
1599 (LPVOID
)&client_cs
);
1601 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1602 DestroyWindow(mdi_client
);
1606 case WM_WINDOWPOSCHANGED
:
1608 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1611 GetWindowRect(hwnd
, &rc1
);
1612 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1613 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1614 /* note: winpos coordinates are relative to parent */
1615 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1616 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1617 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1619 GetWindowRect(hwnd
, &rc1
);
1620 GetClientRect(hwnd
, &rc2
);
1621 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1622 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1623 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1626 case WM_WINDOWPOSCHANGING
:
1628 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1629 WINDOWPOS my_winpos
= *winpos
;
1631 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1632 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1633 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1634 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1636 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1638 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1639 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1640 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1642 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1643 "DefWindowProc should not change WINDOWPOS values\n");
1652 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1655 static BOOL
mdi_RegisterWindowClasses(void)
1660 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1663 cls
.hInstance
= GetModuleHandleA(0);
1665 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1666 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1667 cls
.lpszMenuName
= NULL
;
1668 cls
.lpszClassName
= "MDI_parent_Class";
1669 if(!RegisterClassA(&cls
)) return FALSE
;
1671 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1672 cls
.lpszClassName
= "MDI_child_Class_1";
1673 if(!RegisterClassA(&cls
)) return FALSE
;
1675 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1676 cls
.lpszClassName
= "MDI_child_Class_2";
1677 if(!RegisterClassA(&cls
)) return FALSE
;
1682 static void test_mdi(void)
1687 if (!mdi_RegisterWindowClasses()) assert(0);
1689 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1690 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1691 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1692 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1693 GetDesktopWindow(), 0,
1694 GetModuleHandle(0), NULL
);
1695 assert(mdi_hwndMain
);
1697 while(GetMessage(&msg, 0, 0, 0))
1699 TranslateMessage(&msg);
1700 DispatchMessage(&msg);
1703 DestroyWindow(mdi_hwndMain
);
1706 static void test_icons(void)
1710 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1711 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1712 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1713 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1716 cls
.cbSize
= sizeof(cls
);
1718 cls
.lpfnWndProc
= DefWindowProcA
;
1722 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1723 cls
.hIconSm
= small_icon
;
1724 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1725 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1726 cls
.lpszMenuName
= NULL
;
1727 cls
.lpszClassName
= "IconWindowClass";
1729 RegisterClassExA(&cls
);
1731 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1732 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1735 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1736 ok( res
== 0, "wrong big icon %p/0\n", res
);
1737 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1738 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1739 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1740 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1741 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1742 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1743 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1744 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1746 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1747 ok( res
== 0, "wrong small icon %p/0\n", res
);
1748 /* this test is XP specific */
1749 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1750 ok( res != 0, "wrong small icon %p\n", res );*/
1751 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1752 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1753 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1754 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1755 /* this test is XP specific */
1756 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1757 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1758 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1759 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1760 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1761 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1762 /* this test is XP specific */
1763 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1764 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1766 /* make sure the big icon hasn't changed */
1767 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1768 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1770 DestroyWindow( hwnd
);
1773 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1775 if (msg
== WM_NCCALCSIZE
)
1777 RECT
*rect
= (RECT
*)lparam
;
1778 /* first time around increase the rectangle, next time decrease it */
1779 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1780 else InflateRect( rect
, -10, -10 );
1783 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1786 static void test_SetWindowPos(HWND hwnd
)
1788 RECT orig_win_rc
, rect
;
1790 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1792 SetRect(&rect
, 111, 222, 333, 444);
1793 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1794 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1795 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1797 SetRect(&rect
, 111, 222, 333, 444);
1798 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1799 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1800 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1802 GetWindowRect(hwnd
, &orig_win_rc
);
1804 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1805 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1806 GetWindowRect( hwnd
, &rect
);
1807 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1808 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1809 GetClientRect( hwnd
, &rect
);
1810 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1811 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1812 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1814 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1815 GetWindowRect( hwnd
, &rect
);
1816 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1817 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1818 GetClientRect( hwnd
, &rect
);
1819 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1820 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1821 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1823 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1824 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1825 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1827 /* Win9x truncates coordinates to 16-bit irrespectively */
1830 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1831 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1833 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1834 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1837 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1838 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1840 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1841 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1842 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1843 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1844 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1845 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1846 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1849 static void test_SetMenu(HWND parent
)
1853 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1857 hMenu
= CreateMenu();
1860 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1863 /* fails on (at least) Wine, NT4, XP SP2 */
1864 test_nonclient_area(parent
);
1866 ret
= GetMenu(parent
);
1867 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1868 /* test whether we can destroy a menu assigned to a window */
1869 retok
= DestroyMenu(hMenu
);
1870 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1871 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1872 ret
= GetMenu(parent
);
1873 /* This test fails on Win9x */
1875 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1876 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1877 test_nonclient_area(parent
);
1879 hMenu
= CreateMenu();
1883 ret
= GetMenu(parent
);
1884 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1886 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1887 test_nonclient_area(parent
);
1888 ret
= GetMenu(parent
);
1889 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1891 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1894 /* fails on (at least) Wine, NT4, XP SP2 */
1895 test_nonclient_area(parent
);
1897 ret
= GetMenu(parent
);
1898 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1900 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1901 test_nonclient_area(parent
);
1902 ret
= GetMenu(parent
);
1903 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1906 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1909 ret
= GetMenu(child
);
1910 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1912 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1913 test_nonclient_area(child
);
1914 ret
= GetMenu(child
);
1915 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1917 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1918 test_nonclient_area(child
);
1919 ret
= GetMenu(child
);
1920 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1922 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1923 test_nonclient_area(child
);
1924 ret
= GetMenu(child
);
1925 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1927 style
= GetWindowLong(child
, GWL_STYLE
);
1928 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1929 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1930 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1931 SetWindowLong(child
, GWL_STYLE
, style
);
1933 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1934 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1935 SetWindowLong(child
, GWL_STYLE
, style
);
1937 DestroyWindow(child
);
1941 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1943 HWND child
[5], hwnd
;
1948 hwnd
= GetWindow(parent
, GW_CHILD
);
1949 ok(!hwnd
, "have to start without children to perform the test\n");
1951 for (i
= 0; i
< total
; i
++)
1953 if (style
[i
] & DS_CONTROL
)
1955 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1956 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1957 if (style
[i
] & WS_VISIBLE
)
1958 ShowWindow(child
[i
], SW_SHOW
);
1960 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1963 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1964 parent
, (HMENU
)i
, 0, NULL
);
1965 trace("child[%d] = %p\n", i
, child
[i
]);
1966 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
1969 hwnd
= GetWindow(parent
, GW_CHILD
);
1970 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
1971 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
1972 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
1974 for (i
= 0; i
< total
; i
++)
1976 trace("hwnd[%d] = %p\n", i
, hwnd
);
1977 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
1979 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
1982 for (i
= 0; i
< total
; i
++)
1983 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
1986 static void test_children_zorder(HWND parent
)
1988 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
1990 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
1992 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
1993 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
1994 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
1995 const int complex_order_1
[1] = { 0 };
1996 const int complex_order_2
[2] = { 1, 0 };
1997 const int complex_order_3
[3] = { 1, 0, 2 };
1998 const int complex_order_4
[4] = { 1, 0, 2, 3 };
1999 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2000 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2001 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2002 WS_CHILD
| WS_VISIBLE
};
2003 const int complex_order_6
[3] = { 0, 1, 2 };
2005 /* simple WS_CHILD */
2006 test_window_tree(parent
, simple_style
, simple_order
, 5);
2008 /* complex children styles */
2009 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2010 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2011 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2012 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2013 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2015 /* another set of complex children styles */
2016 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2019 #define check_z_order(hwnd, next, prev, owner, topmost) \
2020 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2023 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2024 BOOL topmost
, const char *file
, int line
)
2029 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2030 /* skip foreign windows */
2031 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2032 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2034 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2035 test
= GetWindow(test
, GW_HWNDNEXT
);
2037 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2039 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2040 /* skip foreign windows */
2041 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2042 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2044 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2045 test
= GetWindow(test
, GW_HWNDPREV
);
2047 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2049 test
= GetWindow(hwnd
, GW_OWNER
);
2050 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2052 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2053 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2056 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2058 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2060 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2062 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2064 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2065 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2067 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2068 WS_OVERLAPPED
| WS_CAPTION
,
2070 0, 0, GetModuleHandle(0), NULL
);
2071 trace("hwnd_F %p\n", hwnd_F
);
2072 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2074 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2075 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2076 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2077 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2079 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2082 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2083 trace("hwnd_C %p\n", hwnd_C
);
2084 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2085 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2086 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2087 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2089 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2092 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2093 trace("hwnd_B %p\n", hwnd_B
);
2094 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2095 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2096 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2097 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2098 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2100 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2103 0, 0, GetModuleHandle(0), NULL
);
2104 trace("hwnd_A %p\n", hwnd_A
);
2105 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2106 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2107 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2108 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2109 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2110 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2112 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A
, hwnd_B
, hwnd_C
, hwnd_D
, hwnd_E
, hwnd_F
);
2114 /* move hwnd_F and its popups up */
2115 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2116 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2117 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2118 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2119 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2120 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2121 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2123 /* move hwnd_F and its popups down */
2124 #if 0 /* enable once Wine is fixed to pass this test */
2125 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2126 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2127 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2128 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2129 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2130 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2131 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2134 DestroyWindow(hwnd_A
);
2135 DestroyWindow(hwnd_B
);
2136 DestroyWindow(hwnd_C
);
2137 DestroyWindow(hwnd_F
);
2140 static void test_vis_rgn( HWND hwnd
)
2142 RECT win_rect
, rgn_rect
;
2143 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2146 ShowWindow(hwnd
,SW_SHOW
);
2147 hdc
= GetDC( hwnd
);
2148 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2149 GetWindowRect( hwnd
, &win_rect
);
2150 GetRgnBox( hrgn
, &rgn_rect
);
2151 if (GetVersion() & 0x80000000)
2153 trace("win9x, mapping to screen coords\n");
2154 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2156 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2157 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2158 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2159 rgn_rect
.left
, win_rect
.left
);
2160 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2161 rgn_rect
.top
, win_rect
.top
);
2162 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2163 rgn_rect
.right
, win_rect
.right
);
2164 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2165 rgn_rect
.bottom
, win_rect
.bottom
);
2166 ReleaseDC( hwnd
, hdc
);
2169 static LRESULT WINAPI
set_focus_on_activate_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
2171 if (msg
== WM_ACTIVATE
&& LOWORD(wp
) == WA_ACTIVE
)
2173 HWND child
= GetWindow(hwnd
, GW_CHILD
);
2174 ok(child
!= 0, "couldn't find child window\n");
2176 ok(GetFocus() == child
, "Focus should be on child %p\n", child
);
2179 return DefWindowProc(hwnd
, msg
, wp
, lp
);
2182 static void test_SetFocus(HWND hwnd
)
2185 WNDPROC old_wnd_proc
;
2187 /* check if we can set focus to non-visible windows */
2189 ShowWindow(hwnd
, SW_SHOW
);
2192 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2193 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2194 ShowWindow(hwnd
, SW_HIDE
);
2197 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2198 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2199 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2202 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2203 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2204 ShowWindow(child
, SW_SHOW
);
2205 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2206 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2207 ShowWindow(child
, SW_HIDE
);
2208 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2209 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2210 ShowWindow(child
, SW_SHOW
);
2212 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2213 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2214 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2216 ShowWindow(child
, SW_HIDE
);
2218 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2219 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2220 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2221 ShowWindow(child
, SW_HIDE
);
2222 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2224 ShowWindow(hwnd
, SW_SHOW
);
2225 ShowWindow(child
, SW_SHOW
);
2227 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2228 EnableWindow(hwnd
, FALSE
);
2229 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2230 EnableWindow(hwnd
, TRUE
);
2232 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2233 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2234 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2236 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2237 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2238 ShowWindow(hwnd
, SW_RESTORE
);
2239 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2240 ok( GetFocus() == hwnd
, "Focus should be on parent %p\n", hwnd
);
2241 ShowWindow(hwnd
, SW_SHOWMINIMIZED
);
2242 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2243 ok( GetFocus() != child
, "Focus should not be on child %p\n", child
);
2245 ok( GetFocus() != hwnd
, "Focus should not be on parent %p\n", hwnd
);
2246 old_wnd_proc
= (WNDPROC
)SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)set_focus_on_activate_proc
);
2247 ShowWindow(hwnd
, SW_RESTORE
);
2248 ok( GetActiveWindow() == hwnd
, "parent window %p should be active\n", hwnd
);
2250 ok( GetFocus() == child
, "Focus should be on child %p, not %p\n", child
, GetFocus() );
2252 SetWindowLongPtr(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)old_wnd_proc
);
2254 DestroyWindow( child
);
2257 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2259 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2261 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2262 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2263 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2266 static void test_SetActiveWindow(HWND hwnd
)
2270 flush_events( TRUE
);
2271 ShowWindow(hwnd
, SW_HIDE
);
2274 check_wnd_state(0, 0, 0, 0);
2276 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2278 ShowWindow(hwnd
, SW_SHOW
);
2279 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2281 hwnd2
= SetActiveWindow(0);
2282 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2283 check_wnd_state(0, 0, 0, 0);
2285 hwnd2
= SetActiveWindow(hwnd
);
2286 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2287 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2289 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2290 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2292 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2293 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2295 ShowWindow(hwnd
, SW_HIDE
);
2296 check_wnd_state(0, 0, 0, 0);
2298 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2299 SetActiveWindow(hwnd
);
2300 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2302 ShowWindow(hwnd
, SW_SHOW
);
2303 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2305 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2306 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2308 DestroyWindow(hwnd2
);
2309 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2311 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2312 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2314 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2315 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2317 DestroyWindow(hwnd2
);
2318 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2321 static void test_SetForegroundWindow(HWND hwnd
)
2326 flush_events( TRUE
);
2327 ShowWindow(hwnd
, SW_HIDE
);
2330 check_wnd_state(0, 0, 0, 0);
2332 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2334 ShowWindow(hwnd
, SW_SHOW
);
2335 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2337 hwnd2
= SetActiveWindow(0);
2338 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2339 check_wnd_state(0, 0, 0, 0);
2341 ret
= SetForegroundWindow(hwnd
);
2342 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2343 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2345 SetLastError(0xdeadbeef);
2346 ret
= SetForegroundWindow(0);
2347 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2348 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2349 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2351 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2352 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2354 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2355 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2357 hwnd2
= GetForegroundWindow();
2358 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2359 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2360 hwnd2
= GetForegroundWindow();
2361 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2363 ShowWindow(hwnd
, SW_HIDE
);
2364 check_wnd_state(0, 0, 0, 0);
2366 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2367 ret
= SetForegroundWindow(hwnd
);
2368 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2369 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2371 ShowWindow(hwnd
, SW_SHOW
);
2372 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2374 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2375 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2377 DestroyWindow(hwnd2
);
2378 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2380 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2381 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2383 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2384 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2386 DestroyWindow(hwnd2
);
2387 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2390 static WNDPROC old_button_proc
;
2392 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2397 key_state
= GetKeyState(VK_LBUTTON
);
2398 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2400 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2402 if (msg
== WM_LBUTTONDOWN
)
2406 check_wnd_state(button
, button
, button
, button
);
2408 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2410 trace("hwnd %p\n", hwnd
);
2412 check_wnd_state(button
, button
, button
, button
);
2414 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2416 check_wnd_state(button
, button
, button
, button
);
2418 DestroyWindow(hwnd
);
2420 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2422 trace("hwnd %p\n", hwnd
);
2424 check_wnd_state(button
, button
, button
, button
);
2426 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2427 * match internal button state.
2429 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2430 check_wnd_state(button
, button
, button
, 0);
2432 ShowWindow(hwnd
, SW_SHOW
);
2433 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2435 capture
= SetCapture(hwnd
);
2436 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2438 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2440 DestroyWindow(hwnd
);
2442 check_wnd_state(button
, 0, button
, 0);
2448 static void test_capture_1(void)
2450 HWND button
, capture
;
2452 capture
= GetCapture();
2453 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2455 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2457 trace("button %p\n", button
);
2459 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2461 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2463 capture
= SetCapture(button
);
2464 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2465 check_wnd_state(button
, 0, button
, button
);
2467 DestroyWindow(button
);
2468 check_wnd_state(0, 0, 0, 0);
2471 static void test_capture_2(void)
2473 HWND button
, hwnd
, capture
;
2475 check_wnd_state(0, 0, 0, 0);
2477 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2479 trace("button %p\n", button
);
2481 check_wnd_state(button
, button
, button
, 0);
2483 capture
= SetCapture(button
);
2484 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2486 check_wnd_state(button
, button
, button
, button
);
2488 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2489 * internal button state.
2491 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2492 check_wnd_state(button
, button
, button
, button
);
2494 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2496 trace("hwnd %p\n", hwnd
);
2498 check_wnd_state(button
, button
, button
, button
);
2500 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2502 check_wnd_state(button
, button
, button
, button
);
2504 DestroyWindow(hwnd
);
2506 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2508 trace("hwnd %p\n", hwnd
);
2510 check_wnd_state(button
, button
, button
, button
);
2512 ShowWindow(hwnd
, SW_SHOW
);
2514 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2516 capture
= SetCapture(hwnd
);
2517 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2519 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2521 DestroyWindow(hwnd
);
2522 check_wnd_state(button
, button
, button
, 0);
2524 DestroyWindow(button
);
2525 check_wnd_state(0, 0, 0, 0);
2528 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2532 ShowWindow(hwnd1
, SW_HIDE
);
2533 ShowWindow(hwnd2
, SW_HIDE
);
2535 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2536 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2539 check_wnd_state(0, 0, 0, hwnd1
);
2542 check_wnd_state(0, 0, 0, hwnd2
);
2544 ShowWindow(hwnd1
, SW_SHOW
);
2545 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2547 ret
= ReleaseCapture();
2548 ok (ret
, "releasecapture did not return TRUE.\n");
2549 ret
= ReleaseCapture();
2550 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2553 static void test_keyboard_input(HWND hwnd
)
2558 flush_events( TRUE
);
2559 ShowWindow(hwnd
, SW_SHOW
);
2561 flush_events( TRUE
);
2563 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2566 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2568 flush_events( TRUE
);
2570 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2571 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2572 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2573 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2574 ok( !ret
, "message %04x available\n", msg
.message
);
2576 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2578 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2579 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2580 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2581 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2582 ok( !ret
, "message %04x available\n", msg
.message
);
2584 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2586 keybd_event(VK_SPACE
, 0, 0, 0);
2587 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2588 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2589 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2590 ok( !ret
, "message %04x available\n", msg
.message
);
2593 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2595 flush_events( TRUE
);
2597 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2598 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2599 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2600 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2601 ok( !ret
, "message %04x available\n", msg
.message
);
2603 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2605 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2606 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2607 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2608 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2609 ok( !ret
, "message %04x available\n", msg
.message
);
2611 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2613 keybd_event(VK_SPACE
, 0, 0, 0);
2614 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2615 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2616 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2617 ok( !ret
, "message %04x available\n", msg
.message
);
2620 static void test_mouse_input(HWND hwnd
)
2630 ShowWindow(hwnd
, SW_SHOW
);
2633 GetWindowRect(hwnd
, &rc
);
2634 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2636 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2637 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2640 ShowWindow(popup
, SW_SHOW
);
2641 UpdateWindow(popup
);
2643 GetWindowRect(popup
, &rc
);
2644 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2646 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2647 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2648 trace("setting cursor to (%d,%d)\n", x
, y
);
2652 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2654 flush_events( TRUE
);
2656 /* Check that setting the same position will generate WM_MOUSEMOVE */
2659 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2660 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2661 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n", x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2663 /* force the system to update its internal queue mouse position,
2664 * otherwise it won't generate relative mouse movements below.
2666 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2667 flush_events( TRUE
);
2670 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2671 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2672 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2673 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2674 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2675 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2676 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2677 ok( !ret
, "message %04x available\n", msg
.message
);
2679 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2680 ShowWindow(popup
, SW_HIDE
);
2681 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2682 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2683 flush_events( TRUE
);
2685 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2686 ShowWindow(hwnd
, SW_HIDE
);
2687 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2688 ok( !ret
, "message %04x available\n", msg
.message
);
2689 flush_events( TRUE
);
2691 /* test mouse clicks */
2693 ShowWindow(hwnd
, SW_SHOW
);
2694 flush_events( TRUE
);
2695 ShowWindow(popup
, SW_SHOW
);
2696 flush_events( TRUE
);
2698 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2699 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2700 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2701 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2703 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2704 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2705 msg
.hwnd
, popup
, msg
.message
);
2706 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2707 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2708 msg
.hwnd
, popup
, msg
.message
);
2710 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2711 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2712 msg
.hwnd
, popup
, msg
.message
);
2713 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2714 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2715 msg
.hwnd
, popup
, msg
.message
);
2717 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2718 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2719 msg
.hwnd
, popup
, msg
.message
);
2720 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2721 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2722 msg
.hwnd
, popup
, msg
.message
);
2724 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2725 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2726 msg
.hwnd
, popup
, msg
.message
);
2727 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2728 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2729 msg
.hwnd
, popup
, msg
.message
);
2731 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2732 ok(!ret
, "message %04x available\n", msg
.message
);
2734 ShowWindow(popup
, SW_HIDE
);
2735 flush_events( TRUE
);
2737 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2738 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2739 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2740 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2742 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2743 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2744 msg
.hwnd
, hwnd
, msg
.message
);
2745 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2746 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2747 msg
.hwnd
, hwnd
, msg
.message
);
2749 test_lbuttondown_flag
= TRUE
;
2750 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2751 test_lbuttondown_flag
= FALSE
;
2753 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2754 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2755 msg
.hwnd
, popup
, msg
.message
);
2756 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2757 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2758 msg
.hwnd
, popup
, msg
.message
);
2759 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2761 /* Test WM_MOUSEACTIVATE */
2762 #define TEST_MOUSEACTIVATE(A,B) \
2763 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2764 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2766 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2767 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2768 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2769 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2770 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2771 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2772 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2773 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2774 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2775 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2776 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2777 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2778 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2779 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2780 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2781 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2782 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2783 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2784 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2785 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2786 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2787 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2788 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2789 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2791 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2792 flush_events( TRUE
);
2794 DestroyWindow(popup
);
2797 static void test_validatergn(HWND hwnd
)
2803 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2804 ShowWindow(hwnd
, SW_SHOW
);
2805 UpdateWindow( hwnd
);
2806 /* test that ValidateRect validates children*/
2807 InvalidateRect( child
, NULL
, 1);
2808 GetWindowRect( child
, &rc
);
2809 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2810 ret
= GetUpdateRect( child
, &rc2
, 0);
2811 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2812 "Update rectangle is empty!\n");
2813 ValidateRect( hwnd
, &rc
);
2814 ret
= GetUpdateRect( child
, &rc2
, 0);
2815 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2816 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2817 rc2
.right
, rc2
.bottom
);
2819 /* now test ValidateRgn */
2820 InvalidateRect( child
, NULL
, 1);
2821 GetWindowRect( child
, &rc
);
2822 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2823 rgn
= CreateRectRgnIndirect( &rc
);
2824 ValidateRgn( hwnd
, rgn
);
2825 ret
= GetUpdateRect( child
, &rc2
, 0);
2826 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2827 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2828 rc2
.right
, rc2
.bottom
);
2831 DestroyWindow( child
);
2834 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2836 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2837 GetWindowRect( hwnd
, prc
);
2838 trace("window rect is %d,%d - %d,%d\n",
2839 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2840 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2841 trace("nccalc rect is %d,%d - %d,%d\n",
2842 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2845 static void test_nccalcscroll(HWND parent
)
2848 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2849 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2850 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2851 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2852 10, 10, 200, 200, parent
, 0, 0, NULL
);
2853 ShowWindow( parent
, SW_SHOW
);
2854 UpdateWindow( parent
);
2856 /* test window too low for a horizontal scroll bar */
2857 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2858 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2859 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2861 /* test window just high enough for a horizontal scroll bar */
2862 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2863 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2864 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2866 /* test window too narrow for a vertical scroll bar */
2867 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2868 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2869 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2871 /* test window just wide enough for a vertical scroll bar */
2872 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2873 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2874 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2876 /* same test, but with client edge: not enough width */
2877 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2878 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2879 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2880 "Width should be %d size is %d,%d - %d,%d\n",
2881 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2883 DestroyWindow( hwnd
);
2886 static void test_SetParent(void)
2889 HWND desktop
= GetDesktopWindow();
2891 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2892 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2894 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2895 100, 100, 200, 200, 0, 0, 0, NULL
);
2896 assert(parent
!= 0);
2897 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2898 0, 0, 50, 50, parent
, 0, 0, NULL
);
2899 assert(child1
!= 0);
2900 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2901 0, 0, 50, 50, child1
, 0, 0, NULL
);
2902 assert(child2
!= 0);
2903 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2904 0, 0, 50, 50, child2
, 0, 0, NULL
);
2905 assert(child3
!= 0);
2906 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2907 0, 0, 50, 50, child3
, 0, 0, NULL
);
2908 assert(child4
!= 0);
2910 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2911 parent
, child1
, child2
, child3
, child4
);
2913 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2914 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2915 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2916 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2917 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2919 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2920 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2921 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2922 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2923 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2925 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2926 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2927 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2928 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2929 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2930 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2931 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2932 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2933 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2935 if (!is_win9x
) /* Win9x doesn't survive this test */
2937 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2938 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2939 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2940 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2941 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2942 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2943 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2945 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2946 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2947 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2948 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2949 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2952 hMenu
= CreateMenu();
2953 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2954 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2955 assert(sibling
!= 0);
2957 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2958 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2960 ret
= DestroyWindow(parent
);
2961 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2963 ok(!IsWindow(parent
), "parent still exists\n");
2964 ok(!IsWindow(sibling
), "sibling still exists\n");
2965 ok(!IsWindow(child1
), "child1 still exists\n");
2966 ok(!IsWindow(child2
), "child2 still exists\n");
2967 ok(!IsWindow(child3
), "child3 still exists\n");
2968 ok(!IsWindow(child4
), "child4 still exists\n");
2971 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2973 LPCREATESTRUCT lpcs
;
2980 lpcs
= (LPCREATESTRUCT
)lparam
;
2981 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2984 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2985 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2986 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2987 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2989 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2991 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2992 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2993 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2995 ok(lpss
->styleNew
== lpcs
->style
,
2996 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2997 lpss
->styleNew
, lpcs
->style
);
3001 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3004 static ATOM atomStyleCheckClass
;
3006 static void register_style_check_class(void)
3014 GetModuleHandle(NULL
),
3016 LoadCursor(NULL
, IDC_ARROW
),
3017 (HBRUSH
)(COLOR_BTNFACE
+1),
3019 TEXT("WineStyleCheck"),
3022 atomStyleCheckClass
= RegisterClass(&wc
);
3025 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3027 DWORD dwActualStyle
;
3028 DWORD dwActualExStyle
;
3031 HWND hwndParent
= NULL
;
3033 ss
.styleNew
= dwStyleIn
;
3034 ss
.styleOld
= dwExStyleIn
;
3036 if (dwStyleIn
& WS_CHILD
)
3038 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3039 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3042 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3043 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3046 flush_events( TRUE
);
3048 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3049 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3050 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3051 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3052 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3054 DestroyWindow(hwnd
);
3055 if (hwndParent
) DestroyWindow(hwndParent
);
3058 /* tests what window styles the window manager automatically adds */
3059 static void test_window_styles(void)
3061 register_style_check_class();
3063 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3064 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3065 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3066 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3067 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3068 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3069 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3070 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3071 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3072 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3073 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3076 static void test_scrollvalidate( HWND parent
)
3079 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3080 HRGN exprgn
, tmprgn
, clipping
;
3081 RECT rc
, rcu
, cliprc
;
3082 /* create two overlapping child windows. The visual region
3083 * of hwnd1 is clipped by the overlapping part of
3084 * hwnd2 because of the WS_CLIPSIBLING style */
3087 clipping
= CreateRectRgn(0,0,0,0);
3088 tmprgn
= CreateRectRgn(0,0,0,0);
3089 exprgn
= CreateRectRgn(0,0,0,0);
3090 hwnd2
= CreateWindowExA(0, "static", NULL
,
3091 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3092 75, 30, 100, 100, parent
, 0, 0, NULL
);
3093 hwnd1
= CreateWindowExA(0, "static", NULL
,
3094 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3095 25, 50, 100, 100, parent
, 0, 0, NULL
);
3096 ShowWindow( parent
, SW_SHOW
);
3097 UpdateWindow( parent
);
3098 GetClientRect( hwnd1
, &rc
);
3100 SetRectRgn( clipping
, 10, 10, 90, 90);
3101 hdc
= GetDC( hwnd1
);
3102 /* for a visual touch */
3103 TextOut( hdc
, 0,10, "0123456789", 10);
3104 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3105 if (winetest_debug
> 0) dump_region(hrgn
);
3106 /* create a region with what is expected */
3107 SetRectRgn( exprgn
, 39,0,49,74);
3108 SetRectRgn( tmprgn
, 88,79,98,93);
3109 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3110 SetRectRgn( tmprgn
, 0,93,98,98);
3111 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3112 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3113 trace("update rect is %d,%d - %d,%d\n",
3114 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3115 /* now with clipping region */
3116 SelectClipRgn( hdc
, clipping
);
3117 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3118 if (winetest_debug
> 0) dump_region(hrgn
);
3119 /* create a region with what is expected */
3120 SetRectRgn( exprgn
, 39,10,49,74);
3121 SetRectRgn( tmprgn
, 80,79,90,85);
3122 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3123 SetRectRgn( tmprgn
, 10,85,90,90);
3124 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3125 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3126 trace("update rect is %d,%d - %d,%d\n",
3127 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3128 ReleaseDC( hwnd1
, hdc
);
3130 /* test scrolling a window with an update region */
3131 DestroyWindow( hwnd2
);
3132 ValidateRect( hwnd1
, NULL
);
3133 SetRect( &rc
, 40,40, 50,50);
3134 InvalidateRect( hwnd1
, &rc
, 1);
3135 GetClientRect( hwnd1
, &rc
);
3137 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3138 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3139 if (winetest_debug
> 0) dump_region(hrgn
);
3140 SetRectRgn( exprgn
, 88,0,98,98);
3141 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3142 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3143 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3145 /* clear an update region */
3146 UpdateWindow( hwnd1
);
3148 SetRect( &rc
, 0,40, 100,60);
3149 SetRect( &cliprc
, 0,0, 100,100);
3150 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3151 if (winetest_debug
> 0) dump_region( hrgn
);
3152 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3153 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3155 /* now test ScrollWindowEx with a combination of
3156 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3157 /* make hwnd2 the child of hwnd1 */
3158 hwnd2
= CreateWindowExA(0, "static", NULL
,
3159 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3160 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3161 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3162 GetClientRect( hwnd1
, &rc
);
3165 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3166 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3167 ValidateRect( hwnd1
, NULL
);
3168 ValidateRect( hwnd2
, NULL
);
3169 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3170 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3171 if (winetest_debug
> 0) dump_region(hrgn
);
3172 SetRectRgn( exprgn
, 88,0,98,88);
3173 SetRectRgn( tmprgn
, 0,88,98,98);
3174 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3175 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3177 /* SW_SCROLLCHILDREN */
3178 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3179 ValidateRect( hwnd1
, NULL
);
3180 ValidateRect( hwnd2
, NULL
);
3181 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3182 if (winetest_debug
> 0) dump_region(hrgn
);
3183 /* expected region is the same as in previous test */
3184 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3186 /* no SW_SCROLLCHILDREN */
3187 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3188 ValidateRect( hwnd1
, NULL
);
3189 ValidateRect( hwnd2
, NULL
);
3190 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3191 if (winetest_debug
> 0) dump_region(hrgn
);
3192 /* expected region is the same as in previous test */
3193 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3195 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3196 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3197 ValidateRect( hwnd1
, NULL
);
3198 ValidateRect( hwnd2
, NULL
);
3199 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3200 if (winetest_debug
> 0) dump_region(hrgn
);
3201 SetRectRgn( exprgn
, 88,0,98,20);
3202 SetRectRgn( tmprgn
, 20,20,98,30);
3203 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3204 SetRectRgn( tmprgn
, 20,30,30,88);
3205 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3206 SetRectRgn( tmprgn
, 0,88,30,98);
3207 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3208 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3211 DeleteObject( hrgn
);
3212 DeleteObject( exprgn
);
3213 DeleteObject( tmprgn
);
3214 DestroyWindow( hwnd1
);
3215 DestroyWindow( hwnd2
);
3218 /* couple of tests of return values of scrollbar functions
3219 * called on a scrollbarless window */
3220 static void test_scroll(void)
3225 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3226 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3227 100, 100, 200, 200, 0, 0, 0, NULL
);
3229 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3230 ok( ret
, "GetScrollRange returns FALSE\n");
3231 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3232 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3233 si
.cbSize
= sizeof( si
);
3234 si
.fMask
= SIF_PAGE
;
3235 si
.nPage
= 0xdeadbeef;
3236 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3237 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3238 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3240 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3241 ok( ret
, "GetScrollRange returns FALSE\n");
3242 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3243 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3244 si
.cbSize
= sizeof( si
);
3245 si
.fMask
= SIF_PAGE
;
3246 si
.nPage
= 0xdeadbeef;
3247 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3248 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3249 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3251 DestroyWindow( hwnd
);
3254 static void test_scrolldc( HWND parent
)
3257 HRGN exprgn
, tmprgn
, hrgn
;
3258 RECT rc
, rc2
, rcu
, cliprc
;
3262 hrgn
= CreateRectRgn(0,0,0,0);
3263 tmprgn
= CreateRectRgn(0,0,0,0);
3264 exprgn
= CreateRectRgn(0,0,0,0);
3266 hwnd1
= CreateWindowExA(0, "static", NULL
,
3267 WS_CHILD
| WS_VISIBLE
,
3268 25, 50, 100, 100, parent
, 0, 0, NULL
);
3269 ShowWindow( parent
, SW_SHOW
);
3270 UpdateWindow( parent
);
3271 flush_events( TRUE
);
3272 GetClientRect( hwnd1
, &rc
);
3273 hdc
= GetDC( hwnd1
);
3274 /* paint the upper half of the window black */
3276 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3277 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3278 /* clip region is the lower half */
3280 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3281 /* test whether scrolled pixels are properly clipped */
3282 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3283 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3284 /* this scroll should not cause any visible changes */
3285 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3286 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3287 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3288 /* test with NULL clip rect */
3289 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3290 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3291 trace("update rect: %d,%d - %d,%d\n",
3292 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3293 if (winetest_debug
> 0) dump_region(hrgn
);
3294 SetRect(&rc2
, 0, 0, 100, 100);
3295 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3296 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3298 SetRectRgn( exprgn
, 0, 0, 20, 80);
3299 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3300 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3301 if (winetest_debug
> 0) dump_region(exprgn
);
3302 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3303 /* test clip rect > scroll rect */
3304 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3306 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3307 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3308 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3309 SetRectRgn( exprgn
, 25, 25, 75, 35);
3310 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3311 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3312 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3313 colr
= GetPixel( hdc
, 80, 80);
3314 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3315 trace("update rect: %d,%d - %d,%d\n",
3316 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3317 if (winetest_debug
> 0) dump_region(hrgn
);
3321 DeleteObject(exprgn
);
3322 DeleteObject(tmprgn
);
3323 DestroyWindow(hwnd1
);
3326 static void test_params(void)
3331 /* Just a param check */
3332 SetLastError(0xdeadbeef);
3333 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3334 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3336 SetLastError(0xdeadbeef);
3337 hwnd
=CreateWindow("LISTBOX", "TestList",
3338 (LBS_STANDARD
& ~LBS_SORT
),
3340 NULL
, (HMENU
)1, NULL
, 0);
3342 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3343 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3344 GetLastError() == 0xdeadbeef, /* Win9x */
3345 "wrong last error value %d\n", GetLastError());
3348 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3352 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3359 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3362 ShowWindow(hwnd
, SW_SHOW
);
3364 test_nonclient_area(hwnd
);
3367 DestroyWindow(hwnd
);
3370 static BOOL
AWR_init(void)
3374 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3375 class.lpfnWndProc
= DefWindowProcA
;
3376 class.cbClsExtra
= 0;
3377 class.cbWndExtra
= 0;
3378 class.hInstance
= 0;
3379 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3380 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3381 class.hbrBackground
= 0;
3382 class.lpszMenuName
= 0;
3383 class.lpszClassName
= szAWRClass
;
3385 if (!RegisterClass (&class)) {
3386 ok(FALSE
, "RegisterClass failed\n");
3390 hmenu
= CreateMenu();
3393 ok(hmenu
!= 0, "Failed to create menu\n");
3394 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3400 static void test_AWR_window_size(BOOL menu
)
3404 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3407 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3408 WS_HSCROLL
, WS_VSCROLL
3412 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3415 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3416 WS_EX_DLGMODALFRAME
,
3423 /* A exhaustive check of all the styles takes too long
3424 * so just do a (hopefully representative) sample
3426 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3427 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3428 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3429 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3430 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3435 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3437 static void test_AdjustWindowRect(void)
3442 SHOWSYSMETRIC(SM_CYCAPTION
);
3443 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3444 SHOWSYSMETRIC(SM_CYMENU
);
3445 SHOWSYSMETRIC(SM_CXEDGE
);
3446 SHOWSYSMETRIC(SM_CYEDGE
);
3447 SHOWSYSMETRIC(SM_CXVSCROLL
);
3448 SHOWSYSMETRIC(SM_CYHSCROLL
);
3449 SHOWSYSMETRIC(SM_CXFRAME
);
3450 SHOWSYSMETRIC(SM_CYFRAME
);
3451 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3452 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3453 SHOWSYSMETRIC(SM_CXBORDER
);
3454 SHOWSYSMETRIC(SM_CYBORDER
);
3456 test_AWR_window_size(FALSE
);
3457 test_AWR_window_size(TRUE
);
3461 #undef SHOWSYSMETRIC
3464 /* Global variables to trigger exit from loop */
3465 static int redrawComplete
, WMPAINT_count
;
3467 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3472 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3474 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3476 BeginPaint(hwnd
, &ps
);
3477 EndPaint(hwnd
, &ps
);
3482 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3485 /* Ensure we exit from RedrawNow regardless of invalidated area */
3486 static void test_redrawnow(void)
3491 cls
.style
= CS_DBLCLKS
;
3492 cls
.lpfnWndProc
= redraw_window_procA
;
3495 cls
.hInstance
= GetModuleHandleA(0);
3497 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3498 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3499 cls
.lpszMenuName
= NULL
;
3500 cls
.lpszClassName
= "RedrawWindowClass";
3502 if(!RegisterClassA(&cls
)) {
3503 trace("Register failed %d\n", GetLastError());
3507 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3508 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3510 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3511 ShowWindow(hwndMain
, SW_SHOW
);
3512 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3513 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3514 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3515 redrawComplete
= TRUE
;
3516 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3519 DestroyWindow( hwndMain
);
3522 struct parentdc_stat
{
3528 struct parentdc_test
{
3529 struct parentdc_stat main
, main_todo
;
3530 struct parentdc_stat child1
, child1_todo
;
3531 struct parentdc_stat child2
, child2_todo
;
3534 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3539 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3544 trace("doing WM_PAINT on %p\n", hwnd
);
3545 GetClientRect(hwnd
, &rc
);
3546 CopyRect(&t
->client
, &rc
);
3547 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3548 GetWindowRect(hwnd
, &rc
);
3549 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3550 BeginPaint(hwnd
, &ps
);
3551 CopyRect(&t
->paint
, &ps
.rcPaint
);
3552 GetClipBox(ps
.hdc
, &rc
);
3553 CopyRect(&t
->clip
, &rc
);
3554 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3555 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3556 EndPaint(hwnd
, &ps
);
3559 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3562 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3564 SetRectEmpty(&t
->client
);
3565 SetRectEmpty(&t
->clip
);
3566 SetRectEmpty(&t
->paint
);
3569 static void zero_parentdc_test(struct parentdc_test
*t
)
3571 zero_parentdc_stat(&t
->main
);
3572 zero_parentdc_stat(&t
->child1
);
3573 zero_parentdc_stat(&t
->child2
);
3576 #define parentdc_field_ok(t, w, r, f, got) \
3577 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3578 ": expected %d, got %d\n", \
3581 #define parentdc_todo_field_ok(t, w, r, f, got) \
3582 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3583 else parentdc_field_ok(t, w, r, f, got)
3585 #define parentdc_rect_ok(t, w, r, got) \
3586 parentdc_todo_field_ok(t, w, r, left, got); \
3587 parentdc_todo_field_ok(t, w, r, top, got); \
3588 parentdc_todo_field_ok(t, w, r, right, got); \
3589 parentdc_todo_field_ok(t, w, r, bottom, got);
3591 #define parentdc_win_ok(t, w, got) \
3592 parentdc_rect_ok(t, w, client, got); \
3593 parentdc_rect_ok(t, w, clip, got); \
3594 parentdc_rect_ok(t, w, paint, got);
3596 #define parentdc_ok(t, got) \
3597 parentdc_win_ok(t, main, got); \
3598 parentdc_win_ok(t, child1, got); \
3599 parentdc_win_ok(t, child2, got);
3601 static void test_csparentdc(void)
3603 WNDCLASSA clsMain
, cls
;
3604 HWND hwndMain
, hwnd1
, hwnd2
;
3607 struct parentdc_test test_answer
;
3609 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3610 const struct parentdc_test test1
=
3612 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3613 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3614 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3617 const struct parentdc_test test2
=
3619 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3620 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3621 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3624 const struct parentdc_test test3
=
3626 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3627 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3628 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3631 const struct parentdc_test test4
=
3633 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3634 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3635 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3638 const struct parentdc_test test5
=
3640 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3641 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3642 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3645 const struct parentdc_test test6
=
3647 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3648 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3649 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3652 const struct parentdc_test test7
=
3654 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3655 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3656 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3660 clsMain
.style
= CS_DBLCLKS
;
3661 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3662 clsMain
.cbClsExtra
= 0;
3663 clsMain
.cbWndExtra
= 0;
3664 clsMain
.hInstance
= GetModuleHandleA(0);
3666 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3667 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3668 clsMain
.lpszMenuName
= NULL
;
3669 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3671 if(!RegisterClassA(&clsMain
)) {
3672 trace("Register failed %d\n", GetLastError());
3676 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3677 cls
.lpfnWndProc
= parentdc_window_procA
;
3680 cls
.hInstance
= GetModuleHandleA(0);
3682 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3683 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3684 cls
.lpszMenuName
= NULL
;
3685 cls
.lpszClassName
= "ParentDcWindowClass";
3687 if(!RegisterClassA(&cls
)) {
3688 trace("Register failed %d\n", GetLastError());
3692 SetRect(&rc
, 0, 0, 150, 150);
3693 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3694 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3695 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3696 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3697 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3698 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3699 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3700 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3701 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3702 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3703 ShowWindow(hwndMain
, SW_SHOW
);
3704 ShowWindow(hwnd1
, SW_SHOW
);
3705 ShowWindow(hwnd2
, SW_SHOW
);
3706 flush_events( TRUE
);
3708 zero_parentdc_test(&test_answer
);
3709 InvalidateRect(hwndMain
, NULL
, TRUE
);
3710 flush_events( TRUE
);
3711 parentdc_ok(test1
, test_answer
);
3713 zero_parentdc_test(&test_answer
);
3714 SetRect(&rc
, 0, 0, 50, 50);
3715 InvalidateRect(hwndMain
, &rc
, TRUE
);
3716 flush_events( TRUE
);
3717 parentdc_ok(test2
, test_answer
);
3719 zero_parentdc_test(&test_answer
);
3720 SetRect(&rc
, 0, 0, 10, 10);
3721 InvalidateRect(hwndMain
, &rc
, TRUE
);
3722 flush_events( TRUE
);
3723 parentdc_ok(test3
, test_answer
);
3725 zero_parentdc_test(&test_answer
);
3726 SetRect(&rc
, 40, 40, 50, 50);
3727 InvalidateRect(hwndMain
, &rc
, TRUE
);
3728 flush_events( TRUE
);
3729 parentdc_ok(test4
, test_answer
);
3731 zero_parentdc_test(&test_answer
);
3732 SetRect(&rc
, 20, 20, 60, 60);
3733 InvalidateRect(hwndMain
, &rc
, TRUE
);
3734 flush_events( TRUE
);
3735 parentdc_ok(test5
, test_answer
);
3737 zero_parentdc_test(&test_answer
);
3738 SetRect(&rc
, 0, 0, 10, 10);
3739 InvalidateRect(hwnd1
, &rc
, TRUE
);
3740 flush_events( TRUE
);
3741 parentdc_ok(test6
, test_answer
);
3743 zero_parentdc_test(&test_answer
);
3744 SetRect(&rc
, -5, -5, 65, 65);
3745 InvalidateRect(hwnd1
, &rc
, TRUE
);
3746 flush_events( TRUE
);
3747 parentdc_ok(test7
, test_answer
);
3749 DestroyWindow(hwndMain
);
3750 DestroyWindow(hwnd1
);
3751 DestroyWindow(hwnd2
);
3754 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3756 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3759 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3761 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3764 static void test_IsWindowUnicode(void)
3766 static const char ansi_class_nameA
[] = "ansi class name";
3767 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3768 static const char unicode_class_nameA
[] = "unicode class name";
3769 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3774 memset(&classW
, 0, sizeof(classW
));
3775 classW
.hInstance
= GetModuleHandleA(0);
3776 classW
.lpfnWndProc
= def_window_procW
;
3777 classW
.lpszClassName
= unicode_class_nameW
;
3778 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3780 memset(&classA
, 0, sizeof(classA
));
3781 classA
.hInstance
= GetModuleHandleA(0);
3782 classA
.lpfnWndProc
= def_window_procA
;
3783 classA
.lpszClassName
= ansi_class_nameA
;
3784 assert(RegisterClassA(&classA
));
3786 /* unicode class: window proc */
3787 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3788 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3791 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3792 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3793 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3794 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3795 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3797 DestroyWindow(hwnd
);
3799 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3800 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3803 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3804 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3805 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3806 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3807 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3809 DestroyWindow(hwnd
);
3811 /* ansi class: window proc */
3812 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3813 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3816 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3817 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3818 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3819 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3820 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3822 DestroyWindow(hwnd
);
3824 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3825 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3828 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3829 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3830 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3831 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3832 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3834 DestroyWindow(hwnd
);
3836 /* unicode class: class proc */
3837 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3838 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3841 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3842 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3843 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3844 /* do not restore class window proc back to unicode */
3846 DestroyWindow(hwnd
);
3848 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3849 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3852 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3853 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3854 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3856 DestroyWindow(hwnd
);
3858 /* ansi class: class proc */
3859 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3860 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3863 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3864 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3865 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3866 /* do not restore class window proc back to ansi */
3868 DestroyWindow(hwnd
);
3870 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3871 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3874 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3875 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3876 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3878 DestroyWindow(hwnd
);
3881 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3885 if (msg
!= WM_GETMINMAXINFO
)
3886 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3888 minmax
= (MINMAXINFO
*)lp
;
3890 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3892 minmax
->ptReserved
.x
= 0;
3893 minmax
->ptReserved
.y
= 0;
3894 minmax
->ptMaxSize
.x
= 400;
3895 minmax
->ptMaxSize
.y
= 400;
3896 minmax
->ptMaxPosition
.x
= 300;
3897 minmax
->ptMaxPosition
.y
= 300;
3898 minmax
->ptMaxTrackSize
.x
= 200;
3899 minmax
->ptMaxTrackSize
.y
= 200;
3900 minmax
->ptMinTrackSize
.x
= 100;
3901 minmax
->ptMinTrackSize
.y
= 100;
3904 DefWindowProc(hwnd
, msg
, wp
, lp
);
3908 static int expected_cx
, expected_cy
;
3909 static RECT expected_rect
, broken_rect
;
3911 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3915 case WM_GETMINMAXINFO
:
3918 GetWindowRect( hwnd
, &rect
);
3919 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3920 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3921 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3926 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3928 GetWindowRect( hwnd
, &rect
);
3929 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3930 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3931 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3932 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3933 ok( (rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3934 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
) ||
3935 broken( rect
.right
- rect
.left
== broken_rect
.right
- broken_rect
.left
&&
3936 rect
.bottom
- rect
.top
== broken_rect
.bottom
- broken_rect
.top
),
3937 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3938 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3939 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3940 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3944 RECT rect
, *r
= (RECT
*)lp
;
3945 GetWindowRect( hwnd
, &rect
);
3946 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
3947 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3948 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3949 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3952 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3956 static void test_CreateWindow(void)
3964 #define expect_menu(window, menu) \
3965 SetLastError(0xdeadbeef); \
3966 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3968 #define expect_style(window, style)\
3969 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3971 #define expect_ex_style(window, ex_style)\
3972 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3974 hmenu
= CreateMenu();
3976 parent
= GetDesktopWindow();
3977 assert(parent
!= 0);
3979 SetLastError(0xdeadbeef);
3980 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3983 SetLastError(0xdeadbeef);
3984 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3985 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3986 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3987 expect_menu(hwnd
, 1);
3988 expect_style(hwnd
, WS_CHILD
);
3989 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3990 DestroyWindow(hwnd
);
3992 SetLastError(0xdeadbeef);
3993 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3994 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3995 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3996 expect_menu(hwnd
, 1);
3997 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3998 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3999 DestroyWindow(hwnd
);
4001 SetLastError(0xdeadbeef);
4002 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
4003 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4004 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4005 expect_menu(hwnd
, 1);
4006 expect_style(hwnd
, WS_CHILD
);
4007 expect_ex_style(hwnd
, 0);
4008 DestroyWindow(hwnd
);
4010 SetLastError(0xdeadbeef);
4011 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4012 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4013 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4014 expect_menu(hwnd
, 1);
4015 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4016 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4017 DestroyWindow(hwnd
);
4020 SetLastError(0xdeadbeef);
4021 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4022 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4023 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4024 expect_menu(hwnd
, hmenu
);
4025 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4026 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4027 DestroyWindow(hwnd
);
4028 SetLastError(0xdeadbeef);
4029 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4030 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4032 hmenu
= CreateMenu();
4034 SetLastError(0xdeadbeef);
4035 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4036 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4037 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4038 expect_menu(hwnd
, hmenu
);
4039 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4040 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4041 DestroyWindow(hwnd
);
4042 SetLastError(0xdeadbeef);
4043 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4044 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4046 hmenu
= CreateMenu();
4048 SetLastError(0xdeadbeef);
4049 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4050 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4051 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4052 expect_menu(hwnd
, hmenu
);
4053 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4054 expect_ex_style(hwnd
, 0);
4055 DestroyWindow(hwnd
);
4056 SetLastError(0xdeadbeef);
4057 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4058 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4060 hmenu
= CreateMenu();
4062 SetLastError(0xdeadbeef);
4063 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4064 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4065 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4066 expect_menu(hwnd
, hmenu
);
4067 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4068 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4069 DestroyWindow(hwnd
);
4070 SetLastError(0xdeadbeef);
4071 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4072 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4074 /* WS_CHILD | WS_POPUP */
4075 SetLastError(0xdeadbeef);
4076 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4077 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4078 ok(!hwnd
, "CreateWindowEx should fail\n");
4079 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4081 hmenu
= CreateMenu();
4083 SetLastError(0xdeadbeef);
4084 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4085 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4086 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4087 expect_menu(hwnd
, hmenu
);
4088 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4089 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4090 DestroyWindow(hwnd
);
4091 SetLastError(0xdeadbeef);
4092 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4093 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4095 SetLastError(0xdeadbeef);
4096 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4097 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4098 ok(!hwnd
, "CreateWindowEx should fail\n");
4099 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4101 hmenu
= CreateMenu();
4103 SetLastError(0xdeadbeef);
4104 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4105 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4106 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4107 expect_menu(hwnd
, hmenu
);
4108 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4109 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4110 DestroyWindow(hwnd
);
4111 SetLastError(0xdeadbeef);
4112 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4113 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4115 SetLastError(0xdeadbeef);
4116 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4117 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4118 ok(!hwnd
, "CreateWindowEx should fail\n");
4119 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4121 hmenu
= CreateMenu();
4123 SetLastError(0xdeadbeef);
4124 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4125 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4126 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4127 expect_menu(hwnd
, hmenu
);
4128 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4129 expect_ex_style(hwnd
, 0);
4130 DestroyWindow(hwnd
);
4131 SetLastError(0xdeadbeef);
4132 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4133 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4135 SetLastError(0xdeadbeef);
4136 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4137 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4138 ok(!hwnd
, "CreateWindowEx should fail\n");
4139 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4141 hmenu
= CreateMenu();
4143 SetLastError(0xdeadbeef);
4144 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4145 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4146 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4147 expect_menu(hwnd
, hmenu
);
4148 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4149 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4150 DestroyWindow(hwnd
);
4151 SetLastError(0xdeadbeef);
4152 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4153 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4155 /* test child window sizing */
4157 cls
.lpfnWndProc
= minmax_wnd_proc
;
4160 cls
.hInstance
= GetModuleHandle(0);
4162 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4163 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4164 cls
.lpszMenuName
= NULL
;
4165 cls
.lpszClassName
= "MinMax_WndClass";
4166 RegisterClass(&cls
);
4168 SetLastError(0xdeadbeef);
4169 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4170 0, 0, 100, 100, 0, 0, 0, NULL
);
4171 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4172 expect_menu(parent
, 0);
4173 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4174 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4176 memset(&minmax
, 0, sizeof(minmax
));
4177 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4178 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4179 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4180 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4181 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4183 GetWindowRect(parent
, &rc
);
4184 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4185 GetClientRect(parent
, &rc
);
4186 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4188 InflateRect(&rc
, 200, 200);
4189 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4191 SetLastError(0xdeadbeef);
4192 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4193 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4194 parent
, (HMENU
)1, 0, NULL
);
4195 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4196 expect_menu(hwnd
, 1);
4197 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4198 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4200 memset(&minmax
, 0, sizeof(minmax
));
4201 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4202 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4204 GetWindowRect(hwnd
, &rc
);
4205 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4206 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4207 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4208 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4209 DestroyWindow(hwnd
);
4211 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4212 cls
.lpszClassName
= "Sizes_WndClass";
4213 RegisterClass(&cls
);
4215 expected_cx
= expected_cy
= 200000;
4216 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4217 broken_rect
= expected_rect
;
4218 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4219 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4220 GetClientRect( hwnd
, &rc
);
4221 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4222 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4223 DestroyWindow(hwnd
);
4225 expected_cx
= expected_cy
= -10;
4226 SetRect( &expected_rect
, 0, 0, 0, 0 );
4227 broken_rect
= expected_rect
;
4228 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4229 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4230 GetClientRect( hwnd
, &rc
);
4231 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4232 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4233 DestroyWindow(hwnd
);
4235 expected_cx
= expected_cy
= -200000;
4236 SetRect( &expected_rect
, 0, 0, 0, 0 );
4237 broken_rect
= expected_rect
;
4238 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4239 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4240 GetClientRect( hwnd
, &rc
);
4241 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4242 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4243 DestroyWindow(hwnd
);
4245 /* we need a parent at 0,0 so that child coordinates match */
4246 DestroyWindow(parent
);
4247 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_POPUP
, 0, 0, 100, 100, 0, 0, 0, NULL
);
4248 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4251 expected_cy
= 0x7fffffff;
4252 SetRect( &expected_rect
, 10, 10, 110, 0x7fffffff );
4253 SetRect( &broken_rect
, 10, 10, 110, 0x7fffffffU
+ 10 );
4254 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 10, 10, 100, 0x7fffffff, parent
, 0, 0, NULL
);
4255 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4256 GetClientRect( hwnd
, &rc
);
4257 ok( rc
.right
== 100, "invalid rect right %u\n", rc
.right
);
4258 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4259 DestroyWindow(hwnd
);
4261 expected_cx
= 0x7fffffff;
4262 expected_cy
= 0x7fffffff;
4263 SetRect( &expected_rect
, 20, 10, 0x7fffffff, 0x7fffffff );
4264 SetRect( &broken_rect
, 20, 10, 0x7fffffffU
+ 20, 0x7fffffffU
+ 10 );
4265 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 20, 10, 0x7fffffff, 0x7fffffff, parent
, 0, 0, NULL
);
4266 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4267 GetClientRect( hwnd
, &rc
);
4268 ok( rc
.right
== 0x7fffffff - 20 || broken(rc
.right
== 0), "invalid rect right %u\n", rc
.right
);
4269 ok( rc
.bottom
== 0x7fffffff - 10 || broken(rc
.bottom
== 0), "invalid rect bottom %u\n", rc
.bottom
);
4270 DestroyWindow(hwnd
);
4272 /* top level window */
4273 expected_cx
= expected_cy
= 200000;
4274 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4275 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4276 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4277 GetClientRect( hwnd
, &rc
);
4278 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4279 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4280 DestroyWindow(hwnd
);
4282 DestroyWindow(parent
);
4284 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4285 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4289 #undef expect_ex_style
4292 /* function that remembers whether the system the test is running on sets the
4293 * last error for user32 functions to make the tests stricter */
4294 static int check_error(DWORD actual
, DWORD expected
)
4296 static int sets_last_error
= -1;
4297 if (sets_last_error
== -1)
4298 sets_last_error
= (actual
!= 0xdeadbeef);
4299 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4302 static void test_SetWindowLong(void)
4305 WNDPROC old_window_procW
;
4307 SetLastError(0xdeadbeef);
4308 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4309 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4310 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4311 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4313 SetLastError(0xdeadbeef);
4314 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4315 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4316 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4317 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4319 SetLastError(0xdeadbeef);
4320 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4321 ok((WNDPROC
)retval
== main_window_procA
,
4322 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4323 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4324 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4325 ok((WNDPROC
)retval
== main_window_procA
,
4326 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4327 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4329 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4330 SetLastError(0xdeadbeef);
4331 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4332 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4334 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4335 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4336 ok((WNDPROC
)retval
== old_window_procW
,
4337 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4338 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4340 /* set it back to ANSI */
4341 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4345 static void test_ShowWindow(void)
4352 SetRect(&rcMain
, 120, 120, 210, 210);
4354 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4355 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4356 WS_MAXIMIZEBOX
| WS_POPUP
,
4357 rcMain
.left
, rcMain
.top
,
4358 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4362 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4363 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4364 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4365 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4366 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4367 GetWindowRect(hwnd
, &rc
);
4368 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4369 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4370 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4372 ret
= ShowWindow(hwnd
, SW_SHOW
);
4373 ok(!ret
, "not expected ret: %lu\n", ret
);
4374 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4375 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4376 ok(style
& WS_VISIBLE
, "window should be visible\n");
4377 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4378 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4379 GetWindowRect(hwnd
, &rc
);
4380 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4381 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4382 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4384 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4385 ok(ret
, "not expected ret: %lu\n", ret
);
4386 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4387 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4388 ok(style
& WS_VISIBLE
, "window should be visible\n");
4389 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4390 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4391 GetWindowRect(hwnd
, &rc
);
4392 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4394 ShowWindow(hwnd
, SW_RESTORE
);
4395 ok(ret
, "not expected ret: %lu\n", ret
);
4396 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4397 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4398 ok(style
& WS_VISIBLE
, "window should be visible\n");
4399 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4400 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4401 GetWindowRect(hwnd
, &rc
);
4402 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4403 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4404 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4406 ret
= EnableWindow(hwnd
, FALSE
);
4407 ok(!ret
, "not expected ret: %lu\n", ret
);
4408 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4409 ok(style
& WS_DISABLED
, "window should be disabled\n");
4411 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4412 ok(!ret
, "not expected ret: %lu\n", ret
);
4413 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4414 ok(style
& WS_DISABLED
, "window should be disabled\n");
4415 ok(style
& WS_VISIBLE
, "window should be visible\n");
4416 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4417 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4418 GetWindowRect(hwnd
, &rc
);
4419 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4420 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4421 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4423 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4424 ok(!ret
, "not expected ret: %lu\n", ret
);
4425 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4426 ok(style
& WS_DISABLED
, "window should be disabled\n");
4427 ok(style
& WS_VISIBLE
, "window should be visible\n");
4428 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4429 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4430 GetWindowRect(hwnd
, &rc
);
4431 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4432 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4433 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4435 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4436 ok(ret
, "not expected ret: %lu\n", ret
);
4437 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4438 ok(style
& WS_DISABLED
, "window should be disabled\n");
4439 ok(style
& WS_VISIBLE
, "window should be visible\n");
4440 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4441 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4442 GetWindowRect(hwnd
, &rc
);
4443 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4445 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4446 ok(!ret
, "not expected ret: %lu\n", ret
);
4447 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4448 ok(style
& WS_DISABLED
, "window should be disabled\n");
4449 ok(style
& WS_VISIBLE
, "window should be visible\n");
4450 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4451 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4452 GetWindowRect(hwnd
, &rc
);
4453 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4455 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4456 ok(ret
, "not expected ret: %lu\n", ret
);
4457 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4458 ok(style
& WS_DISABLED
, "window should be disabled\n");
4459 ok(style
& WS_VISIBLE
, "window should be visible\n");
4460 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4461 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4462 GetWindowRect(hwnd
, &rc
);
4463 ok(EqualRect(&rcMain
, &rc
), "expected (%d,%d)-(%d,%d), got (%d,%d)-(%d,%d)\n",
4464 rcMain
.left
, rcMain
.top
, rcMain
.right
, rcMain
.bottom
,
4465 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4467 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4468 ok(!ret
, "not expected ret: %lu\n", ret
);
4469 ok(IsWindow(hwnd
), "window should exist\n");
4471 ret
= EnableWindow(hwnd
, TRUE
);
4472 ok(ret
, "not expected ret: %lu\n", ret
);
4474 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4475 ok(!ret
, "not expected ret: %lu\n", ret
);
4476 ok(!IsWindow(hwnd
), "window should not exist\n");
4479 static void test_gettext(void)
4482 LPCSTR clsname
= "gettexttest";
4486 memset( &cls
, 0, sizeof cls
);
4487 cls
.lpfnWndProc
= DefWindowProc
;
4488 cls
.lpszClassName
= clsname
;
4489 cls
.hInstance
= GetModuleHandle(NULL
);
4491 if (!RegisterClass( &cls
)) return;
4493 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4494 ok( hwnd
!= NULL
, "window was null\n");
4496 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4497 ok( r
== 0, "settext should return zero\n");
4499 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4500 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4502 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4503 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4505 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4506 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4508 DestroyWindow(hwnd
);
4509 UnregisterClass( clsname
, NULL
);
4513 static void test_GetUpdateRect(void)
4516 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4518 HWND hgrandparent
, hparent
, hchild
;
4520 static const char classNameA
[] = "GetUpdateRectClass";
4522 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4523 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4525 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4526 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4528 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4529 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4531 ShowWindow(hgrandparent
, SW_SHOW
);
4532 UpdateWindow(hgrandparent
);
4533 flush_events( TRUE
);
4535 ShowWindow(hchild
, SW_HIDE
);
4536 SetRect(&rc2
, 0, 0, 0, 0);
4537 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4538 ok(!ret
, "GetUpdateRect returned not empty region\n");
4539 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4540 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4541 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4543 SetRect(&rc2
, 10, 10, 40, 40);
4544 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4545 ok(ret
, "GetUpdateRect returned empty region\n");
4546 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4547 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4548 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4550 parent_wm_paint
= FALSE
;
4551 grandparent_wm_paint
= FALSE
;
4552 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4554 if (msg
.message
== WM_PAINT
)
4556 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4557 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4559 DispatchMessage(&msg
);
4561 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4562 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4564 DestroyWindow(hgrandparent
);
4567 cls
.lpfnWndProc
= DefWindowProcA
;
4570 cls
.hInstance
= GetModuleHandleA(0);
4572 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4573 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4574 cls
.lpszMenuName
= NULL
;
4575 cls
.lpszClassName
= classNameA
;
4577 if(!RegisterClassA(&cls
)) {
4578 trace("Register failed %d\n", GetLastError());
4582 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4583 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4585 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4586 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4588 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4589 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4591 ShowWindow(hgrandparent
, SW_SHOW
);
4592 UpdateWindow(hgrandparent
);
4593 flush_events( TRUE
);
4595 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4596 ok(!ret
, "GetUpdateRect returned not empty region\n");
4598 ShowWindow(hchild
, SW_HIDE
);
4600 SetRect(&rc2
, 0, 0, 0, 0);
4601 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4602 ok(!ret
, "GetUpdateRect returned not empty region\n");
4603 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4604 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4605 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4607 SetRect(&rc2
, 10, 10, 40, 40);
4608 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4609 ok(ret
, "GetUpdateRect returned empty region\n");
4610 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4611 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4612 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4614 parent_wm_paint
= FALSE
;
4615 grandparent_wm_paint
= FALSE
;
4616 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4618 if (msg
.message
== WM_PAINT
)
4620 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4621 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4623 DispatchMessage(&msg
);
4625 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4626 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4628 DestroyWindow(hgrandparent
);
4632 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4640 const int waitTime
= 2000;
4642 BeginPaint(hwnd
, &ps
);
4644 /* create and destroy window to create an exposed region on this window */
4645 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4646 10,10,50,50, NULL
, NULL
, 0, NULL
);
4649 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4651 ValidateRect(hwnd
, NULL
);
4652 EndPaint(hwnd
, &ps
);
4654 if(waitResult
!= WAIT_TIMEOUT
)
4656 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4657 ok(IsRectEmpty(&updateRect
), "Exposed rect should be empty\n");
4662 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4665 static void test_Expose(void)
4670 memset(&cls
, 0, sizeof(WNDCLASSA
));
4671 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4672 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4673 cls
.lpszClassName
= "TestExposeClass";
4674 atom
= RegisterClassA(&cls
);
4676 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4677 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4683 static void test_GetWindowModuleFileName(void)
4688 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4690 if (!pGetWindowModuleFileNameA
)
4692 skip("GetWindowModuleFileNameA is not available\n");
4696 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4699 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4700 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
4703 SetLastError(0xdeadbeef);
4704 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4705 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4708 SetLastError(0xdeadbeef);
4709 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, sizeof(buf2
));
4710 ok(ret2
, "GetWindowModuleFileNameA error %u\n", GetLastError());
4712 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
4713 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4715 hinst
= GetModuleHandle(0);
4717 SetLastError(0xdeadbeef);
4718 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4719 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4720 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4721 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4722 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4724 SetLastError(0xdeadbeef);
4725 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4726 ok(!ret2
, "GetModuleFileName should return 0\n");
4727 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4728 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4729 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4731 SetLastError(0xdeadbeef);
4732 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, ret1
- 2);
4733 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4734 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4735 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4736 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4738 SetLastError(0xdeadbeef);
4739 ret2
= pGetWindowModuleFileNameA(hwnd
, buf2
, 0);
4740 ok(!ret2
, "expected 0, got %u\n", ret2
);
4741 ok(GetLastError() == 0xdeadbeef /* XP */ ||
4742 GetLastError() == ERROR_INSUFFICIENT_BUFFER
, /* win2k3, vista */
4743 "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
4745 DestroyWindow(hwnd
);
4748 hwnd
= (HWND
)0xdeadbeef;
4749 SetLastError(0xdeadbeef);
4750 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4751 ok(!ret1
, "expected 0, got %u\n", ret1
);
4752 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4754 hwnd
= GetDesktopWindow();
4755 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4756 SetLastError(0xdeadbeef);
4757 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4758 ok(!ret1
, "expected 0, got %u\n", ret1
);
4760 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4761 ok(IsWindow(hwnd
), "got invalid tray window %p\n", hwnd
);
4762 SetLastError(0xdeadbeef);
4763 ret1
= pGetWindowModuleFileNameA(hwnd
, buf1
, sizeof(buf1
));
4764 ok(!ret1
, "expected 0, got %u\n", ret1
);
4767 static void test_hwnd_message(void)
4769 HWND parent
= 0, hwnd
, found
;
4772 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
| WS_VISIBLE
,
4773 100, 100, 200, 200, HWND_MESSAGE
, 0, 0, NULL
);
4776 win_skip("CreateWindowExA with parent HWND_MESSAGE failed\n");
4780 ok( !GetParent(hwnd
), "GetParent should return 0 for message only windows\n" );
4784 HWND root
, desktop
= GetDesktopWindow();
4786 parent
= pGetAncestor(hwnd
, GA_PARENT
);
4787 ok(parent
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message windows\n");
4788 ok(parent
!= desktop
, "GetAncestor(GA_PARENT) should not return desktop for message windows\n");
4789 root
= pGetAncestor(hwnd
, GA_ROOT
);
4790 ok(root
== hwnd
, "GetAncestor(GA_ROOT) should return hwnd for message windows\n");
4791 ok( !pGetAncestor(parent
, GA_PARENT
), "parent shouldn't have a parent\n" );
4792 trace("parent %p root %p desktop %p\n", parent
, root
, desktop
);
4793 if (!GetClassNameA( parent
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
4794 ok( !lstrcmpi( buffer
, "Message" ), "wrong parent class '%s'\n", buffer
);
4795 GetWindowRect( parent
, &rect
);
4796 ok( rect
.left
== 0 && rect
.right
== 100 && rect
.top
== 0 && rect
.bottom
== 100,
4797 "wrong parent rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4799 GetWindowRect( hwnd
, &rect
);
4800 ok( rect
.left
== 100 && rect
.right
== 300 && rect
.top
== 100 && rect
.bottom
== 300,
4801 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
4803 /* test FindWindow behavior */
4805 found
= FindWindowExA( 0, 0, 0, "message window" );
4806 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4807 SetLastError(0xdeadbeef);
4808 found
= FindWindowExA( GetDesktopWindow(), 0, 0, "message window" );
4809 ok( found
== 0, "found message window %p/%p\n", found
, hwnd
);
4810 ok( GetLastError() == 0xdeadbeef, "expected deadbeef, got %d\n", GetLastError() );
4813 found
= FindWindowExA( parent
, 0, 0, "message window" );
4814 ok( found
== hwnd
, "didn't find message window %p/%p\n", found
, hwnd
);
4817 /* test IsChild behavior */
4819 if (parent
) ok( !IsChild( parent
, hwnd
), "HWND_MESSAGE is child of top window\n" );
4821 /* test IsWindowVisible behavior */
4823 ok( !IsWindowVisible( hwnd
), "HWND_MESSAGE window is visible\n" );
4824 if (parent
) ok( !IsWindowVisible( parent
), "HWND_MESSAGE parent is visible\n" );
4826 DestroyWindow(hwnd
);
4829 static void test_layered_window(void)
4837 if (!pGetLayeredWindowAttributes
|| !pSetLayeredWindowAttributes
)
4839 win_skip( "layered windows not supported\n" );
4842 hwnd
= CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION
,
4843 100, 100, 200, 200, 0, 0, 0, NULL
);
4845 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4846 ok( !ret
, "GetLayeredWindowAttributes should fail on non-layered window\n" );
4847 ret
= pSetLayeredWindowAttributes( hwnd
, 0, 0, LWA_ALPHA
);
4848 ok( !ret
, "SetLayeredWindowAttributes should fail on non-layered window\n" );
4849 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4850 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4851 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4852 ret
= pSetLayeredWindowAttributes( hwnd
, 0x123456, 44, LWA_ALPHA
);
4853 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4854 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4855 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4856 ok( key
== 0x123456, "wrong color key %x\n", key
);
4857 ok( alpha
== 44, "wrong alpha %u\n", alpha
);
4858 ok( flags
== LWA_ALPHA
, "wrong flags %x\n", flags
);
4860 /* clearing WS_EX_LAYERED resets attributes */
4861 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
4862 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4863 ok( !ret
, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
4864 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4865 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4866 ok( !ret
, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
4867 ret
= pSetLayeredWindowAttributes( hwnd
, 0x654321, 22, LWA_COLORKEY
| LWA_ALPHA
);
4868 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4869 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4870 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4871 ok( key
== 0x654321, "wrong color key %x\n", key
);
4872 ok( alpha
== 22, "wrong alpha %u\n", alpha
);
4873 ok( flags
== (LWA_COLORKEY
| LWA_ALPHA
), "wrong flags %x\n", flags
);
4875 ret
= pSetLayeredWindowAttributes( hwnd
, 0x888888, 33, LWA_COLORKEY
);
4876 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4878 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4879 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4880 ok( key
== 0x888888, "wrong color key %x\n", key
);
4881 /* alpha not changed on vista if LWA_ALPHA is not set */
4882 ok( alpha
== 22 || alpha
== 33, "wrong alpha %u\n", alpha
);
4883 ok( flags
== LWA_COLORKEY
, "wrong flags %x\n", flags
);
4885 /* color key always changed */
4886 ret
= pSetLayeredWindowAttributes( hwnd
, 0x999999, 44, 0 );
4887 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4889 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4890 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4891 ok( key
== 0x999999, "wrong color key %x\n", key
);
4892 ok( alpha
== 22 || alpha
== 44, "wrong alpha %u\n", alpha
);
4893 ok( flags
== 0, "wrong flags %x\n", flags
);
4895 /* default alpha is 0 */
4896 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) & ~WS_EX_LAYERED
);
4897 SetWindowLong( hwnd
, GWL_EXSTYLE
, GetWindowLong(hwnd
, GWL_EXSTYLE
) | WS_EX_LAYERED
);
4898 ret
= pSetLayeredWindowAttributes( hwnd
, 0x222222, 55, 0 );
4899 ok( ret
, "SetLayeredWindowAttributes should succeed on layered window\n" );
4900 ret
= pGetLayeredWindowAttributes( hwnd
, &key
, &alpha
, &flags
);
4901 ok( ret
, "GetLayeredWindowAttributes should succeed on layered window\n" );
4902 ok( key
== 0x222222, "wrong color key %x\n", key
);
4903 ok( alpha
== 0 || alpha
== 55, "wrong alpha %u\n", alpha
);
4904 ok( flags
== 0, "wrong flags %x\n", flags
);
4906 DestroyWindow( hwnd
);
4911 HMODULE user32
= GetModuleHandleA( "user32.dll" );
4912 pGetAncestor
= (void *)GetProcAddress( user32
, "GetAncestor" );
4913 pGetWindowInfo
= (void *)GetProcAddress( user32
, "GetWindowInfo" );
4914 pGetWindowModuleFileNameA
= (void *)GetProcAddress( user32
, "GetWindowModuleFileNameA" );
4915 pGetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "GetLayeredWindowAttributes" );
4916 pSetLayeredWindowAttributes
= (void *)GetProcAddress( user32
, "SetLayeredWindowAttributes" );
4918 if (!RegisterWindowClasses()) assert(0);
4920 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4923 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4924 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4925 WS_MAXIMIZEBOX
| WS_POPUP
,
4927 0, 0, GetModuleHandle(0), NULL
);
4928 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4929 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4930 WS_MAXIMIZEBOX
| WS_POPUP
,
4932 0, 0, GetModuleHandle(0), NULL
);
4934 assert( hwndMain2
);
4936 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4938 /* Add the tests below this line */
4939 test_hwnd_message();
4940 test_nonclient_area(hwndMain
);
4942 test_GetWindowModuleFileName();
4945 test_capture_3(hwndMain
, hwndMain2
);
4947 test_CreateWindow();
4948 test_parent_owner();
4953 test_SetWindowPos(hwndMain
);
4954 test_SetMenu(hwndMain
);
4955 test_SetFocus(hwndMain
);
4956 test_SetActiveWindow(hwndMain
);
4957 test_SetForegroundWindow(hwndMain
);
4959 test_children_zorder(hwndMain
);
4960 test_popup_zorder(hwndMain2
, hwndMain
);
4961 test_keyboard_input(hwndMain
);
4962 test_mouse_input(hwndMain
);
4963 test_validatergn(hwndMain
);
4964 test_nccalcscroll( hwndMain
);
4965 test_scrollvalidate( hwndMain
);
4966 test_scrolldc( hwndMain
);
4968 test_IsWindowUnicode();
4969 test_vis_rgn(hwndMain
);
4971 test_AdjustWindowRect();
4972 test_window_styles();
4975 test_SetWindowLong();
4978 test_GetUpdateRect();
4980 test_layered_window();
4982 test_shell_window();
4984 /* add the tests above this line */
4985 UnhookWindowsHookEx(hhook
);