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
*);
50 static BOOL test_lbuttondown_flag
;
51 static HWND hwndMessage
;
52 static HWND hwndMain
, hwndMain2
;
55 static const char* szAWRClass
= "Winsize";
59 #define COUNTOF(arr) (sizeof(arr)/sizeof(arr[0]))
61 /* try to make sure pending X events have been processed before continuing */
62 static void flush_events( BOOL remove_messages
)
67 DWORD time
= GetTickCount() + diff
;
71 if (MsgWaitForMultipleObjects( 0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
) break;
73 while (PeekMessage( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessage( &msg
);
74 diff
= time
- GetTickCount();
79 /* check the values returned by the various parent/owner functions on a given window */
80 static void check_parents( HWND hwnd
, HWND ga_parent
, HWND gwl_parent
, HWND get_parent
,
81 HWND gw_owner
, HWND ga_root
, HWND ga_root_owner
)
87 res
= pGetAncestor( hwnd
, GA_PARENT
);
88 ok( res
== ga_parent
, "Wrong result for GA_PARENT %p expected %p\n", res
, ga_parent
);
90 res
= (HWND
)GetWindowLongPtrA( hwnd
, GWLP_HWNDPARENT
);
91 ok( res
== gwl_parent
, "Wrong result for GWL_HWNDPARENT %p expected %p\n", res
, gwl_parent
);
92 res
= GetParent( hwnd
);
93 ok( res
== get_parent
, "Wrong result for GetParent %p expected %p\n", res
, get_parent
);
94 res
= GetWindow( hwnd
, GW_OWNER
);
95 ok( res
== gw_owner
, "Wrong result for GW_OWNER %p expected %p\n", res
, gw_owner
);
98 res
= pGetAncestor( hwnd
, GA_ROOT
);
99 ok( res
== ga_root
, "Wrong result for GA_ROOT %p expected %p\n", res
, ga_root
);
100 res
= pGetAncestor( hwnd
, GA_ROOTOWNER
);
101 ok( res
== ga_root_owner
, "Wrong result for GA_ROOTOWNER %p expected %p\n", res
, ga_root_owner
);
105 static BOOL CALLBACK
EnumChildProc( HWND hwndChild
, LPARAM lParam
)
108 trace("EnumChildProc on %p\n", hwndChild
);
109 if (*(LPINT
)lParam
> 1) return FALSE
;
113 /* will search for the given window */
114 static BOOL CALLBACK
EnumChildProc1( HWND hwndChild
, LPARAM lParam
)
116 trace("EnumChildProc1 on %p\n", hwndChild
);
117 if ((HWND
)lParam
== hwndChild
) return FALSE
;
121 static HWND
create_tool_window( LONG style
, HWND parent
)
123 HWND ret
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1", style
,
124 0, 0, 100, 100, parent
, 0, 0, NULL
);
125 ok( ret
!= 0, "Creation failed\n" );
129 /* test parent and owner values for various combinations */
130 static void test_parent_owner(void)
133 HWND test
, owner
, ret
;
134 HWND desktop
= GetDesktopWindow();
135 HWND child
= create_tool_window( WS_CHILD
, hwndMain
);
138 trace( "main window %p main2 %p desktop %p child %p\n", hwndMain
, hwndMain2
, desktop
, child
);
140 /* child without parent, should fail */
141 SetLastError(0xdeadbeef);
142 test
= CreateWindowExA(0, "ToolWindowClass", "Tool window 1",
143 WS_CHILD
, 0, 0, 100, 100, 0, 0, 0, NULL
);
144 ok( GetLastError() == ERROR_TLW_WITH_WSCHILD
, "CreateWindowExA should call SetLastError\n" );
145 ok( !test
, "WS_CHILD without parent created\n" );
148 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
149 style
= GetWindowLongA( desktop
, GWL_STYLE
);
150 ok( !SetWindowLongA( desktop
, GWL_STYLE
, WS_POPUP
), "Set GWL_STYLE on desktop succeeded\n" );
151 ok( !SetWindowLongA( desktop
, GWL_STYLE
, 0 ), "Set GWL_STYLE on desktop succeeded\n" );
152 ok( GetWindowLongA( desktop
, GWL_STYLE
) == style
, "Desktop style changed\n" );
154 /* normal child window */
155 test
= create_tool_window( WS_CHILD
, hwndMain
);
156 trace( "created child %p\n", test
);
157 check_parents( test
, hwndMain
, hwndMain
, hwndMain
, 0, hwndMain
, hwndMain
);
158 SetWindowLongA( test
, GWL_STYLE
, 0 );
159 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
160 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
161 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
162 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
|WS_CHILD
);
163 check_parents( test
, hwndMain
, hwndMain
, 0, 0, hwndMain
, test
);
164 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
165 DestroyWindow( test
);
167 /* normal child window with WS_MAXIMIZE */
168 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
169 DestroyWindow( test
);
171 /* normal child window with WS_THICKFRAME */
172 test
= create_tool_window( WS_CHILD
| WS_THICKFRAME
, hwndMain
);
173 DestroyWindow( test
);
175 /* popup window with WS_THICKFRAME */
176 test
= create_tool_window( WS_POPUP
| WS_THICKFRAME
, hwndMain
);
177 DestroyWindow( test
);
179 /* child of desktop */
180 test
= create_tool_window( WS_CHILD
, desktop
);
181 trace( "created child of desktop %p\n", test
);
182 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
183 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
184 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
185 SetWindowLongA( test
, GWL_STYLE
, 0 );
186 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
187 DestroyWindow( test
);
189 /* child of desktop with WS_MAXIMIZE */
190 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, desktop
);
191 DestroyWindow( test
);
193 /* child of desktop with WS_MINIMIZE */
194 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, desktop
);
195 DestroyWindow( test
);
198 test
= create_tool_window( WS_CHILD
, child
);
199 trace( "created child of child %p\n", test
);
200 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
201 SetWindowLongA( test
, GWL_STYLE
, 0 );
202 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
203 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
204 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
205 DestroyWindow( test
);
207 /* child of child with WS_MAXIMIZE */
208 test
= create_tool_window( WS_CHILD
| WS_MAXIMIZE
, child
);
209 DestroyWindow( test
);
211 /* child of child with WS_MINIMIZE */
212 test
= create_tool_window( WS_CHILD
| WS_MINIMIZE
, child
);
213 DestroyWindow( test
);
215 /* not owned top-level window */
216 test
= create_tool_window( 0, 0 );
217 trace( "created top-level %p\n", test
);
218 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
219 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
220 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
221 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
222 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
223 DestroyWindow( test
);
225 /* not owned top-level window with WS_MAXIMIZE */
226 test
= create_tool_window( WS_MAXIMIZE
, 0 );
227 DestroyWindow( test
);
229 /* owned top-level window */
230 test
= create_tool_window( 0, hwndMain
);
231 trace( "created owned top-level %p\n", test
);
232 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
233 SetWindowLongA( test
, GWL_STYLE
, WS_POPUP
);
234 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
235 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
236 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
237 DestroyWindow( test
);
239 /* owned top-level window with WS_MAXIMIZE */
240 test
= create_tool_window( WS_MAXIMIZE
, hwndMain
);
241 DestroyWindow( test
);
243 /* not owned popup */
244 test
= create_tool_window( WS_POPUP
, 0 );
245 trace( "created popup %p\n", test
);
246 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
247 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
248 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
249 SetWindowLongA( test
, GWL_STYLE
, 0 );
250 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
251 DestroyWindow( test
);
253 /* not owned popup with WS_MAXIMIZE */
254 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, 0 );
255 DestroyWindow( test
);
258 test
= create_tool_window( WS_POPUP
, hwndMain
);
259 trace( "created owned popup %p\n", test
);
260 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
261 SetWindowLongA( test
, GWL_STYLE
, WS_CHILD
);
262 check_parents( test
, desktop
, hwndMain
, desktop
, hwndMain
, test
, desktop
);
263 SetWindowLongA( test
, GWL_STYLE
, 0 );
264 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
265 DestroyWindow( test
);
267 /* owned popup with WS_MAXIMIZE */
268 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, hwndMain
);
269 DestroyWindow( test
);
271 /* top-level window owned by child (same as owned by top-level) */
272 test
= create_tool_window( 0, child
);
273 trace( "created top-level owned by child %p\n", test
);
274 check_parents( test
, desktop
, hwndMain
, 0, hwndMain
, test
, test
);
275 DestroyWindow( test
);
277 /* top-level window owned by child (same as owned by top-level) with WS_MAXIMIZE */
278 test
= create_tool_window( WS_MAXIMIZE
, child
);
279 DestroyWindow( test
);
281 /* popup owned by desktop (same as not owned) */
282 test
= create_tool_window( WS_POPUP
, desktop
);
283 trace( "created popup owned by desktop %p\n", test
);
284 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
285 DestroyWindow( test
);
287 /* popup owned by desktop (same as not owned) with WS_MAXIMIZE */
288 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, desktop
);
289 DestroyWindow( test
);
291 /* popup owned by child (same as owned by top-level) */
292 test
= create_tool_window( WS_POPUP
, child
);
293 trace( "created popup owned by child %p\n", test
);
294 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
295 DestroyWindow( test
);
297 /* popup owned by child (same as owned by top-level) with WS_MAXIMIZE */
298 test
= create_tool_window( WS_POPUP
| WS_MAXIMIZE
, child
);
299 DestroyWindow( test
);
301 /* not owned popup with WS_CHILD (same as WS_POPUP only) */
302 test
= create_tool_window( WS_POPUP
| WS_CHILD
, 0 );
303 trace( "created WS_CHILD popup %p\n", test
);
304 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
305 DestroyWindow( test
);
307 /* not owned popup with WS_CHILD | WS_MAXIMIZE (same as WS_POPUP only) */
308 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, 0 );
309 DestroyWindow( test
);
311 /* owned popup with WS_CHILD (same as WS_POPUP only) */
312 test
= create_tool_window( WS_POPUP
| WS_CHILD
, hwndMain
);
313 trace( "created owned WS_CHILD popup %p\n", test
);
314 check_parents( test
, desktop
, hwndMain
, hwndMain
, hwndMain
, test
, hwndMain
);
315 DestroyWindow( test
);
317 /* owned popup with WS_CHILD (same as WS_POPUP only) with WS_MAXIMIZE */
318 test
= create_tool_window( WS_POPUP
| WS_CHILD
| WS_MAXIMIZE
, hwndMain
);
319 DestroyWindow( test
);
321 /******************** parent changes *************************/
322 trace( "testing parent changes\n" );
325 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
328 /* this test succeeds on NT but crashes on win9x systems */
329 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
330 ok( !ret
, "Set GWL_HWNDPARENT succeeded on desktop\n" );
331 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
332 ok( !SetParent( desktop
, hwndMain
), "SetParent succeeded on desktop\n" );
333 check_parents( desktop
, 0, 0, 0, 0, 0, 0 );
335 /* normal child window */
336 test
= create_tool_window( WS_CHILD
, hwndMain
);
337 trace( "created child %p\n", test
);
339 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
340 ok( ret
== hwndMain
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain
);
341 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
343 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
344 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
345 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
347 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)desktop
);
348 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
349 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
351 /* window is now child of desktop so GWLP_HWNDPARENT changes owner from now on */
352 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
353 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
354 check_parents( test
, desktop
, child
, desktop
, child
, test
, desktop
);
356 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
357 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
358 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
359 DestroyWindow( test
);
361 /* not owned top-level window */
362 test
= create_tool_window( 0, 0 );
363 trace( "created top-level %p\n", test
);
365 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
366 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
367 check_parents( test
, desktop
, hwndMain2
, 0, hwndMain2
, test
, test
);
369 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
370 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
371 check_parents( test
, desktop
, child
, 0, child
, test
, test
);
373 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
374 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
375 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
376 DestroyWindow( test
);
378 /* not owned popup */
379 test
= create_tool_window( WS_POPUP
, 0 );
380 trace( "created popup %p\n", test
);
382 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)hwndMain2
);
383 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
384 check_parents( test
, desktop
, hwndMain2
, hwndMain2
, hwndMain2
, test
, hwndMain2
);
386 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (LONG_PTR
)child
);
387 ok( ret
== hwndMain2
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, hwndMain2
);
388 check_parents( test
, desktop
, child
, child
, child
, test
, hwndMain
);
390 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, 0 );
391 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
392 check_parents( test
, desktop
, 0, 0, 0, test
, test
);
393 DestroyWindow( test
);
395 /* normal child window */
396 test
= create_tool_window( WS_CHILD
, hwndMain
);
397 trace( "created child %p\n", test
);
399 ret
= SetParent( test
, desktop
);
400 ok( ret
== hwndMain
, "SetParent return value %p expected %p\n", ret
, hwndMain
);
401 check_parents( test
, desktop
, 0, desktop
, 0, test
, desktop
);
403 ret
= SetParent( test
, child
);
404 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
405 check_parents( test
, child
, child
, child
, 0, hwndMain
, hwndMain
);
407 ret
= SetParent( test
, hwndMain2
);
408 ok( ret
== child
, "SetParent return value %p expected %p\n", ret
, child
);
409 check_parents( test
, hwndMain2
, hwndMain2
, hwndMain2
, 0, hwndMain2
, hwndMain2
);
410 DestroyWindow( test
);
412 /* not owned top-level window */
413 test
= create_tool_window( 0, 0 );
414 trace( "created top-level %p\n", test
);
416 ret
= SetParent( test
, child
);
417 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
418 check_parents( test
, child
, child
, 0, 0, hwndMain
, test
);
419 DestroyWindow( test
);
422 test
= create_tool_window( WS_POPUP
, hwndMain2
);
423 trace( "created owned popup %p\n", test
);
425 ret
= SetParent( test
, child
);
426 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
427 check_parents( test
, child
, child
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
429 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)hwndMain
);
430 ok( ret
== child
, "GWL_HWNDPARENT return value %p expected %p\n", ret
, child
);
431 check_parents( test
, hwndMain
, hwndMain
, hwndMain2
, hwndMain2
, hwndMain
, hwndMain2
);
432 DestroyWindow( test
);
434 /**************** test owner destruction *******************/
436 /* owned child popup */
437 owner
= create_tool_window( 0, 0 );
438 test
= create_tool_window( WS_POPUP
, owner
);
439 trace( "created owner %p and popup %p\n", owner
, test
);
440 ret
= SetParent( test
, child
);
441 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
442 check_parents( test
, child
, child
, owner
, owner
, hwndMain
, owner
);
443 /* window is now child of 'child' but owned by 'owner' */
444 DestroyWindow( owner
);
445 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
446 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
447 * while Win95, Win2k, WinXP do.
449 /*check_parents( test, child, child, owner, owner, hwndMain, owner );*/
450 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
453 /* owned top-level popup */
454 owner
= create_tool_window( 0, 0 );
455 test
= create_tool_window( WS_POPUP
, owner
);
456 trace( "created owner %p and popup %p\n", owner
, test
);
457 check_parents( test
, desktop
, owner
, owner
, owner
, test
, owner
);
458 DestroyWindow( owner
);
459 ok( !IsWindow(test
), "Window %p not destroyed by owner destruction\n", test
);
461 /* top-level popup owned by child */
462 owner
= create_tool_window( WS_CHILD
, hwndMain2
);
463 test
= create_tool_window( WS_POPUP
, 0 );
464 trace( "created owner %p and popup %p\n", owner
, test
);
465 ret
= (HWND
)SetWindowLongPtrA( test
, GWLP_HWNDPARENT
, (ULONG_PTR
)owner
);
466 ok( ret
== 0, "GWL_HWNDPARENT return value %p expected 0\n", ret
);
467 check_parents( test
, desktop
, owner
, owner
, owner
, test
, hwndMain2
);
468 DestroyWindow( owner
);
469 ok( IsWindow(test
), "Window %p destroyed by owner destruction\n", test
);
470 ok( !IsWindow(owner
), "Owner %p not destroyed\n", owner
);
471 /* Win98 doesn't pass this test. It doesn't allow a destroyed owner,
472 * while Win95, Win2k, WinXP do.
474 /*check_parents( test, desktop, owner, owner, owner, test, owner );*/
478 DestroyWindow(child
);
481 owner
= create_tool_window( WS_OVERLAPPED
, 0 );
482 test
= create_tool_window( WS_POPUP
, desktop
);
484 ok( !GetWindow( test
, GW_OWNER
), "Wrong owner window\n" );
486 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
487 "EnumChildWindows should have returned FALSE\n" );
488 ok( numChildren
== 0, "numChildren should be 0 got %d\n", numChildren
);
490 SetWindowLongA( test
, GWL_STYLE
, (GetWindowLongA( test
, GWL_STYLE
) & ~WS_POPUP
) | WS_CHILD
);
491 ret
= SetParent( test
, owner
);
492 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
495 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
496 "EnumChildWindows should have returned TRUE\n" );
497 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
499 child
= create_tool_window( WS_CHILD
, owner
);
501 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
502 "EnumChildWindows should have returned FALSE\n" );
503 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
504 DestroyWindow( child
);
506 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, owner
);
507 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
509 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
510 "EnumChildWindows should have returned TRUE\n" );
511 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
513 ret
= SetParent( child
, owner
);
514 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
515 ok( ret
== desktop
, "SetParent return value %p expected %p\n", ret
, desktop
);
517 ok( !EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
518 "EnumChildWindows should have returned FALSE\n" );
519 ok( numChildren
== 2, "numChildren should be 2 got %d\n", numChildren
);
521 ret
= SetParent( child
, NULL
);
522 ok( GetWindow( child
, GW_OWNER
) == owner
, "Wrong owner window\n" );
523 ok( ret
== owner
, "SetParent return value %p expected %p\n", ret
, owner
);
525 ok( EnumChildWindows( owner
, EnumChildProc
, (LPARAM
)&numChildren
),
526 "EnumChildWindows should have returned TRUE\n" );
527 ok( numChildren
== 1, "numChildren should be 1 got %d\n", numChildren
);
529 /* even GW_OWNER == owner it's still a desktop's child */
530 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
531 "EnumChildWindows should have found %p and returned FALSE\n", child
);
533 DestroyWindow( child
);
534 child
= create_tool_window( WS_VISIBLE
| WS_OVERLAPPEDWINDOW
, NULL
);
536 ok( !EnumChildWindows( desktop
, EnumChildProc1
, (LPARAM
)child
),
537 "EnumChildWindows should have found %p and returned FALSE\n", child
);
539 DestroyWindow( child
);
540 DestroyWindow( test
);
541 DestroyWindow( owner
);
545 static LRESULT WINAPI
main_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
549 case WM_GETMINMAXINFO
:
551 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
553 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
554 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
555 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
556 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
557 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
558 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
559 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
560 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
561 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
564 case WM_WINDOWPOSCHANGING
:
566 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
567 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
568 trace("main: WM_WINDOWPOSCHANGING\n");
569 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
570 winpos
->hwnd
, winpos
->hwndInsertAfter
,
571 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
572 if (!(winpos
->flags
& SWP_NOMOVE
))
574 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
575 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
577 /* Win9x does not fixup cx/xy for WM_WINDOWPOSCHANGING */
578 if (!(winpos
->flags
& SWP_NOSIZE
) && !is_win9x
)
580 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
581 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
585 case WM_WINDOWPOSCHANGED
:
588 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
589 trace("main: WM_WINDOWPOSCHANGED\n");
590 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
591 winpos
->hwnd
, winpos
->hwndInsertAfter
,
592 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
593 ok(winpos
->x
>= -32768 && winpos
->x
<= 32767, "bad winpos->x %d\n", winpos
->x
);
594 ok(winpos
->y
>= -32768 && winpos
->y
<= 32767, "bad winpos->y %d\n", winpos
->y
);
596 ok(winpos
->cx
>= 0 && winpos
->cx
<= 32767, "bad winpos->cx %d\n", winpos
->cx
);
597 ok(winpos
->cy
>= 0 && winpos
->cy
<= 32767, "bad winpos->cy %d\n", winpos
->cy
);
599 GetWindowRect(hwnd
, &rc1
);
600 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
601 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
602 /* note: winpos coordinates are relative to parent */
603 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
604 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
607 /* Uncomment this once the test succeeds in all cases */
608 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
611 GetClientRect(hwnd
, &rc2
);
612 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
613 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
614 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
615 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
620 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
621 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
623 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
624 if (got_getminmaxinfo
)
625 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
627 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
628 ok(got_getminmaxinfo
, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
630 ok(!got_getminmaxinfo
, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
634 if (test_lbuttondown_flag
)
636 ShowWindow((HWND
)wparam
, SW_SHOW
);
637 flush_events( FALSE
);
642 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
645 static LRESULT WINAPI
tool_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
649 case WM_GETMINMAXINFO
:
651 MINMAXINFO
* minmax
= (MINMAXINFO
*)lparam
;
653 trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd
, wparam
, lparam
);
654 trace("ptReserved (%d,%d), ptMaxSize (%d,%d), ptMaxPosition (%d,%d)\n"
655 " ptMinTrackSize (%d,%d), ptMaxTrackSize (%d,%d)\n",
656 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
657 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
658 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
659 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
660 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
661 SetWindowLongPtrA(hwnd
, GWLP_USERDATA
, 0x20031021);
666 BOOL got_getminmaxinfo
= GetWindowLongPtrA(hwnd
, GWLP_USERDATA
) == 0x20031021;
667 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
669 trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd
, cs
->hwndParent
, cs
->style
);
670 if (got_getminmaxinfo
)
671 trace("%p got WM_GETMINMAXINFO\n", hwnd
);
673 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
674 ok(got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
676 ok(!got_getminmaxinfo
, "tool: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
681 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
684 static BOOL
RegisterWindowClasses(void)
688 cls
.style
= CS_DBLCLKS
;
689 cls
.lpfnWndProc
= main_window_procA
;
692 cls
.hInstance
= GetModuleHandleA(0);
694 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
695 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
696 cls
.lpszMenuName
= NULL
;
697 cls
.lpszClassName
= "MainWindowClass";
699 if(!RegisterClassA(&cls
)) return FALSE
;
702 cls
.lpfnWndProc
= tool_window_procA
;
705 cls
.hInstance
= GetModuleHandleA(0);
707 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
708 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
709 cls
.lpszMenuName
= NULL
;
710 cls
.lpszClassName
= "ToolWindowClass";
712 if(!RegisterClassA(&cls
)) return FALSE
;
717 static void verify_window_info(HWND hwnd
, const WINDOWINFO
*info
)
719 RECT rcWindow
, rcClient
;
722 ok(IsWindow(hwnd
), "bad window handle\n");
724 GetWindowRect(hwnd
, &rcWindow
);
725 ok(EqualRect(&rcWindow
, &info
->rcWindow
), "wrong rcWindow\n");
727 GetClientRect(hwnd
, &rcClient
);
728 /* translate to screen coordinates */
729 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rcClient
, 2);
730 ok(EqualRect(&rcClient
, &info
->rcClient
), "wrong rcClient\n");
732 ok(info
->dwStyle
== (DWORD
)GetWindowLongA(hwnd
, GWL_STYLE
),
733 "wrong dwStyle: %08x != %08x\n", info
->dwStyle
, GetWindowLongA(hwnd
, GWL_STYLE
));
734 /* Windows reports a not documented exstyle 0x800 in WINDOWINFO, but
735 * doesn't return it in GetWindowLong(hwnd, GWL_EXSTYLE).
737 ok((info
->dwExStyle
& ~0x800) == (DWORD
)GetWindowLongA(hwnd
, GWL_EXSTYLE
),
738 "wrong dwExStyle: %08x != %08x\n", info
->dwExStyle
, GetWindowLongA(hwnd
, GWL_EXSTYLE
));
739 status
= (GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0;
740 ok(info
->dwWindowStatus
== status
, "wrong dwWindowStatus: %04x != %04x\n",
741 info
->dwWindowStatus
, status
);
743 trace("rcWindow: %d,%d - %d,%d\n", rcWindow
.left
, rcWindow
.top
, rcWindow
.right
, rcWindow
.bottom
);
744 trace("rcClient: %d,%d - %d,%d\n", rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
746 /* win2k and XP return broken border info in GetWindowInfo most of
747 * the time, so there is no point in testing it.
751 ok(info
->cxWindowBorders
== (unsigned)(rcClient
.left
- rcWindow
.left
),
752 "wrong cxWindowBorders %d != %d\n", info
->cxWindowBorders
, rcClient
.left
- rcWindow
.left
);
753 border
= min(rcWindow
.bottom
- rcClient
.bottom
, rcClient
.top
- rcWindow
.top
);
754 ok(info
->cyWindowBorders
== border
,
755 "wrong cyWindowBorders %d != %d\n", info
->cyWindowBorders
, border
);
757 ok(info
->atomWindowType
== GetClassLongA(hwnd
, GCW_ATOM
), "wrong atomWindowType\n");
758 ok(info
->wCreatorVersion
== 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
759 info
->wCreatorVersion
== 0x0500 /* Vista */,
760 "wrong wCreatorVersion %04x\n", info
->wCreatorVersion
);
763 static void FixedAdjustWindowRectEx(RECT
* rc
, LONG style
, BOOL menu
, LONG exstyle
)
765 AdjustWindowRectEx(rc
, style
, menu
, exstyle
);
766 /* AdjustWindowRectEx does not include scroll bars */
767 if (style
& WS_VSCROLL
)
769 if(exstyle
& WS_EX_LEFTSCROLLBAR
)
770 rc
->left
-= GetSystemMetrics(SM_CXVSCROLL
);
772 rc
->right
+= GetSystemMetrics(SM_CXVSCROLL
);
774 if (style
& WS_HSCROLL
)
775 rc
->bottom
+= GetSystemMetrics(SM_CYHSCROLL
);
778 static void test_nonclient_area(HWND hwnd
)
780 DWORD style
, exstyle
;
781 RECT rc_window
, rc_client
, rc
;
783 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
785 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
786 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
787 menu
= !(style
& WS_CHILD
) && GetMenu(hwnd
) != 0;
789 GetWindowRect(hwnd
, &rc_window
);
790 trace("window: (%d,%d)-(%d,%d)\n", rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
791 GetClientRect(hwnd
, &rc_client
);
792 trace("client: (%d,%d)-(%d,%d)\n", rc_client
.left
, rc_client
.top
, rc_client
.right
, rc_client
.bottom
);
794 /* avoid some cases when things go wrong */
795 if (IsRectEmpty(&rc_window
) || IsRectEmpty(&rc_client
) ||
796 rc_window
.right
> 32768 || rc_window
.bottom
> 32768) return;
798 CopyRect(&rc
, &rc_client
);
799 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc
, 2);
800 FixedAdjustWindowRectEx(&rc
, style
, menu
, exstyle
);
802 trace("calc window: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
803 ok(EqualRect(&rc
, &rc_window
), "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
806 CopyRect(&rc
, &rc_window
);
807 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
808 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
809 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
810 ok(EqualRect(&rc
, &rc_client
), "client rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
812 /* Win9x doesn't like WM_NCCALCSIZE with synthetic data and crashes */;
816 /* and now test AdjustWindowRectEx and WM_NCCALCSIZE on synthetic data */
817 SetRect(&rc_client
, 0, 0, 250, 150);
818 CopyRect(&rc_window
, &rc_client
);
819 MapWindowPoints(hwnd
, 0, (LPPOINT
)&rc_window
, 2);
820 FixedAdjustWindowRectEx(&rc_window
, style
, menu
, exstyle
);
821 trace("calc window: (%d,%d)-(%d,%d)\n",
822 rc_window
.left
, rc_window
.top
, rc_window
.right
, rc_window
.bottom
);
824 CopyRect(&rc
, &rc_window
);
825 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc
);
826 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc
, 2);
827 trace("calc client: (%d,%d)-(%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
828 ok(EqualRect(&rc
, &rc_client
), "synthetic rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d\n", style
, exstyle
, menu
);
831 static LRESULT CALLBACK
cbt_hook_proc(int nCode
, WPARAM wParam
, LPARAM lParam
)
833 static const char *CBT_code_name
[10] = {
844 const char *code_name
= (nCode
>= 0 && nCode
<= HCBT_SETFOCUS
) ? CBT_code_name
[nCode
] : "Unknown";
846 trace("CBT: %d (%s), %08lx, %08lx\n", nCode
, code_name
, wParam
, lParam
);
848 /* on HCBT_DESTROYWND window state is undefined */
849 if (nCode
!= HCBT_DESTROYWND
&& IsWindow((HWND
)wParam
))
855 /* Win98 actually does check the info.cbSize and doesn't allow
856 * it to be anything except sizeof(WINDOWINFO), while Win95, Win2k,
857 * WinXP do not check it at all.
859 info
.cbSize
= sizeof(WINDOWINFO
);
860 ok(pGetWindowInfo((HWND
)wParam
, &info
), "GetWindowInfo should not fail\n");
861 verify_window_info((HWND
)wParam
, &info
);
869 static const RECT rc_null
;
872 CBT_CREATEWNDA
*createwnd
= (CBT_CREATEWNDA
*)lParam
;
873 trace("HCBT_CREATEWND: hwnd %p, parent %p, style %08x\n",
874 (HWND
)wParam
, createwnd
->lpcs
->hwndParent
, createwnd
->lpcs
->style
);
875 ok(createwnd
->hwndInsertAfter
== HWND_TOP
, "hwndInsertAfter should be always HWND_TOP\n");
877 /* WS_VISIBLE should be turned off yet */
878 style
= createwnd
->lpcs
->style
& ~WS_VISIBLE
;
879 ok(style
== GetWindowLongA((HWND
)wParam
, GWL_STYLE
),
880 "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n",
881 GetWindowLongA((HWND
)wParam
, GWL_STYLE
), style
);
885 /* Uncomment this once the test succeeds in all cases */
886 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
888 ok(GetParent((HWND
)wParam
) == hwndMessage
,
889 "wrong result from GetParent %p: message window %p\n",
890 GetParent((HWND
)wParam
), hwndMessage
);
893 ok(!GetParent((HWND
)wParam
), "GetParent should return 0 at this point\n");
895 ok(!GetWindow((HWND
)wParam
, GW_OWNER
), "GW_OWNER should be set to 0 at this point\n");
899 /* while NT assigns GW_HWNDFIRST/LAST some values at this point,
900 * Win9x still has them set to 0.
902 ok(GetWindow((HWND
)wParam
, GW_HWNDFIRST
) != 0, "GW_HWNDFIRST should not be set to 0 at this point\n");
903 ok(GetWindow((HWND
)wParam
, GW_HWNDLAST
) != 0, "GW_HWNDLAST should not be set to 0 at this point\n");
905 ok(!GetWindow((HWND
)wParam
, GW_HWNDPREV
), "GW_HWNDPREV should be set to 0 at this point\n");
906 ok(!GetWindow((HWND
)wParam
, GW_HWNDNEXT
), "GW_HWNDNEXT should be set to 0 at this point\n");
910 /* Uncomment this once the test succeeds in all cases */
913 ok(pGetAncestor((HWND
)wParam
, GA_PARENT
) == hwndMessage
, "GA_PARENT should be set to hwndMessage at this point\n");
914 ok(pGetAncestor((HWND
)wParam
, GA_ROOT
) == (HWND
)wParam
,
915 "GA_ROOT is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOT
), (HWND
)wParam
);
917 if ((style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
918 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == hwndMessage
,
919 "GA_ROOTOWNER should be set to hwndMessage at this point\n");
921 ok(pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
) == (HWND
)wParam
,
922 "GA_ROOTOWNER is set to %p, expected %p\n", pGetAncestor((HWND
)wParam
, GA_ROOTOWNER
), (HWND
)wParam
);
925 ok(GetWindowRect((HWND
)wParam
, &rc
), "GetWindowRect failed\n");
926 ok(EqualRect(&rc
, &rc_null
), "window rect should be set to 0 HCBT_CREATEWND\n");
927 ok(GetClientRect((HWND
)wParam
, &rc
), "GetClientRect failed\n");
928 ok(EqualRect(&rc
, &rc_null
), "client rect should be set to 0 on HCBT_CREATEWND\n");
934 return CallNextHookEx(hhook
, nCode
, wParam
, lParam
);
937 static void test_shell_window(void)
941 HMODULE hinst
, hUser32
;
942 BOOL (WINAPI
*SetShellWindow
)(HWND
);
943 BOOL (WINAPI
*SetShellWindowEx
)(HWND
, HWND
);
944 HWND hwnd1
, hwnd2
, hwnd3
, hwnd4
, hwnd5
;
945 HWND shellWindow
, nextWnd
;
947 if (!GetWindowLongW(GetDesktopWindow(), GWL_STYLE
))
949 trace("Skipping shell window test on Win9x\n");
953 shellWindow
= GetShellWindow();
954 hinst
= GetModuleHandle(0);
955 hUser32
= GetModuleHandleA("user32");
957 SetShellWindow
= (void *)GetProcAddress(hUser32
, "SetShellWindow");
958 SetShellWindowEx
= (void *)GetProcAddress(hUser32
, "SetShellWindowEx");
960 trace("previous shell window: %p\n", shellWindow
);
966 ret
= DestroyWindow(shellWindow
);
967 error
= GetLastError();
969 ok(!ret
, "DestroyWindow(shellWindow)\n");
970 /* passes on Win XP, but not on Win98 */
971 ok(error
==ERROR_ACCESS_DENIED
, "ERROR_ACCESS_DENIED after DestroyWindow(shellWindow)\n");
973 /* close old shell instance */
974 GetWindowThreadProcessId(shellWindow
, &pid
);
975 hProcess
= OpenProcess(PROCESS_ALL_ACCESS
, FALSE
, pid
);
976 ret
= TerminateProcess(hProcess
, 0);
977 ok(ret
, "termination of previous shell process failed: GetLastError()=%d\n", GetLastError());
978 WaitForSingleObject(hProcess
, INFINITE
); /* wait for termination */
979 CloseHandle(hProcess
);
982 hwnd1
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst
, 0);
983 trace("created window 1: %p\n", hwnd1
);
985 ret
= SetShellWindow(hwnd1
);
986 ok(ret
, "first call to SetShellWindow(hwnd1)\n");
987 shellWindow
= GetShellWindow();
988 ok(shellWindow
==hwnd1
, "wrong shell window: %p\n", shellWindow
);
990 ret
= SetShellWindow(hwnd1
);
991 ok(!ret
, "second call to SetShellWindow(hwnd1)\n");
993 ret
= SetShellWindow(0);
994 error
= GetLastError();
995 /* passes on Win XP, but not on Win98
996 ok(!ret, "reset shell window by SetShellWindow(0)\n");
997 ok(error==ERROR_INVALID_WINDOW_HANDLE, "ERROR_INVALID_WINDOW_HANDLE after SetShellWindow(0)\n"); */
999 ret
= SetShellWindow(hwnd1
);
1000 /* passes on Win XP, but not on Win98
1001 ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
1003 SetWindowLong(hwnd1
, GWL_EXSTYLE
, GetWindowLong(hwnd1
,GWL_EXSTYLE
)|WS_EX_TOPMOST
);
1004 ret
= GetWindowLong(hwnd1
,GWL_EXSTYLE
)&WS_EX_TOPMOST
? TRUE
: FALSE
;
1005 ok(!ret
, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
1007 ret
= DestroyWindow(hwnd1
);
1008 ok(ret
, "DestroyWindow(hwnd1)\n");
1010 hwnd2
= CreateWindowEx(WS_EX_TOPMOST
, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst
, 0);
1011 trace("created window 2: %p\n", hwnd2
);
1012 ret
= SetShellWindow(hwnd2
);
1013 ok(!ret
, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
1015 hwnd3
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst
, 0);
1016 trace("created window 3: %p\n", hwnd3
);
1018 hwnd4
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst
, 0);
1019 trace("created window 4: %p\n", hwnd4
);
1021 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1022 ok(nextWnd
==hwnd3
, "wrong next window for hwnd4: %p - expected hwnd3\n", nextWnd
);
1024 ret
= SetShellWindow(hwnd4
);
1025 ok(ret
, "SetShellWindow(hwnd4)\n");
1026 shellWindow
= GetShellWindow();
1027 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1029 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1030 ok(nextWnd
==0, "wrong next window for hwnd4: %p - expected 0\n", nextWnd
);
1032 ret
= SetWindowPos(hwnd4
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1033 ok(ret
, "SetWindowPos(hwnd4, HWND_TOPMOST)\n");
1035 ret
= SetWindowPos(hwnd4
, hwnd3
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1036 ok(ret
, "SetWindowPos(hwnd4, hwnd3\n");
1038 ret
= SetShellWindow(hwnd3
);
1039 ok(!ret
, "SetShellWindow(hwnd3)\n");
1040 shellWindow
= GetShellWindow();
1041 ok(shellWindow
==hwnd4
, "wrong shell window: %p - expected hwnd4\n", shellWindow
);
1043 hwnd5
= CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW
/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst
, 0);
1044 trace("created window 5: %p\n", hwnd5
);
1045 ret
= SetWindowPos(hwnd4
, hwnd5
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1046 ok(ret
, "SetWindowPos(hwnd4, hwnd5)\n");
1050 nextWnd
= GetWindow(hwnd4
, GW_HWNDNEXT
);
1051 ok(nextWnd
==0, "wrong next window for hwnd4 after SetWindowPos(): %p - expected 0\n", nextWnd
);
1054 /* destroy test windows */
1055 DestroyWindow(hwnd2
);
1056 DestroyWindow(hwnd3
);
1057 DestroyWindow(hwnd4
);
1058 DestroyWindow(hwnd5
);
1061 /************** MDI test ****************/
1063 static char mdi_lParam_test_message
[] = "just a test string";
1065 static void test_MDI_create(HWND parent
, HWND mdi_client
, INT first_id
)
1067 MDICREATESTRUCTA mdi_cs
;
1069 static const WCHAR classW
[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
1070 static const WCHAR titleW
[] = {'M','D','I',' ','c','h','i','l','d',0};
1071 BOOL isWin9x
= FALSE
;
1073 mdi_cs
.szClass
= "MDI_child_Class_1";
1074 mdi_cs
.szTitle
= "MDI child";
1075 mdi_cs
.hOwner
= GetModuleHandle(0);
1076 mdi_cs
.x
= CW_USEDEFAULT
;
1077 mdi_cs
.y
= CW_USEDEFAULT
;
1078 mdi_cs
.cx
= CW_USEDEFAULT
;
1079 mdi_cs
.cy
= CW_USEDEFAULT
;
1081 mdi_cs
.lParam
= (LPARAM
)mdi_lParam_test_message
;
1082 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1083 ok(mdi_child
!= 0, "MDI child creation failed\n");
1084 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1085 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1086 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1088 mdi_cs
.style
= 0x7fffffff; /* without WS_POPUP */
1089 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1090 ok(mdi_child
!= 0, "MDI child creation failed\n");
1091 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1092 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1093 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1095 mdi_cs
.style
= 0xffffffff; /* with WS_POPUP */
1096 mdi_child
= (HWND
)SendMessageA(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1097 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1099 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1103 ok(mdi_child
!= 0, "MDI child creation failed\n");
1104 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1105 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1106 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1109 /* test MDICREATESTRUCT A<->W mapping */
1110 /* MDICREATESTRUCTA and MDICREATESTRUCTW have the same layout */
1112 mdi_cs
.szClass
= (LPCSTR
)classW
;
1113 mdi_cs
.szTitle
= (LPCSTR
)titleW
;
1114 SetLastError(0xdeadbeef);
1115 mdi_child
= (HWND
)SendMessageW(mdi_client
, WM_MDICREATE
, 0, (LPARAM
)&mdi_cs
);
1118 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1121 ok(mdi_child
!= 0, "MDI child creation failed\n");
1125 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1126 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1127 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1130 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1132 CW_USEDEFAULT
, CW_USEDEFAULT
,
1133 CW_USEDEFAULT
, CW_USEDEFAULT
,
1134 mdi_client
, GetModuleHandle(0),
1135 (LPARAM
)mdi_lParam_test_message
);
1136 ok(mdi_child
!= 0, "MDI child creation failed\n");
1137 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1138 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1139 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1141 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1142 0x7fffffff, /* without WS_POPUP */
1143 CW_USEDEFAULT
, CW_USEDEFAULT
,
1144 CW_USEDEFAULT
, CW_USEDEFAULT
,
1145 mdi_client
, GetModuleHandle(0),
1146 (LPARAM
)mdi_lParam_test_message
);
1147 ok(mdi_child
!= 0, "MDI child creation failed\n");
1148 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1149 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1150 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1152 mdi_child
= CreateMDIWindowA("MDI_child_Class_1", "MDI child",
1153 0xffffffff, /* with WS_POPUP */
1154 CW_USEDEFAULT
, CW_USEDEFAULT
,
1155 CW_USEDEFAULT
, CW_USEDEFAULT
,
1156 mdi_client
, GetModuleHandle(0),
1157 (LPARAM
)mdi_lParam_test_message
);
1158 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1160 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1164 ok(mdi_child
!= 0, "MDI child creation failed\n");
1165 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1166 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1167 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1170 /* test MDICREATESTRUCT A<->W mapping */
1171 SetLastError(0xdeadbeef);
1172 mdi_child
= CreateMDIWindowW(classW
, titleW
,
1174 CW_USEDEFAULT
, CW_USEDEFAULT
,
1175 CW_USEDEFAULT
, CW_USEDEFAULT
,
1176 mdi_client
, GetModuleHandle(0),
1177 (LPARAM
)mdi_lParam_test_message
);
1180 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1183 ok(mdi_child
!= 0, "MDI child creation failed\n");
1187 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1188 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1189 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1192 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1194 CW_USEDEFAULT
, CW_USEDEFAULT
,
1195 CW_USEDEFAULT
, CW_USEDEFAULT
,
1196 mdi_client
, 0, GetModuleHandle(0),
1197 (LPVOID
)mdi_lParam_test_message
);
1198 ok(mdi_child
!= 0, "MDI child creation failed\n");
1199 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1200 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1201 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1203 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1204 0x7fffffff, /* without WS_POPUP */
1205 CW_USEDEFAULT
, CW_USEDEFAULT
,
1206 CW_USEDEFAULT
, CW_USEDEFAULT
,
1207 mdi_client
, 0, GetModuleHandle(0),
1208 (LPVOID
)mdi_lParam_test_message
);
1209 ok(mdi_child
!= 0, "MDI child creation failed\n");
1210 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1211 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1212 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1214 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_1", "MDI child",
1215 0xffffffff, /* with WS_POPUP */
1216 CW_USEDEFAULT
, CW_USEDEFAULT
,
1217 CW_USEDEFAULT
, CW_USEDEFAULT
,
1218 mdi_client
, 0, GetModuleHandle(0),
1219 (LPVOID
)mdi_lParam_test_message
);
1220 if (GetWindowLongA(mdi_client
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1222 ok(!mdi_child
, "MDI child with WS_POPUP and with MDIS_ALLCHILDSTYLES should fail\n");
1226 ok(mdi_child
!= 0, "MDI child creation failed\n");
1227 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1228 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1229 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1232 /* test MDICREATESTRUCT A<->W mapping */
1233 SetLastError(0xdeadbeef);
1234 mdi_child
= CreateWindowExW(WS_EX_MDICHILD
, classW
, titleW
,
1236 CW_USEDEFAULT
, CW_USEDEFAULT
,
1237 CW_USEDEFAULT
, CW_USEDEFAULT
,
1238 mdi_client
, 0, GetModuleHandle(0),
1239 (LPVOID
)mdi_lParam_test_message
);
1242 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1245 ok(mdi_child
!= 0, "MDI child creation failed\n");
1249 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == first_id
, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1250 SendMessageA(mdi_client
, WM_MDIDESTROY
, (WPARAM
)mdi_child
, 0);
1251 ok(!IsWindow(mdi_child
), "WM_MDIDESTROY failed\n");
1254 /* This test fails on Win9x */
1257 mdi_child
= CreateWindowExA(WS_EX_MDICHILD
, "MDI_child_Class_2", "MDI child",
1259 CW_USEDEFAULT
, CW_USEDEFAULT
,
1260 CW_USEDEFAULT
, CW_USEDEFAULT
,
1261 parent
, 0, GetModuleHandle(0),
1262 (LPVOID
)mdi_lParam_test_message
);
1263 ok(!mdi_child
, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
1266 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1267 WS_CHILD
, /* without WS_POPUP */
1268 CW_USEDEFAULT
, CW_USEDEFAULT
,
1269 CW_USEDEFAULT
, CW_USEDEFAULT
,
1270 mdi_client
, 0, GetModuleHandle(0),
1271 (LPVOID
)mdi_lParam_test_message
);
1272 ok(mdi_child
!= 0, "MDI child creation failed\n");
1273 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1274 DestroyWindow(mdi_child
);
1276 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1277 WS_CHILD
| WS_POPUP
, /* with WS_POPUP */
1278 CW_USEDEFAULT
, CW_USEDEFAULT
,
1279 CW_USEDEFAULT
, CW_USEDEFAULT
,
1280 mdi_client
, 0, GetModuleHandle(0),
1281 (LPVOID
)mdi_lParam_test_message
);
1282 ok(mdi_child
!= 0, "MDI child creation failed\n");
1283 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1284 DestroyWindow(mdi_child
);
1286 /* maximized child */
1287 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1288 WS_CHILD
| WS_MAXIMIZE
,
1289 CW_USEDEFAULT
, CW_USEDEFAULT
,
1290 CW_USEDEFAULT
, CW_USEDEFAULT
,
1291 mdi_client
, 0, GetModuleHandle(0),
1292 (LPVOID
)mdi_lParam_test_message
);
1293 ok(mdi_child
!= 0, "MDI child creation failed\n");
1294 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1295 DestroyWindow(mdi_child
);
1297 trace("Creating maximized child with a caption\n");
1298 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1299 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
,
1300 CW_USEDEFAULT
, CW_USEDEFAULT
,
1301 CW_USEDEFAULT
, CW_USEDEFAULT
,
1302 mdi_client
, 0, GetModuleHandle(0),
1303 (LPVOID
)mdi_lParam_test_message
);
1304 ok(mdi_child
!= 0, "MDI child creation failed\n");
1305 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1306 DestroyWindow(mdi_child
);
1308 trace("Creating maximized child with a caption and a thick frame\n");
1309 mdi_child
= CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
1310 WS_CHILD
| WS_MAXIMIZE
| WS_CAPTION
| WS_THICKFRAME
,
1311 CW_USEDEFAULT
, CW_USEDEFAULT
,
1312 CW_USEDEFAULT
, CW_USEDEFAULT
,
1313 mdi_client
, 0, GetModuleHandle(0),
1314 (LPVOID
)mdi_lParam_test_message
);
1315 ok(mdi_child
!= 0, "MDI child creation failed\n");
1316 ok(GetWindowLongPtrA(mdi_child
, GWLP_ID
) == 0, "wrong child id %d\n", GetWindowLongPtrA(mdi_child
, GWLP_ID
));
1317 DestroyWindow(mdi_child
);
1320 /**********************************************************************
1321 * MDI_ChildGetMinMaxInfo (copied from windows/mdi.c)
1323 * Note: The rule here is that client rect of the maximized MDI child
1324 * is equal to the client rect of the MDI client window.
1326 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
1330 GetClientRect( client
, &rect
);
1331 AdjustWindowRectEx( &rect
, GetWindowLongA( hwnd
, GWL_STYLE
),
1332 0, GetWindowLongA( hwnd
, GWL_EXSTYLE
));
1334 rect
.right
-= rect
.left
;
1335 rect
.bottom
-= rect
.top
;
1336 lpMinMax
->ptMaxSize
.x
= rect
.right
;
1337 lpMinMax
->ptMaxSize
.y
= rect
.bottom
;
1339 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
1340 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
1342 trace("max rect (%d,%d - %d, %d)\n",
1343 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1346 static LRESULT WINAPI
mdi_child_wnd_proc_1(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1353 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1354 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1356 ok(cs
->dwExStyle
& WS_EX_MDICHILD
, "WS_EX_MDICHILD should be set\n");
1357 ok(mdi_cs
->lParam
== (LPARAM
)mdi_lParam_test_message
, "wrong mdi_cs->lParam\n");
1359 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_1"), "wrong class name\n");
1360 ok(!lstrcmpA(cs
->lpszClass
, mdi_cs
->szClass
), "class name does not match\n");
1361 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1362 ok(!lstrcmpA(cs
->lpszName
, mdi_cs
->szTitle
), "title does not match\n");
1363 ok(cs
->hInstance
== mdi_cs
->hOwner
, "%p != %p\n", cs
->hInstance
, mdi_cs
->hOwner
);
1365 /* MDICREATESTRUCT should have original values */
1366 ok(mdi_cs
->style
== 0 || mdi_cs
->style
== 0x7fffffff || mdi_cs
->style
== 0xffffffff,
1367 "mdi_cs->style does not match (%08x)\n", mdi_cs
->style
);
1368 ok(mdi_cs
->x
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->x
);
1369 ok(mdi_cs
->y
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->y
);
1370 ok(mdi_cs
->cx
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cx
);
1371 ok(mdi_cs
->cy
== CW_USEDEFAULT
, "%d != CW_USEDEFAULT\n", mdi_cs
->cy
);
1373 /* CREATESTRUCT should have fixed values */
1374 ok(cs
->x
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->x
);
1375 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1377 /* cx/cy == CW_USEDEFAULT are translated to NOT zero values */
1378 ok(cs
->cx
!= CW_USEDEFAULT
&& cs
->cx
!= 0, "%d == CW_USEDEFAULT\n", cs
->cx
);
1379 ok(cs
->cy
!= CW_USEDEFAULT
&& cs
->cy
!= 0, "%d == CW_USEDEFAULT\n", cs
->cy
);
1381 ok(!(cs
->style
& WS_POPUP
), "WS_POPUP is not allowed\n");
1383 if (GetWindowLongA(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1385 LONG style
= mdi_cs
->style
| WS_CHILD
| WS_CLIPSIBLINGS
;
1386 ok(cs
->style
== style
,
1387 "cs->style does not match (%08x)\n", cs
->style
);
1391 LONG style
= mdi_cs
->style
;
1393 style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1394 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1395 ok(cs
->style
== style
,
1396 "cs->style does not match (%08x)\n", cs
->style
);
1401 case WM_GETMINMAXINFO
:
1403 HWND client
= GetParent(hwnd
);
1405 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1406 MINMAXINFO my_minmax
;
1407 LONG style
, exstyle
;
1409 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1410 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1412 GetWindowRect(client
, &rc
);
1413 trace("MDI client %p window size = (%d x %d)\n", client
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1414 GetClientRect(client
, &rc
);
1415 trace("MDI client %p client size = (%d x %d)\n", client
, rc
.right
, rc
.bottom
);
1416 trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN
),
1417 GetSystemMetrics(SM_CYSCREEN
));
1419 GetClientRect(client
, &rc
);
1420 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1421 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1422 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1423 trace("MDI child: calculated max window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1425 trace("ptReserved = (%d,%d)\n"
1426 "ptMaxSize = (%d,%d)\n"
1427 "ptMaxPosition = (%d,%d)\n"
1428 "ptMinTrackSize = (%d,%d)\n"
1429 "ptMaxTrackSize = (%d,%d)\n",
1430 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1431 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1432 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1433 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1434 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1436 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1437 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1438 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1439 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1441 DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1443 trace("DefMDIChildProc returned:\n"
1444 "ptReserved = (%d,%d)\n"
1445 "ptMaxSize = (%d,%d)\n"
1446 "ptMaxPosition = (%d,%d)\n"
1447 "ptMinTrackSize = (%d,%d)\n"
1448 "ptMaxTrackSize = (%d,%d)\n",
1449 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1450 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1451 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1452 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1453 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1455 MDI_ChildGetMinMaxInfo(client
, hwnd
, &my_minmax
);
1456 ok(minmax
->ptMaxSize
.x
== my_minmax
.ptMaxSize
.x
, "default width of maximized child %d != %d\n",
1457 minmax
->ptMaxSize
.x
, my_minmax
.ptMaxSize
.x
);
1458 ok(minmax
->ptMaxSize
.y
== my_minmax
.ptMaxSize
.y
, "default height of maximized child %d != %d\n",
1459 minmax
->ptMaxSize
.y
, my_minmax
.ptMaxSize
.y
);
1464 case WM_MDIACTIVATE
:
1466 HWND active
, client
= GetParent(hwnd
);
1467 /*trace("%p WM_MDIACTIVATE %08x %08lx\n", hwnd, wparam, lparam);*/
1468 active
= (HWND
)SendMessageA(client
, WM_MDIGETACTIVE
, 0, 0);
1469 if (hwnd
== (HWND
)lparam
) /* if we are being activated */
1470 ok (active
== (HWND
)lparam
, "new active %p != active %p\n", (HWND
)lparam
, active
);
1472 ok (active
== (HWND
)wparam
, "old active %p != active %p\n", (HWND
)wparam
, active
);
1476 return DefMDIChildProcA(hwnd
, msg
, wparam
, lparam
);
1479 static LRESULT WINAPI
mdi_child_wnd_proc_2(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1486 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lparam
;
1488 trace("%s\n", (msg
== WM_NCCREATE
) ? "WM_NCCREATE" : "WM_CREATE");
1489 trace("x %d, y %d, cx %d, cy %d\n", cs
->x
, cs
->y
, cs
->cx
, cs
->cy
);
1491 ok(!(cs
->dwExStyle
& WS_EX_MDICHILD
), "WS_EX_MDICHILD should not be set\n");
1492 ok(cs
->lpCreateParams
== mdi_lParam_test_message
, "wrong cs->lpCreateParams\n");
1494 ok(!lstrcmpA(cs
->lpszClass
, "MDI_child_Class_2"), "wrong class name\n");
1495 ok(!lstrcmpA(cs
->lpszName
, "MDI child"), "wrong title\n");
1497 /* CREATESTRUCT should have fixed values */
1498 /* For some reason Win9x doesn't translate cs->x from CW_USEDEFAULT,
1500 /*ok(cs->x != CW_USEDEFAULT, "%d == CW_USEDEFAULT\n", cs->x);*/
1501 ok(cs
->y
!= CW_USEDEFAULT
, "%d == CW_USEDEFAULT\n", cs
->y
);
1503 /* cx/cy == CW_USEDEFAULT are translated to 0 */
1504 /* For some reason Win98 doesn't translate cs->cx from CW_USEDEFAULT,
1505 while Win95, Win2k, WinXP do. */
1506 /*ok(cs->cx == 0, "%d != 0\n", cs->cx);*/
1507 ok(cs
->cy
== 0, "%d != 0\n", cs
->cy
);
1511 case WM_GETMINMAXINFO
:
1513 HWND parent
= GetParent(hwnd
);
1515 MINMAXINFO
*minmax
= (MINMAXINFO
*)lparam
;
1516 LONG style
, exstyle
;
1518 trace("WM_GETMINMAXINFO\n");
1520 style
= GetWindowLongA(hwnd
, GWL_STYLE
);
1521 exstyle
= GetWindowLongA(hwnd
, GWL_EXSTYLE
);
1523 GetClientRect(parent
, &rc
);
1524 trace("parent %p client size = (%d x %d)\n", parent
, rc
.right
, rc
.bottom
);
1526 GetClientRect(parent
, &rc
);
1527 if ((style
& WS_CAPTION
) == WS_CAPTION
)
1528 style
&= ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
1529 AdjustWindowRectEx(&rc
, style
, 0, exstyle
);
1530 trace("calculated max child window size = (%d x %d)\n", rc
.right
-rc
.left
, rc
.bottom
-rc
.top
);
1532 trace("ptReserved = (%d,%d)\n"
1533 "ptMaxSize = (%d,%d)\n"
1534 "ptMaxPosition = (%d,%d)\n"
1535 "ptMinTrackSize = (%d,%d)\n"
1536 "ptMaxTrackSize = (%d,%d)\n",
1537 minmax
->ptReserved
.x
, minmax
->ptReserved
.y
,
1538 minmax
->ptMaxSize
.x
, minmax
->ptMaxSize
.y
,
1539 minmax
->ptMaxPosition
.x
, minmax
->ptMaxPosition
.y
,
1540 minmax
->ptMinTrackSize
.x
, minmax
->ptMinTrackSize
.y
,
1541 minmax
->ptMaxTrackSize
.x
, minmax
->ptMaxTrackSize
.y
);
1543 ok(minmax
->ptMaxSize
.x
== rc
.right
- rc
.left
, "default width of maximized child %d != %d\n",
1544 minmax
->ptMaxSize
.x
, rc
.right
- rc
.left
);
1545 ok(minmax
->ptMaxSize
.y
== rc
.bottom
- rc
.top
, "default height of maximized child %d != %d\n",
1546 minmax
->ptMaxSize
.y
, rc
.bottom
- rc
.top
);
1550 case WM_WINDOWPOSCHANGED
:
1552 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1555 GetWindowRect(hwnd
, &rc1
);
1556 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1557 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1558 /* note: winpos coordinates are relative to parent */
1559 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1560 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1561 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1563 GetWindowRect(hwnd
, &rc1
);
1564 GetClientRect(hwnd
, &rc2
);
1565 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1566 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1567 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1570 case WM_WINDOWPOSCHANGING
:
1572 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1573 WINDOWPOS my_winpos
= *winpos
;
1575 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1576 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1577 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1578 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1580 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1582 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1583 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1584 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1586 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1587 "DefWindowProc should not change WINDOWPOS values\n");
1592 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1595 static LRESULT WINAPI
mdi_main_wnd_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1597 static HWND mdi_client
;
1603 CLIENTCREATESTRUCT client_cs
;
1606 GetClientRect(hwnd
, &rc
);
1608 client_cs
.hWindowMenu
= 0;
1609 client_cs
.idFirstChild
= 1;
1611 /* MDIClient without MDIS_ALLCHILDSTYLES */
1612 mdi_client
= CreateWindowExA(0, "mdiclient",
1614 WS_CHILD
/*| WS_VISIBLE*/,
1615 /* tests depend on a not zero MDIClient size */
1616 0, 0, rc
.right
, rc
.bottom
,
1617 hwnd
, 0, GetModuleHandle(0),
1618 (LPVOID
)&client_cs
);
1620 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1621 DestroyWindow(mdi_client
);
1623 /* MDIClient with MDIS_ALLCHILDSTYLES */
1624 mdi_client
= CreateWindowExA(0, "mdiclient",
1626 WS_CHILD
| MDIS_ALLCHILDSTYLES
/*| WS_VISIBLE*/,
1627 /* tests depend on a not zero MDIClient size */
1628 0, 0, rc
.right
, rc
.bottom
,
1629 hwnd
, 0, GetModuleHandle(0),
1630 (LPVOID
)&client_cs
);
1632 test_MDI_create(hwnd
, mdi_client
, client_cs
.idFirstChild
);
1633 DestroyWindow(mdi_client
);
1637 case WM_WINDOWPOSCHANGED
:
1639 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1642 GetWindowRect(hwnd
, &rc1
);
1643 trace("window: (%d,%d)-(%d,%d)\n", rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
1644 SetRect(&rc2
, winpos
->x
, winpos
->y
, winpos
->x
+ winpos
->cx
, winpos
->y
+ winpos
->cy
);
1645 /* note: winpos coordinates are relative to parent */
1646 MapWindowPoints(GetParent(hwnd
), 0, (LPPOINT
)&rc2
, 2);
1647 trace("pos: (%d,%d)-(%d,%d)\n", rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
1648 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1650 GetWindowRect(hwnd
, &rc1
);
1651 GetClientRect(hwnd
, &rc2
);
1652 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)&rc1
);
1653 MapWindowPoints(0, hwnd
, (LPPOINT
)&rc1
, 2);
1654 ok(EqualRect(&rc1
, &rc2
), "rects do not match\n");
1657 case WM_WINDOWPOSCHANGING
:
1659 WINDOWPOS
*winpos
= (WINDOWPOS
*)lparam
;
1660 WINDOWPOS my_winpos
= *winpos
;
1662 trace("%s\n", (msg
== WM_WINDOWPOSCHANGING
) ? "WM_WINDOWPOSCHANGING" : "WM_WINDOWPOSCHANGED");
1663 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1664 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1665 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1667 DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
1669 trace("%p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
1670 winpos
->hwnd
, winpos
->hwndInsertAfter
,
1671 winpos
->x
, winpos
->y
, winpos
->cx
, winpos
->cy
, winpos
->flags
);
1673 ok(!memcmp(&my_winpos
, winpos
, sizeof(WINDOWPOS
)),
1674 "DefWindowProc should not change WINDOWPOS values\n");
1683 return DefFrameProcA(hwnd
, mdi_client
, msg
, wparam
, lparam
);
1686 static BOOL
mdi_RegisterWindowClasses(void)
1691 cls
.lpfnWndProc
= mdi_main_wnd_procA
;
1694 cls
.hInstance
= GetModuleHandleA(0);
1696 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1697 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1698 cls
.lpszMenuName
= NULL
;
1699 cls
.lpszClassName
= "MDI_parent_Class";
1700 if(!RegisterClassA(&cls
)) return FALSE
;
1702 cls
.lpfnWndProc
= mdi_child_wnd_proc_1
;
1703 cls
.lpszClassName
= "MDI_child_Class_1";
1704 if(!RegisterClassA(&cls
)) return FALSE
;
1706 cls
.lpfnWndProc
= mdi_child_wnd_proc_2
;
1707 cls
.lpszClassName
= "MDI_child_Class_2";
1708 if(!RegisterClassA(&cls
)) return FALSE
;
1713 static void test_mdi(void)
1718 if (!mdi_RegisterWindowClasses()) assert(0);
1720 mdi_hwndMain
= CreateWindowExA(0, "MDI_parent_Class", "MDI parent window",
1721 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
1722 WS_MAXIMIZEBOX
/*| WS_VISIBLE*/,
1723 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
,
1724 GetDesktopWindow(), 0,
1725 GetModuleHandle(0), NULL
);
1726 assert(mdi_hwndMain
);
1728 while(GetMessage(&msg, 0, 0, 0))
1730 TranslateMessage(&msg);
1731 DispatchMessage(&msg);
1734 DestroyWindow(mdi_hwndMain
);
1737 static void test_icons(void)
1741 HICON icon
= LoadIconA(0, (LPSTR
)IDI_APPLICATION
);
1742 HICON icon2
= LoadIconA(0, (LPSTR
)IDI_QUESTION
);
1743 HICON small_icon
= LoadImageA(0, (LPSTR
)IDI_APPLICATION
, IMAGE_ICON
,
1744 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
1747 cls
.cbSize
= sizeof(cls
);
1749 cls
.lpfnWndProc
= DefWindowProcA
;
1753 cls
.hIcon
= LoadIconA(0, (LPSTR
)IDI_HAND
);
1754 cls
.hIconSm
= small_icon
;
1755 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
1756 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
1757 cls
.lpszMenuName
= NULL
;
1758 cls
.lpszClassName
= "IconWindowClass";
1760 RegisterClassExA(&cls
);
1762 hwnd
= CreateWindowExA(0, "IconWindowClass", "icon test", 0,
1763 100, 100, CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, NULL
, NULL
);
1766 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1767 ok( res
== 0, "wrong big icon %p/0\n", res
);
1768 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon
);
1769 ok( res
== 0, "wrong previous big icon %p/0\n", res
);
1770 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1771 ok( res
== icon
, "wrong big icon after set %p/%p\n", res
, icon
);
1772 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)icon2
);
1773 ok( res
== icon
, "wrong previous big icon %p/%p\n", res
, icon
);
1774 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1775 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1777 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1778 ok( res
== 0, "wrong small icon %p/0\n", res
);
1779 /* this test is XP specific */
1780 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1781 ok( res != 0, "wrong small icon %p\n", res );*/
1782 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)icon
);
1783 ok( res
== 0, "wrong previous small icon %p/0\n", res
);
1784 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1785 ok( res
== icon
, "wrong small icon after set %p/%p\n", res
, icon
);
1786 /* this test is XP specific */
1787 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1788 ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
1789 res
= (HICON
)SendMessageA( hwnd
, WM_SETICON
, ICON_SMALL
, (LPARAM
)small_icon
);
1790 ok( res
== icon
, "wrong previous small icon %p/%p\n", res
, icon
);
1791 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_SMALL
, 0 );
1792 ok( res
== small_icon
, "wrong small icon after set %p/%p\n", res
, small_icon
);
1793 /* this test is XP specific */
1794 /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
1795 ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
1797 /* make sure the big icon hasn't changed */
1798 res
= (HICON
)SendMessageA( hwnd
, WM_GETICON
, ICON_BIG
, 0 );
1799 ok( res
== icon2
, "wrong big icon after set %p/%p\n", res
, icon2
);
1801 DestroyWindow( hwnd
);
1804 static LRESULT WINAPI
nccalcsize_proc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1806 if (msg
== WM_NCCALCSIZE
)
1808 RECT
*rect
= (RECT
*)lparam
;
1809 /* first time around increase the rectangle, next time decrease it */
1810 if (rect
->left
== 100) InflateRect( rect
, 10, 10 );
1811 else InflateRect( rect
, -10, -10 );
1814 return DefWindowProc( hwnd
, msg
, wparam
, lparam
);
1817 static void test_SetWindowPos(HWND hwnd
)
1819 RECT orig_win_rc
, rect
;
1821 BOOL is_win9x
= GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == 0;
1823 SetRect(&rect
, 111, 222, 333, 444);
1824 ok(!GetWindowRect(0, &rect
), "GetWindowRect succeeded\n");
1825 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1826 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1828 SetRect(&rect
, 111, 222, 333, 444);
1829 ok(!GetClientRect(0, &rect
), "GetClientRect succeeded\n");
1830 ok(rect
.left
== 111 && rect
.top
== 222 && rect
.right
== 333 && rect
.bottom
== 444,
1831 "wrong window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1833 GetWindowRect(hwnd
, &orig_win_rc
);
1835 old_proc
= SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)nccalcsize_proc
);
1836 SetWindowPos(hwnd
, 0, 100, 100, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1837 GetWindowRect( hwnd
, &rect
);
1838 ok( rect
.left
== 100 && rect
.top
== 100 && rect
.right
== 100 && rect
.bottom
== 100,
1839 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1840 GetClientRect( hwnd
, &rect
);
1841 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1842 ok( rect
.left
== 90 && rect
.top
== 90 && rect
.right
== 110 && rect
.bottom
== 110,
1843 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1845 SetWindowPos(hwnd
, 0, 200, 200, 0, 0, SWP_NOZORDER
|SWP_FRAMECHANGED
);
1846 GetWindowRect( hwnd
, &rect
);
1847 ok( rect
.left
== 200 && rect
.top
== 200 && rect
.right
== 200 && rect
.bottom
== 200,
1848 "invalid window rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1849 GetClientRect( hwnd
, &rect
);
1850 MapWindowPoints( hwnd
, 0, (POINT
*)&rect
, 2 );
1851 ok( rect
.left
== 210 && rect
.top
== 210 && rect
.right
== 190 && rect
.bottom
== 190,
1852 "invalid client rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
1854 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1855 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1856 SetWindowLongPtr( hwnd
, GWLP_WNDPROC
, old_proc
);
1858 /* Win9x truncates coordinates to 16-bit irrespectively */
1861 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOMOVE
);
1862 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOMOVE
);
1864 SetWindowPos(hwnd
, 0, -32769, -40000, -32769, -90000, SWP_NOSIZE
);
1865 SetWindowPos(hwnd
, 0, 32768, 40000, 32768, 40000, SWP_NOSIZE
);
1868 SetWindowPos(hwnd
, 0, orig_win_rc
.left
, orig_win_rc
.top
,
1869 orig_win_rc
.right
, orig_win_rc
.bottom
, 0);
1871 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1872 SetWindowPos(hwnd
, HWND_TOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1873 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1874 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1875 ok(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
, "WS_EX_TOPMOST should be set\n");
1876 SetWindowPos(hwnd
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOSIZE
|SWP_NOMOVE
);
1877 ok(!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
), "WS_EX_TOPMOST should not be set\n");
1880 static void test_SetMenu(HWND parent
)
1884 BOOL is_win9x
= GetWindowLongPtrW(parent
, GWLP_WNDPROC
) == 0;
1888 hMenu
= CreateMenu();
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
);
1899 /* test whether we can destroy a menu assigned to a window */
1900 retok
= DestroyMenu(hMenu
);
1901 ok( retok
, "DestroyMenu error %d\n", GetLastError());
1902 ok(!IsMenu(hMenu
), "menu handle should be not valid after DestroyMenu\n");
1903 ret
= GetMenu(parent
);
1904 /* This test fails on Win9x */
1906 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1907 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1908 test_nonclient_area(parent
);
1910 hMenu
= CreateMenu();
1914 ret
= GetMenu(parent
);
1915 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1917 ok(!SetMenu(parent
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1918 test_nonclient_area(parent
);
1919 ret
= GetMenu(parent
);
1920 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1922 ok(SetMenu(parent
, hMenu
), "SetMenu on a top level window should not fail\n");
1925 /* fails on (at least) Wine, NT4, XP SP2 */
1926 test_nonclient_area(parent
);
1928 ret
= GetMenu(parent
);
1929 ok(ret
== hMenu
, "unexpected menu id %p\n", ret
);
1931 ok(SetMenu(parent
, 0), "SetMenu(0) on a top level window should not fail\n");
1932 test_nonclient_area(parent
);
1933 ret
= GetMenu(parent
);
1934 ok(ret
== 0, "unexpected menu id %p\n", ret
);
1937 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, parent
, (HMENU
)10, 0, NULL
);
1940 ret
= GetMenu(child
);
1941 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1943 ok(!SetMenu(child
, (HMENU
)20), "SetMenu with invalid menu handle should fail\n");
1944 test_nonclient_area(child
);
1945 ret
= GetMenu(child
);
1946 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1948 ok(!SetMenu(child
, hMenu
), "SetMenu on a child window should fail\n");
1949 test_nonclient_area(child
);
1950 ret
= GetMenu(child
);
1951 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1953 ok(!SetMenu(child
, 0), "SetMenu(0) on a child window should fail\n");
1954 test_nonclient_area(child
);
1955 ret
= GetMenu(child
);
1956 ok(ret
== (HMENU
)10, "unexpected menu id %p\n", ret
);
1958 style
= GetWindowLong(child
, GWL_STYLE
);
1959 SetWindowLong(child
, GWL_STYLE
, style
| WS_POPUP
);
1960 ok(SetMenu(child
, hMenu
), "SetMenu on a popup child window should not fail\n");
1961 ok(SetMenu(child
, 0), "SetMenu on a popup child window should not fail\n");
1962 SetWindowLong(child
, GWL_STYLE
, style
);
1964 SetWindowLong(child
, GWL_STYLE
, style
| WS_OVERLAPPED
);
1965 ok(!SetMenu(child
, hMenu
), "SetMenu on a overlapped child window should fail\n");
1966 SetWindowLong(child
, GWL_STYLE
, style
);
1968 DestroyWindow(child
);
1972 static void test_window_tree(HWND parent
, const DWORD
*style
, const int *order
, int total
)
1974 HWND child
[5], hwnd
;
1979 hwnd
= GetWindow(parent
, GW_CHILD
);
1980 ok(!hwnd
, "have to start without children to perform the test\n");
1982 for (i
= 0; i
< total
; i
++)
1984 if (style
[i
] & DS_CONTROL
)
1986 child
[i
] = CreateWindowExA(0, MAKEINTATOM(32770), "", style
[i
] & ~WS_VISIBLE
,
1987 0,0,0,0, parent
, (HMENU
)i
, 0, NULL
);
1988 if (style
[i
] & WS_VISIBLE
)
1989 ShowWindow(child
[i
], SW_SHOW
);
1991 SetWindowPos(child
[i
], HWND_BOTTOM
, 0,0,10,10, SWP_NOACTIVATE
);
1994 child
[i
] = CreateWindowExA(0, "static", "", style
[i
], 0,0,10,10,
1995 parent
, (HMENU
)i
, 0, NULL
);
1996 trace("child[%d] = %p\n", i
, child
[i
]);
1997 ok(child
[i
] != 0, "CreateWindowEx failed to create child window\n");
2000 hwnd
= GetWindow(parent
, GW_CHILD
);
2001 ok(hwnd
!= 0, "GetWindow(GW_CHILD) failed\n");
2002 ok(hwnd
== GetWindow(child
[total
- 1], GW_HWNDFIRST
), "GW_HWNDFIRST is wrong\n");
2003 ok(child
[order
[total
- 1]] == GetWindow(child
[0], GW_HWNDLAST
), "GW_HWNDLAST is wrong\n");
2005 for (i
= 0; i
< total
; i
++)
2007 trace("hwnd[%d] = %p\n", i
, hwnd
);
2008 ok(child
[order
[i
]] == hwnd
, "Z order of child #%d is wrong\n", i
);
2010 hwnd
= GetWindow(hwnd
, GW_HWNDNEXT
);
2013 for (i
= 0; i
< total
; i
++)
2014 ok(DestroyWindow(child
[i
]), "DestroyWindow failed\n");
2017 static void test_children_zorder(HWND parent
)
2019 const DWORD simple_style
[5] = { WS_CHILD
, WS_CHILD
, WS_CHILD
, WS_CHILD
,
2021 const int simple_order
[5] = { 0, 1, 2, 3, 4 };
2023 const DWORD complex_style
[5] = { WS_CHILD
, WS_CHILD
| WS_MAXIMIZE
,
2024 WS_CHILD
| WS_VISIBLE
, WS_CHILD
,
2025 WS_CHILD
| WS_MAXIMIZE
| WS_VISIBLE
};
2026 const int complex_order_1
[1] = { 0 };
2027 const int complex_order_2
[2] = { 1, 0 };
2028 const int complex_order_3
[3] = { 1, 0, 2 };
2029 const int complex_order_4
[4] = { 1, 0, 2, 3 };
2030 const int complex_order_5
[5] = { 4, 1, 0, 2, 3 };
2031 const DWORD complex_style_6
[3] = { WS_CHILD
| WS_VISIBLE
,
2032 WS_CHILD
| WS_CLIPSIBLINGS
| DS_CONTROL
| WS_VISIBLE
,
2033 WS_CHILD
| WS_VISIBLE
};
2034 const int complex_order_6
[3] = { 0, 1, 2 };
2036 /* simple WS_CHILD */
2037 test_window_tree(parent
, simple_style
, simple_order
, 5);
2039 /* complex children styles */
2040 test_window_tree(parent
, complex_style
, complex_order_1
, 1);
2041 test_window_tree(parent
, complex_style
, complex_order_2
, 2);
2042 test_window_tree(parent
, complex_style
, complex_order_3
, 3);
2043 test_window_tree(parent
, complex_style
, complex_order_4
, 4);
2044 test_window_tree(parent
, complex_style
, complex_order_5
, 5);
2046 /* another set of complex children styles */
2047 test_window_tree(parent
, complex_style_6
, complex_order_6
, 3);
2050 #define check_z_order(hwnd, next, prev, owner, topmost) \
2051 check_z_order_debug((hwnd), (next), (prev), (owner), (topmost), \
2054 static void check_z_order_debug(HWND hwnd
, HWND next
, HWND prev
, HWND owner
,
2055 BOOL topmost
, const char *file
, int line
)
2060 test
= GetWindow(hwnd
, GW_HWNDNEXT
);
2061 /* skip foreign windows */
2062 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2063 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2065 /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2066 test
= GetWindow(test
, GW_HWNDNEXT
);
2068 ok_(file
, line
)(next
== test
, "expected next %p, got %p\n", next
, test
);
2070 test
= GetWindow(hwnd
, GW_HWNDPREV
);
2071 /* skip foreign windows */
2072 while (test
&& (GetWindowThreadProcessId(test
, NULL
) != our_pid
||
2073 UlongToHandle(GetWindowLongPtr(test
, GWLP_HINSTANCE
)) != GetModuleHandle(0)))
2075 /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
2076 test
= GetWindow(test
, GW_HWNDPREV
);
2078 ok_(file
, line
)(prev
== test
, "expected prev %p, got %p\n", prev
, test
);
2080 test
= GetWindow(hwnd
, GW_OWNER
);
2081 ok_(file
, line
)(owner
== test
, "expected owner %p, got %p\n", owner
, test
);
2083 ex_style
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
2084 ok_(file
, line
)(!(ex_style
& WS_EX_TOPMOST
) == !topmost
, "expected %stopmost\n", topmost
? "" : "NOT ");
2087 static void test_popup_zorder(HWND hwnd_D
, HWND hwnd_E
)
2089 HWND hwnd_A
, hwnd_B
, hwnd_C
, hwnd_F
;
2091 trace("hwnd_D %p, hwnd_E %p\n", hwnd_D
, hwnd_E
);
2093 SetWindowPos(hwnd_E
, hwnd_D
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2095 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2096 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2098 hwnd_F
= CreateWindowEx(0, "MainWindowClass", "Owner window",
2099 WS_OVERLAPPED
| WS_CAPTION
,
2101 0, 0, GetModuleHandle(0), NULL
);
2102 trace("hwnd_F %p\n", hwnd_F
);
2103 check_z_order(hwnd_F
, hwnd_D
, 0, 0, FALSE
);
2105 SetWindowPos(hwnd_F
, hwnd_E
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2106 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2107 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2108 check_z_order(hwnd_D
, hwnd_E
, 0, 0, FALSE
);
2110 hwnd_C
= CreateWindowEx(0, "MainWindowClass", NULL
,
2113 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2114 trace("hwnd_C %p\n", hwnd_C
);
2115 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2116 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2117 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2118 check_z_order(hwnd_C
, hwnd_D
, 0, hwnd_F
, FALSE
);
2120 hwnd_B
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2123 hwnd_F
, 0, GetModuleHandle(0), NULL
);
2124 trace("hwnd_B %p\n", hwnd_B
);
2125 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2126 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2127 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2128 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2129 check_z_order(hwnd_B
, hwnd_C
, 0, hwnd_F
, TRUE
);
2131 hwnd_A
= CreateWindowEx(WS_EX_TOPMOST
, "MainWindowClass", NULL
,
2134 0, 0, GetModuleHandle(0), NULL
);
2135 trace("hwnd_A %p\n", hwnd_A
);
2136 check_z_order(hwnd_F
, 0, hwnd_E
, 0, FALSE
);
2137 check_z_order(hwnd_E
, hwnd_F
, hwnd_D
, 0, FALSE
);
2138 check_z_order(hwnd_D
, hwnd_E
, hwnd_C
, 0, FALSE
);
2139 check_z_order(hwnd_C
, hwnd_D
, hwnd_B
, hwnd_F
, FALSE
);
2140 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2141 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2143 trace("A %p B %p C %p D %p E %p F %p\n", hwnd_A
, hwnd_B
, hwnd_C
, hwnd_D
, hwnd_E
, hwnd_F
);
2145 /* move hwnd_F and its popups up */
2146 SetWindowPos(hwnd_F
, HWND_TOP
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2147 check_z_order(hwnd_E
, 0, hwnd_D
, 0, FALSE
);
2148 check_z_order(hwnd_D
, hwnd_E
, hwnd_F
, 0, FALSE
);
2149 check_z_order(hwnd_F
, hwnd_D
, hwnd_C
, 0, FALSE
);
2150 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2151 check_z_order(hwnd_B
, hwnd_C
, hwnd_A
, hwnd_F
, TRUE
);
2152 check_z_order(hwnd_A
, hwnd_B
, 0, 0, TRUE
);
2154 /* move hwnd_F and its popups down */
2155 #if 0 /* enable once Wine is fixed to pass this test */
2156 SetWindowPos(hwnd_F
, HWND_BOTTOM
, 0,0,0,0, SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOACTIVATE
);
2157 check_z_order(hwnd_F
, 0, hwnd_C
, 0, FALSE
);
2158 check_z_order(hwnd_C
, hwnd_F
, hwnd_B
, hwnd_F
, FALSE
);
2159 check_z_order(hwnd_B
, hwnd_C
, hwnd_E
, hwnd_F
, FALSE
);
2160 check_z_order(hwnd_E
, hwnd_B
, hwnd_D
, 0, FALSE
);
2161 check_z_order(hwnd_D
, hwnd_E
, hwnd_A
, 0, FALSE
);
2162 check_z_order(hwnd_A
, hwnd_D
, 0, 0, TRUE
);
2165 DestroyWindow(hwnd_A
);
2166 DestroyWindow(hwnd_B
);
2167 DestroyWindow(hwnd_C
);
2168 DestroyWindow(hwnd_F
);
2171 static void test_vis_rgn( HWND hwnd
)
2173 RECT win_rect
, rgn_rect
;
2174 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2177 ShowWindow(hwnd
,SW_SHOW
);
2178 hdc
= GetDC( hwnd
);
2179 ok( GetRandomRgn( hdc
, hrgn
, SYSRGN
) != 0, "GetRandomRgn failed\n" );
2180 GetWindowRect( hwnd
, &win_rect
);
2181 GetRgnBox( hrgn
, &rgn_rect
);
2182 if (GetVersion() & 0x80000000)
2184 trace("win9x, mapping to screen coords\n");
2185 MapWindowPoints( hwnd
, 0, (POINT
*)&rgn_rect
, 2 );
2187 trace("win: %d,%d-%d,%d\n", win_rect
.left
, win_rect
.top
, win_rect
.right
, win_rect
.bottom
);
2188 trace("rgn: %d,%d-%d,%d\n", rgn_rect
.left
, rgn_rect
.top
, rgn_rect
.right
, rgn_rect
.bottom
);
2189 ok( win_rect
.left
<= rgn_rect
.left
, "rgn left %d not inside win rect %d\n",
2190 rgn_rect
.left
, win_rect
.left
);
2191 ok( win_rect
.top
<= rgn_rect
.top
, "rgn top %d not inside win rect %d\n",
2192 rgn_rect
.top
, win_rect
.top
);
2193 ok( win_rect
.right
>= rgn_rect
.right
, "rgn right %d not inside win rect %d\n",
2194 rgn_rect
.right
, win_rect
.right
);
2195 ok( win_rect
.bottom
>= rgn_rect
.bottom
, "rgn bottom %d not inside win rect %d\n",
2196 rgn_rect
.bottom
, win_rect
.bottom
);
2197 ReleaseDC( hwnd
, hdc
);
2200 static void test_SetFocus(HWND hwnd
)
2204 /* check if we can set focus to non-visible windows */
2206 ShowWindow(hwnd
, SW_SHOW
);
2209 ok( GetFocus() == hwnd
, "Failed to set focus to visible window %p\n", hwnd
);
2210 ok( GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
, "Window %p not visible\n", hwnd
);
2211 ShowWindow(hwnd
, SW_HIDE
);
2214 ok( GetFocus() == hwnd
, "Failed to set focus to invisible window %p\n", hwnd
);
2215 ok( !(GetWindowLong(hwnd
,GWL_STYLE
) & WS_VISIBLE
), "Window %p still visible\n", hwnd
);
2216 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2219 ok( GetFocus() == child
, "Failed to set focus to invisible child %p\n", child
);
2220 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2221 ShowWindow(child
, SW_SHOW
);
2222 ok( GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
, "Child %p is not visible\n", child
);
2223 ok( GetFocus() == child
, "Focus no longer on child %p\n", child
);
2224 ShowWindow(child
, SW_HIDE
);
2225 ok( !(GetWindowLong(child
,GWL_STYLE
) & WS_VISIBLE
), "Child %p is visible\n", child
);
2226 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2227 ShowWindow(child
, SW_SHOW
);
2229 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2230 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_HIDEWINDOW
);
2231 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2233 ShowWindow(child
, SW_HIDE
);
2235 ok( GetFocus() == hwnd
, "Focus should be on parent %p, not %p\n", hwnd
, GetFocus() );
2236 SetWindowPos(child
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_SHOWWINDOW
);
2237 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2238 ShowWindow(child
, SW_HIDE
);
2239 ok( GetFocus() == hwnd
, "Focus should still be on parent %p, not %p\n", hwnd
, GetFocus() );
2241 ShowWindow(hwnd
, SW_SHOW
);
2242 ShowWindow(child
, SW_SHOW
);
2244 ok( GetFocus() == child
, "Focus should be on child %p\n", child
);
2245 EnableWindow(hwnd
, FALSE
);
2246 ok( GetFocus() == child
, "Focus should still be on child %p\n", child
);
2247 EnableWindow(hwnd
, TRUE
);
2249 DestroyWindow( child
);
2252 static void check_wnd_state(HWND active
, HWND foreground
, HWND focus
, HWND capture
)
2254 ok(active
== GetActiveWindow(), "GetActiveWindow() = %p\n", GetActiveWindow());
2256 ok(foreground
== GetForegroundWindow(), "GetForegroundWindow() = %p\n", GetForegroundWindow());
2257 ok(focus
== GetFocus(), "GetFocus() = %p\n", GetFocus());
2258 ok(capture
== GetCapture(), "GetCapture() = %p\n", GetCapture());
2261 static void test_SetActiveWindow(HWND hwnd
)
2265 ShowWindow(hwnd
, SW_HIDE
);
2268 check_wnd_state(0, 0, 0, 0);
2270 /*trace("testing SetActiveWindow %p\n", hwnd);*/
2272 ShowWindow(hwnd
, SW_SHOW
);
2273 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2275 hwnd2
= SetActiveWindow(0);
2276 ok(hwnd2
== hwnd
, "SetActiveWindow returned %p instead of %p\n", hwnd2
, hwnd
);
2277 check_wnd_state(0, 0, 0, 0);
2279 hwnd2
= SetActiveWindow(hwnd
);
2280 ok(hwnd2
== 0, "SetActiveWindow returned %p instead of 0\n", hwnd2
);
2281 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2283 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2284 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2286 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2287 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2289 ShowWindow(hwnd
, SW_HIDE
);
2290 check_wnd_state(0, 0, 0, 0);
2292 /*trace("testing SetActiveWindow on an invisible window %p\n", hwnd);*/
2293 SetActiveWindow(hwnd
);
2294 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2296 ShowWindow(hwnd
, SW_SHOW
);
2297 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2299 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2300 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2302 DestroyWindow(hwnd2
);
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 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2309 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2311 DestroyWindow(hwnd2
);
2312 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2315 static void test_SetForegroundWindow(HWND hwnd
)
2320 ShowWindow(hwnd
, SW_HIDE
);
2323 check_wnd_state(0, 0, 0, 0);
2325 /*trace("testing SetForegroundWindow %p\n", hwnd);*/
2327 ShowWindow(hwnd
, SW_SHOW
);
2328 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2330 hwnd2
= SetActiveWindow(0);
2331 ok(hwnd2
== hwnd
, "SetActiveWindow(0) returned %p instead of %p\n", hwnd2
, hwnd
);
2332 check_wnd_state(0, 0, 0, 0);
2334 ret
= SetForegroundWindow(hwnd
);
2335 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2336 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2338 SetLastError(0xdeadbeef);
2339 ret
= SetForegroundWindow(0);
2340 ok(!ret
, "SetForegroundWindow returned TRUE instead of FALSE\n");
2341 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "got error %d expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
2342 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2344 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2345 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2347 SetWindowPos(hwnd
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_SHOWWINDOW
);
2348 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2350 hwnd2
= GetForegroundWindow();
2351 ok(hwnd2
== hwnd
, "Wrong foreground window %p\n", hwnd2
);
2352 ok(SetForegroundWindow( GetDesktopWindow() ), "SetForegroundWindow(desktop) error: %d\n", GetLastError());
2353 hwnd2
= GetForegroundWindow();
2354 ok(hwnd2
!= hwnd
, "Wrong foreground window %p\n", hwnd2
);
2356 ShowWindow(hwnd
, SW_HIDE
);
2357 check_wnd_state(0, 0, 0, 0);
2359 /*trace("testing SetForegroundWindow on an invisible window %p\n", hwnd);*/
2360 ret
= SetForegroundWindow(hwnd
);
2361 ok(ret
, "SetForegroundWindow returned FALSE instead of TRUE\n");
2362 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2364 ShowWindow(hwnd
, SW_SHOW
);
2365 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2367 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2368 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2370 DestroyWindow(hwnd2
);
2371 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2373 hwnd2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0, hwnd
, 0, 0, NULL
);
2374 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2376 SetWindowPos(hwnd2
,0,0,0,0,0,SWP_NOZORDER
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2377 check_wnd_state(hwnd2
, hwnd2
, hwnd2
, 0);
2379 DestroyWindow(hwnd2
);
2380 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2383 static WNDPROC old_button_proc
;
2385 static LRESULT WINAPI
button_hook_proc(HWND button
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2390 key_state
= GetKeyState(VK_LBUTTON
);
2391 ok(!(key_state
& 0x8000), "VK_LBUTTON should not be pressed, state %04x\n", key_state
);
2393 ret
= CallWindowProcA(old_button_proc
, button
, msg
, wparam
, lparam
);
2395 if (msg
== WM_LBUTTONDOWN
)
2399 check_wnd_state(button
, button
, button
, button
);
2401 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2403 trace("hwnd %p\n", hwnd
);
2405 check_wnd_state(button
, button
, button
, button
);
2407 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2409 check_wnd_state(button
, button
, button
, button
);
2411 DestroyWindow(hwnd
);
2413 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2415 trace("hwnd %p\n", hwnd
);
2417 check_wnd_state(button
, button
, button
, button
);
2419 /* button wnd proc should release capture on WM_KILLFOCUS if it does
2420 * match internal button state.
2422 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2423 check_wnd_state(button
, button
, button
, 0);
2425 ShowWindow(hwnd
, SW_SHOW
);
2426 check_wnd_state(hwnd
, hwnd
, hwnd
, 0);
2428 capture
= SetCapture(hwnd
);
2429 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2431 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2433 DestroyWindow(hwnd
);
2435 check_wnd_state(button
, 0, button
, 0);
2441 static void test_capture_1(void)
2443 HWND button
, capture
;
2445 capture
= GetCapture();
2446 ok(capture
== 0, "GetCapture() = %p\n", capture
);
2448 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2450 trace("button %p\n", button
);
2452 old_button_proc
= (WNDPROC
)SetWindowLongPtrA(button
, GWLP_WNDPROC
, (LONG_PTR
)button_hook_proc
);
2454 SendMessageA(button
, WM_LBUTTONDOWN
, 0, 0);
2456 capture
= SetCapture(button
);
2457 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2458 check_wnd_state(button
, 0, button
, button
);
2460 DestroyWindow(button
);
2461 check_wnd_state(0, 0, 0, 0);
2464 static void test_capture_2(void)
2466 HWND button
, hwnd
, capture
;
2468 check_wnd_state(0, 0, 0, 0);
2470 button
= CreateWindowExA(0, "button", NULL
, WS_POPUP
| WS_VISIBLE
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2472 trace("button %p\n", button
);
2474 check_wnd_state(button
, button
, button
, 0);
2476 capture
= SetCapture(button
);
2477 ok(capture
== 0, "SetCapture() = %p\n", capture
);
2479 check_wnd_state(button
, button
, button
, button
);
2481 /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
2482 * internal button state.
2484 SendMessage(button
, WM_KILLFOCUS
, 0, 0);
2485 check_wnd_state(button
, button
, button
, button
);
2487 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2489 trace("hwnd %p\n", hwnd
);
2491 check_wnd_state(button
, button
, button
, button
);
2493 ShowWindow(hwnd
, SW_SHOWNOACTIVATE
);
2495 check_wnd_state(button
, button
, button
, button
);
2497 DestroyWindow(hwnd
);
2499 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0, 0, 10, 10, 0, 0, 0, NULL
);
2501 trace("hwnd %p\n", hwnd
);
2503 check_wnd_state(button
, button
, button
, button
);
2505 ShowWindow(hwnd
, SW_SHOW
);
2507 check_wnd_state(hwnd
, hwnd
, hwnd
, button
);
2509 capture
= SetCapture(hwnd
);
2510 ok(capture
== button
, "SetCapture() = %p\n", capture
);
2512 check_wnd_state(hwnd
, hwnd
, hwnd
, hwnd
);
2514 DestroyWindow(hwnd
);
2515 check_wnd_state(button
, button
, button
, 0);
2517 DestroyWindow(button
);
2518 check_wnd_state(0, 0, 0, 0);
2521 static void test_capture_3(HWND hwnd1
, HWND hwnd2
)
2525 ShowWindow(hwnd1
, SW_HIDE
);
2526 ShowWindow(hwnd2
, SW_HIDE
);
2528 ok(!IsWindowVisible(hwnd1
), "%p should be invisible\n", hwnd1
);
2529 ok(!IsWindowVisible(hwnd2
), "%p should be invisible\n", hwnd2
);
2532 check_wnd_state(0, 0, 0, hwnd1
);
2535 check_wnd_state(0, 0, 0, hwnd2
);
2537 ShowWindow(hwnd1
, SW_SHOW
);
2538 check_wnd_state(hwnd1
, hwnd1
, hwnd1
, hwnd2
);
2540 ret
= ReleaseCapture();
2541 ok (ret
, "releasecapture did not return TRUE.\n");
2542 ret
= ReleaseCapture();
2543 ok (ret
, "releasecapture did not return TRUE after second try.\n");
2546 static void test_keyboard_input(HWND hwnd
)
2551 ShowWindow(hwnd
, SW_SHOW
);
2553 flush_events( TRUE
);
2555 ok(GetActiveWindow() == hwnd
, "wrong active window %p\n", GetActiveWindow());
2558 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2560 flush_events( TRUE
);
2562 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2563 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2564 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2565 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2566 ok( !ret
, "message %04x available\n", msg
.message
);
2568 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2570 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2571 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2572 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2573 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2574 ok( !ret
, "message %04x available\n", msg
.message
);
2576 ok(GetFocus() == hwnd
, "wrong focus window %p\n", GetFocus());
2578 keybd_event(VK_SPACE
, 0, 0, 0);
2579 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2580 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2581 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2582 ok( !ret
, "message %04x available\n", msg
.message
);
2585 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2587 flush_events( TRUE
);
2589 PostMessageA(hwnd
, WM_KEYDOWN
, 0, 0);
2590 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2591 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2592 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2593 ok( !ret
, "message %04x available\n", msg
.message
);
2595 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2597 PostThreadMessageA(GetCurrentThreadId(), WM_KEYDOWN
, 0, 0);
2598 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2599 ok(!msg
.hwnd
&& msg
.message
== WM_KEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2600 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2601 ok( !ret
, "message %04x available\n", msg
.message
);
2603 ok(GetFocus() == 0, "wrong focus window %p\n", GetFocus());
2605 keybd_event(VK_SPACE
, 0, 0, 0);
2606 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2607 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_SYSKEYDOWN
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2608 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2609 ok( !ret
, "message %04x available\n", msg
.message
);
2612 static void test_mouse_input(HWND hwnd
)
2622 ShowWindow(hwnd
, SW_SHOW
);
2625 GetWindowRect(hwnd
, &rc
);
2626 trace("main window %p: (%d,%d)-(%d,%d)\n", hwnd
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2628 popup
= CreateWindowExA(0, "MainWindowClass", NULL
, WS_POPUP
,
2629 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
,
2632 ShowWindow(popup
, SW_SHOW
);
2633 UpdateWindow(popup
);
2635 GetWindowRect(popup
, &rc
);
2636 trace("popup window %p: (%d,%d)-(%d,%d)\n", popup
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2638 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
2639 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
2640 trace("setting cursor to (%d,%d)\n", x
, y
);
2644 ok(x
== pt
.x
&& y
== pt
.y
, "wrong cursor pos (%d,%d), expected (%d,%d)\n", pt
.x
, pt
.y
, x
, y
);
2646 flush_events( TRUE
);
2648 /* Check that setting the same position will generate WM_MOUSEMOVE */
2651 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2652 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2653 ok(msg
.pt
.x
== x
&& msg
.pt
.y
== y
, "wrong message coords (%d,%d)/(%d,%d)\n", x
, y
, msg
.pt
.x
, msg
.pt
.y
);
2655 /* force the system to update its internal queue mouse position,
2656 * otherwise it won't generate relative mouse movements below.
2658 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2659 flush_events( TRUE
);
2662 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2663 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2664 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2665 /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
2666 if (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
2667 ok(msg
.hwnd
== popup
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2668 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2669 ok( !ret
, "message %04x available\n", msg
.message
);
2671 mouse_event(MOUSEEVENTF_MOVE
, -1, -1, 0, 0);
2672 ShowWindow(popup
, SW_HIDE
);
2673 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2674 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_MOUSEMOVE
, "hwnd %p message %04x\n", msg
.hwnd
, msg
.message
);
2675 flush_events( TRUE
);
2677 mouse_event(MOUSEEVENTF_MOVE
, 1, 1, 0, 0);
2678 ShowWindow(hwnd
, SW_HIDE
);
2679 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2680 ok( !ret
, "message %04x available\n", msg
.message
);
2681 flush_events( TRUE
);
2683 /* test mouse clicks */
2685 ShowWindow(hwnd
, SW_SHOW
);
2686 flush_events( TRUE
);
2687 ShowWindow(popup
, SW_SHOW
);
2688 flush_events( TRUE
);
2690 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2691 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2692 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2693 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2695 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2696 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2697 msg
.hwnd
, popup
, msg
.message
);
2698 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2699 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2700 msg
.hwnd
, popup
, msg
.message
);
2702 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2703 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2704 msg
.hwnd
, popup
, msg
.message
);
2705 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2706 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2707 msg
.hwnd
, popup
, msg
.message
);
2709 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2710 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2711 msg
.hwnd
, popup
, msg
.message
);
2712 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2713 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDBLCLK
, "hwnd %p/%p message %04x\n",
2714 msg
.hwnd
, popup
, msg
.message
);
2716 ok(PeekMessageA(&msg
, 0, 0, 0, 0), "no message available\n");
2717 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2718 msg
.hwnd
, popup
, msg
.message
);
2719 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2720 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2721 msg
.hwnd
, popup
, msg
.message
);
2723 ret
= PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
);
2724 ok(!ret
, "message %04x available\n", msg
.message
);
2726 ShowWindow(popup
, SW_HIDE
);
2727 flush_events( TRUE
);
2729 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2730 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2731 mouse_event(MOUSEEVENTF_LEFTDOWN
, 0, 0, 0, 0);
2732 mouse_event(MOUSEEVENTF_LEFTUP
, 0, 0, 0, 0);
2734 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2735 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2736 msg
.hwnd
, hwnd
, msg
.message
);
2737 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2738 ok(msg
.hwnd
== hwnd
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2739 msg
.hwnd
, hwnd
, msg
.message
);
2741 test_lbuttondown_flag
= TRUE
;
2742 SendMessageA(hwnd
, WM_COMMAND
, (WPARAM
)popup
, 0);
2743 test_lbuttondown_flag
= FALSE
;
2745 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2746 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONDOWN
, "hwnd %p/%p message %04x\n",
2747 msg
.hwnd
, popup
, msg
.message
);
2748 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2749 ok(msg
.hwnd
== popup
&& msg
.message
== WM_LBUTTONUP
, "hwnd %p/%p message %04x\n",
2750 msg
.hwnd
, popup
, msg
.message
);
2751 ok(PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
), "no message available\n");
2753 /* Test WM_MOUSEACTIVATE */
2754 #define TEST_MOUSEACTIVATE(A,B) \
2755 res = SendMessageA(hwnd, WM_MOUSEACTIVATE, (WPARAM)hwnd, (LPARAM)MAKELRESULT(A,0)); \
2756 ok(res == B, "WM_MOUSEACTIVATE for %s returned %ld\n", #A, res);
2758 TEST_MOUSEACTIVATE(HTERROR
,MA_ACTIVATE
);
2759 TEST_MOUSEACTIVATE(HTTRANSPARENT
,MA_ACTIVATE
);
2760 TEST_MOUSEACTIVATE(HTNOWHERE
,MA_ACTIVATE
);
2761 TEST_MOUSEACTIVATE(HTCLIENT
,MA_ACTIVATE
);
2762 TEST_MOUSEACTIVATE(HTCAPTION
,MA_ACTIVATE
);
2763 TEST_MOUSEACTIVATE(HTSYSMENU
,MA_ACTIVATE
);
2764 TEST_MOUSEACTIVATE(HTSIZE
,MA_ACTIVATE
);
2765 TEST_MOUSEACTIVATE(HTMENU
,MA_ACTIVATE
);
2766 TEST_MOUSEACTIVATE(HTHSCROLL
,MA_ACTIVATE
);
2767 TEST_MOUSEACTIVATE(HTVSCROLL
,MA_ACTIVATE
);
2768 TEST_MOUSEACTIVATE(HTMINBUTTON
,MA_ACTIVATE
);
2769 TEST_MOUSEACTIVATE(HTMAXBUTTON
,MA_ACTIVATE
);
2770 TEST_MOUSEACTIVATE(HTLEFT
,MA_ACTIVATE
);
2771 TEST_MOUSEACTIVATE(HTRIGHT
,MA_ACTIVATE
);
2772 TEST_MOUSEACTIVATE(HTTOP
,MA_ACTIVATE
);
2773 TEST_MOUSEACTIVATE(HTTOPLEFT
,MA_ACTIVATE
);
2774 TEST_MOUSEACTIVATE(HTTOPRIGHT
,MA_ACTIVATE
);
2775 TEST_MOUSEACTIVATE(HTBOTTOM
,MA_ACTIVATE
);
2776 TEST_MOUSEACTIVATE(HTBOTTOMLEFT
,MA_ACTIVATE
);
2777 TEST_MOUSEACTIVATE(HTBOTTOMRIGHT
,MA_ACTIVATE
);
2778 TEST_MOUSEACTIVATE(HTBORDER
,MA_ACTIVATE
);
2779 TEST_MOUSEACTIVATE(HTOBJECT
,MA_ACTIVATE
);
2780 TEST_MOUSEACTIVATE(HTCLOSE
,MA_ACTIVATE
);
2781 TEST_MOUSEACTIVATE(HTHELP
,MA_ACTIVATE
);
2783 /* Clear any messages left behind by WM_MOUSEACTIVATE tests */
2784 flush_events( TRUE
);
2786 DestroyWindow(popup
);
2789 static void test_validatergn(HWND hwnd
)
2795 child
= CreateWindowExA(0, "static", NULL
, WS_CHILD
| WS_VISIBLE
, 10, 10, 10, 10, hwnd
, 0, 0, NULL
);
2796 ShowWindow(hwnd
, SW_SHOW
);
2797 UpdateWindow( hwnd
);
2798 /* test that ValidateRect validates children*/
2799 InvalidateRect( child
, NULL
, 1);
2800 GetWindowRect( child
, &rc
);
2801 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2802 ret
= GetUpdateRect( child
, &rc2
, 0);
2803 ok( rc2
.right
> rc2
.left
&& rc2
.bottom
> rc2
.top
,
2804 "Update rectangle is empty!\n");
2805 ValidateRect( hwnd
, &rc
);
2806 ret
= GetUpdateRect( child
, &rc2
, 0);
2807 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2808 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2809 rc2
.right
, rc2
.bottom
);
2811 /* now test ValidateRgn */
2812 InvalidateRect( child
, NULL
, 1);
2813 GetWindowRect( child
, &rc
);
2814 MapWindowPoints( NULL
, hwnd
, (POINT
*) &rc
, 2);
2815 rgn
= CreateRectRgnIndirect( &rc
);
2816 ValidateRgn( hwnd
, rgn
);
2817 ret
= GetUpdateRect( child
, &rc2
, 0);
2818 ok( rc2
.left
== 0 && rc2
.top
== 0 && rc2
.right
== 0 && rc2
.bottom
== 0,
2819 "Update rectangle %d,%d-%d,%d is not empty!\n", rc2
.left
, rc2
.top
,
2820 rc2
.right
, rc2
.bottom
);
2823 DestroyWindow( child
);
2826 static void nccalchelper(HWND hwnd
, INT x
, INT y
, RECT
*prc
)
2828 MoveWindow( hwnd
, 0, 0, x
, y
, 0);
2829 GetWindowRect( hwnd
, prc
);
2830 trace("window rect is %d,%d - %d,%d\n",
2831 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2832 DefWindowProcA(hwnd
, WM_NCCALCSIZE
, 0, (LPARAM
)prc
);
2833 trace("nccalc rect is %d,%d - %d,%d\n",
2834 prc
->left
,prc
->top
,prc
->right
,prc
->bottom
);
2837 static void test_nccalcscroll(HWND parent
)
2840 INT sbheight
= GetSystemMetrics( SM_CYHSCROLL
);
2841 INT sbwidth
= GetSystemMetrics( SM_CXVSCROLL
);
2842 HWND hwnd
= CreateWindowExA(0, "static", NULL
,
2843 WS_CHILD
| WS_VISIBLE
| WS_VSCROLL
| WS_HSCROLL
,
2844 10, 10, 200, 200, parent
, 0, 0, NULL
);
2845 ShowWindow( parent
, SW_SHOW
);
2846 UpdateWindow( parent
);
2848 /* test window too low for a horizontal scroll bar */
2849 nccalchelper( hwnd
, 100, sbheight
, &rc1
);
2850 ok( rc1
.bottom
- rc1
.top
== sbheight
, "Height should be %d size is %d,%d - %d,%d\n",
2851 sbheight
, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2853 /* test window just high enough for a horizontal scroll bar */
2854 nccalchelper( hwnd
, 100, sbheight
+ 1, &rc1
);
2855 ok( rc1
.bottom
- rc1
.top
== 1, "Height should be %d size is %d,%d - %d,%d\n",
2856 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2858 /* test window too narrow for a vertical scroll bar */
2859 nccalchelper( hwnd
, sbwidth
- 1, 100, &rc1
);
2860 ok( rc1
.right
- rc1
.left
== sbwidth
- 1 , "Width should be %d size is %d,%d - %d,%d\n",
2861 sbwidth
- 1, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2863 /* test window just wide enough for a vertical scroll bar */
2864 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2865 ok( rc1
.right
- rc1
.left
== 0, "Width should be %d size is %d,%d - %d,%d\n",
2866 0, rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2868 /* same test, but with client edge: not enough width */
2869 SetWindowLong( hwnd
, GWL_EXSTYLE
, WS_EX_CLIENTEDGE
| GetWindowLong( hwnd
, GWL_EXSTYLE
));
2870 nccalchelper( hwnd
, sbwidth
, 100, &rc1
);
2871 ok( rc1
.right
- rc1
.left
== sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
),
2872 "Width should be %d size is %d,%d - %d,%d\n",
2873 sbwidth
- 2 * GetSystemMetrics(SM_CXEDGE
), rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
);
2875 DestroyWindow( hwnd
);
2878 static void test_SetParent(void)
2881 HWND desktop
= GetDesktopWindow();
2883 BOOL is_win9x
= GetWindowLongPtrW(desktop
, GWLP_WNDPROC
) == 0;
2884 HWND parent
, child1
, child2
, child3
, child4
, sibling
;
2886 parent
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2887 100, 100, 200, 200, 0, 0, 0, NULL
);
2888 assert(parent
!= 0);
2889 child1
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2890 0, 0, 50, 50, parent
, 0, 0, NULL
);
2891 assert(child1
!= 0);
2892 child2
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2893 0, 0, 50, 50, child1
, 0, 0, NULL
);
2894 assert(child2
!= 0);
2895 child3
= CreateWindowExA(0, "static", NULL
, WS_CHILD
,
2896 0, 0, 50, 50, child2
, 0, 0, NULL
);
2897 assert(child3
!= 0);
2898 child4
= CreateWindowExA(0, "static", NULL
, WS_POPUP
,
2899 0, 0, 50, 50, child3
, 0, 0, NULL
);
2900 assert(child4
!= 0);
2902 trace("parent %p, child1 %p, child2 %p, child3 %p, child4 %p\n",
2903 parent
, child1
, child2
, child3
, child4
);
2905 check_parents(parent
, desktop
, 0, 0, 0, parent
, parent
);
2906 check_parents(child1
, parent
, parent
, parent
, 0, parent
, parent
);
2907 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2908 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2909 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2911 ok(!IsChild(desktop
, parent
), "wrong parent/child %p/%p\n", desktop
, parent
);
2912 ok(!IsChild(desktop
, child1
), "wrong parent/child %p/%p\n", desktop
, child1
);
2913 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2914 ok(!IsChild(desktop
, child3
), "wrong parent/child %p/%p\n", desktop
, child3
);
2915 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2917 ok(IsChild(parent
, child1
), "wrong parent/child %p/%p\n", parent
, child1
);
2918 ok(!IsChild(desktop
, child2
), "wrong parent/child %p/%p\n", desktop
, child2
);
2919 ok(!IsChild(parent
, child2
), "wrong parent/child %p/%p\n", parent
, child2
);
2920 ok(!IsChild(child1
, child2
), "wrong parent/child %p/%p\n", child1
, child2
);
2921 ok(!IsChild(parent
, child3
), "wrong parent/child %p/%p\n", parent
, child3
);
2922 ok(IsChild(child2
, child3
), "wrong parent/child %p/%p\n", child2
, child3
);
2923 ok(!IsChild(parent
, child4
), "wrong parent/child %p/%p\n", parent
, child4
);
2924 ok(!IsChild(child3
, child4
), "wrong parent/child %p/%p\n", child3
, child4
);
2925 ok(!IsChild(desktop
, child4
), "wrong parent/child %p/%p\n", desktop
, child4
);
2927 if (!is_win9x
) /* Win9x doesn't survive this test */
2929 ok(!SetParent(parent
, child1
), "SetParent should fail\n");
2930 ok(!SetParent(child2
, child3
), "SetParent should fail\n");
2931 ok(SetParent(child1
, parent
) != 0, "SetParent should not fail\n");
2932 ok(SetParent(parent
, child2
) != 0, "SetParent should not fail\n");
2933 ok(SetParent(parent
, child3
) != 0, "SetParent should not fail\n");
2934 ok(!SetParent(child2
, parent
), "SetParent should fail\n");
2935 ok(SetParent(parent
, child4
) != 0, "SetParent should not fail\n");
2937 check_parents(parent
, child4
, child4
, 0, 0, child4
, parent
);
2938 check_parents(child1
, parent
, parent
, parent
, 0, child4
, parent
);
2939 check_parents(child2
, desktop
, parent
, parent
, parent
, child2
, parent
);
2940 check_parents(child3
, child2
, child2
, child2
, 0, child2
, parent
);
2941 check_parents(child4
, desktop
, child2
, child2
, child2
, child4
, parent
);
2944 hMenu
= CreateMenu();
2945 sibling
= CreateWindowExA(0, "static", NULL
, WS_OVERLAPPEDWINDOW
,
2946 100, 100, 200, 200, 0, hMenu
, 0, NULL
);
2947 assert(sibling
!= 0);
2949 ok(SetParent(sibling
, parent
) != 0, "SetParent should not fail\n");
2950 ok(GetMenu(sibling
) == hMenu
, "SetParent should not remove menu\n");
2952 ret
= DestroyWindow(parent
);
2953 ok( ret
, "DestroyWindow() error %d\n", GetLastError());
2955 ok(!IsWindow(parent
), "parent still exists\n");
2956 ok(!IsWindow(sibling
), "sibling still exists\n");
2957 ok(!IsWindow(child1
), "child1 still exists\n");
2958 ok(!IsWindow(child2
), "child2 still exists\n");
2959 ok(!IsWindow(child3
), "child3 still exists\n");
2960 ok(!IsWindow(child4
), "child4 still exists\n");
2963 static LRESULT WINAPI
StyleCheckProc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2965 LPCREATESTRUCT lpcs
;
2972 lpcs
= (LPCREATESTRUCT
)lparam
;
2973 lpss
= (LPSTYLESTRUCT
)lpcs
->lpCreateParams
;
2976 if ((lpcs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
2977 ((!(lpcs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
2978 (lpcs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
2979 ok(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
, "Window should have WS_EX_WINDOWEDGE style\n");
2981 ok(!(lpcs
->dwExStyle
& WS_EX_WINDOWEDGE
), "Window shouldn't have WS_EX_WINDOWEDGE style\n");
2983 ok((lpss
->styleOld
& ~WS_EX_WINDOWEDGE
) == (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
),
2984 "Ex style (0x%08lx) should match what the caller passed to CreateWindowEx (0x%08lx)\n",
2985 (lpss
->styleOld
& ~WS_EX_WINDOWEDGE
), (lpcs
->dwExStyle
& ~WS_EX_WINDOWEDGE
));
2987 ok(lpss
->styleNew
== lpcs
->style
,
2988 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
2989 lpss
->styleNew
, lpcs
->style
);
2993 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
2996 static ATOM atomStyleCheckClass
;
2998 static void register_style_check_class(void)
3006 GetModuleHandle(NULL
),
3008 LoadCursor(NULL
, IDC_ARROW
),
3009 (HBRUSH
)(COLOR_BTNFACE
+1),
3011 TEXT("WineStyleCheck"),
3014 atomStyleCheckClass
= RegisterClass(&wc
);
3017 static void check_window_style(DWORD dwStyleIn
, DWORD dwExStyleIn
, DWORD dwStyleOut
, DWORD dwExStyleOut
)
3019 DWORD dwActualStyle
;
3020 DWORD dwActualExStyle
;
3023 HWND hwndParent
= NULL
;
3025 ss
.styleNew
= dwStyleIn
;
3026 ss
.styleOld
= dwExStyleIn
;
3028 if (dwStyleIn
& WS_CHILD
)
3030 hwndParent
= CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3031 WS_OVERLAPPEDWINDOW
, 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
3034 hwnd
= CreateWindowEx(dwExStyleIn
, MAKEINTATOM(atomStyleCheckClass
), NULL
,
3035 dwStyleIn
, 0, 0, 0, 0, hwndParent
, NULL
, NULL
, &ss
);
3038 flush_events( TRUE
);
3040 dwActualStyle
= GetWindowLong(hwnd
, GWL_STYLE
);
3041 dwActualExStyle
= GetWindowLong(hwnd
, GWL_EXSTYLE
);
3042 ok((dwActualStyle
== dwStyleOut
) && (dwActualExStyle
== dwExStyleOut
),
3043 "Style (0x%08x) should really be 0x%08x and/or Ex style (0x%08x) should really be 0x%08x\n",
3044 dwActualStyle
, dwStyleOut
, dwActualExStyle
, dwExStyleOut
);
3046 DestroyWindow(hwnd
);
3047 if (hwndParent
) DestroyWindow(hwndParent
);
3050 /* tests what window styles the window manager automatically adds */
3051 static void test_window_styles(void)
3053 register_style_check_class();
3055 check_window_style(0, 0, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
);
3056 check_window_style(WS_OVERLAPPEDWINDOW
, 0, WS_CLIPSIBLINGS
|WS_OVERLAPPEDWINDOW
, WS_EX_WINDOWEDGE
);
3057 check_window_style(WS_CHILD
, 0, WS_CHILD
, 0);
3058 check_window_style(WS_CHILD
, WS_EX_WINDOWEDGE
, WS_CHILD
, 0);
3059 check_window_style(0, WS_EX_TOOLWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_WINDOWEDGE
|WS_EX_TOOLWINDOW
);
3060 check_window_style(WS_POPUP
, 0, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3061 check_window_style(WS_POPUP
, WS_EX_WINDOWEDGE
, WS_POPUP
|WS_CLIPSIBLINGS
, 0);
3062 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
, WS_CHILD
, WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3063 check_window_style(WS_CHILD
, WS_EX_DLGMODALFRAME
|WS_EX_STATICEDGE
, WS_CHILD
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
|WS_EX_DLGMODALFRAME
);
3064 check_window_style(WS_CAPTION
, WS_EX_STATICEDGE
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_STATICEDGE
|WS_EX_WINDOWEDGE
);
3065 check_window_style(0, WS_EX_APPWINDOW
, WS_CLIPSIBLINGS
|WS_CAPTION
, WS_EX_APPWINDOW
|WS_EX_WINDOWEDGE
);
3068 static void test_scrollvalidate( HWND parent
)
3071 HRGN hrgn
=CreateRectRgn(0,0,0,0);
3072 HRGN exprgn
, tmprgn
, clipping
;
3073 RECT rc
, rcu
, cliprc
;
3074 /* create two overlapping child windows. The visual region
3075 * of hwnd1 is clipped by the overlapping part of
3076 * hwnd2 because of the WS_CLIPSIBLING style */
3079 clipping
= CreateRectRgn(0,0,0,0);
3080 tmprgn
= CreateRectRgn(0,0,0,0);
3081 exprgn
= CreateRectRgn(0,0,0,0);
3082 hwnd2
= CreateWindowExA(0, "static", NULL
,
3083 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3084 75, 30, 100, 100, parent
, 0, 0, NULL
);
3085 hwnd1
= CreateWindowExA(0, "static", NULL
,
3086 WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_BORDER
,
3087 25, 50, 100, 100, parent
, 0, 0, NULL
);
3088 ShowWindow( parent
, SW_SHOW
);
3089 UpdateWindow( parent
);
3090 GetClientRect( hwnd1
, &rc
);
3092 SetRectRgn( clipping
, 10, 10, 90, 90);
3093 hdc
= GetDC( hwnd1
);
3094 /* for a visual touch */
3095 TextOut( hdc
, 0,10, "0123456789", 10);
3096 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3097 if (winetest_debug
> 0) dump_region(hrgn
);
3098 /* create a region with what is expected */
3099 SetRectRgn( exprgn
, 39,0,49,74);
3100 SetRectRgn( tmprgn
, 88,79,98,93);
3101 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3102 SetRectRgn( tmprgn
, 0,93,98,98);
3103 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3104 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3105 trace("update rect is %d,%d - %d,%d\n",
3106 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3107 /* now with clipping region */
3108 SelectClipRgn( hdc
, clipping
);
3109 ScrollDC( hdc
, -10, -5, &rc
, &cliprc
, hrgn
, &rcu
);
3110 if (winetest_debug
> 0) dump_region(hrgn
);
3111 /* create a region with what is expected */
3112 SetRectRgn( exprgn
, 39,10,49,74);
3113 SetRectRgn( tmprgn
, 80,79,90,85);
3114 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3115 SetRectRgn( tmprgn
, 10,85,90,90);
3116 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3117 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3118 trace("update rect is %d,%d - %d,%d\n",
3119 rcu
.left
,rcu
.top
,rcu
.right
,rcu
.bottom
);
3120 ReleaseDC( hwnd1
, hdc
);
3122 /* test scrolling a window with an update region */
3123 DestroyWindow( hwnd2
);
3124 ValidateRect( hwnd1
, NULL
);
3125 SetRect( &rc
, 40,40, 50,50);
3126 InvalidateRect( hwnd1
, &rc
, 1);
3127 GetClientRect( hwnd1
, &rc
);
3129 ScrollWindowEx( hwnd1
, -10, 0, &rc
, &cliprc
, hrgn
, &rcu
,
3130 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3131 if (winetest_debug
> 0) dump_region(hrgn
);
3132 SetRectRgn( exprgn
, 88,0,98,98);
3133 SetRectRgn( tmprgn
, 30, 40, 50, 50);
3134 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3135 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3137 /* clear an update region */
3138 UpdateWindow( hwnd1
);
3140 SetRect( &rc
, 0,40, 100,60);
3141 SetRect( &cliprc
, 0,0, 100,100);
3142 ScrollWindowEx( hwnd1
, 0, -25, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3143 if (winetest_debug
> 0) dump_region( hrgn
);
3144 SetRectRgn( exprgn
, 0, 40, 98, 60 );
3145 ok( EqualRgn( exprgn
, hrgn
), "wrong update region in excessive scroll\n");
3147 /* now test ScrollWindowEx with a combination of
3148 * WS_CLIPCHILDREN style and SW_SCROLLCHILDREN flag */
3149 /* make hwnd2 the child of hwnd1 */
3150 hwnd2
= CreateWindowExA(0, "static", NULL
,
3151 WS_CHILD
| WS_VISIBLE
| WS_BORDER
,
3152 50, 50, 100, 100, hwnd1
, 0, 0, NULL
);
3153 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPSIBLINGS
);
3154 GetClientRect( hwnd1
, &rc
);
3157 /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
3158 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3159 ValidateRect( hwnd1
, NULL
);
3160 ValidateRect( hwnd2
, NULL
);
3161 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
,
3162 SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3163 if (winetest_debug
> 0) dump_region(hrgn
);
3164 SetRectRgn( exprgn
, 88,0,98,88);
3165 SetRectRgn( tmprgn
, 0,88,98,98);
3166 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3167 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3169 /* SW_SCROLLCHILDREN */
3170 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3171 ValidateRect( hwnd1
, NULL
);
3172 ValidateRect( hwnd2
, NULL
);
3173 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_SCROLLCHILDREN
| SW_INVALIDATE
);
3174 if (winetest_debug
> 0) dump_region(hrgn
);
3175 /* expected region is the same as in previous test */
3176 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3178 /* no SW_SCROLLCHILDREN */
3179 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) & ~WS_CLIPCHILDREN
);
3180 ValidateRect( hwnd1
, NULL
);
3181 ValidateRect( hwnd2
, NULL
);
3182 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3183 if (winetest_debug
> 0) dump_region(hrgn
);
3184 /* expected region is the same as in previous test */
3185 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3187 /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
3188 SetWindowLong( hwnd1
, GWL_STYLE
, GetWindowLong( hwnd1
, GWL_STYLE
) | WS_CLIPCHILDREN
);
3189 ValidateRect( hwnd1
, NULL
);
3190 ValidateRect( hwnd2
, NULL
);
3191 ScrollWindowEx( hwnd1
, -10, -10, &rc
, &cliprc
, hrgn
, &rcu
, SW_INVALIDATE
);
3192 if (winetest_debug
> 0) dump_region(hrgn
);
3193 SetRectRgn( exprgn
, 88,0,98,20);
3194 SetRectRgn( tmprgn
, 20,20,98,30);
3195 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3196 SetRectRgn( tmprgn
, 20,30,30,88);
3197 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3198 SetRectRgn( tmprgn
, 0,88,30,98);
3199 CombineRgn( exprgn
, exprgn
, tmprgn
, RGN_OR
);
3200 ok( EqualRgn( exprgn
, hrgn
), "wrong update region\n");
3203 DeleteObject( hrgn
);
3204 DeleteObject( exprgn
);
3205 DeleteObject( tmprgn
);
3206 DestroyWindow( hwnd1
);
3207 DestroyWindow( hwnd2
);
3210 /* couple of tests of return values of scrollbar functions
3211 * called on a scrollbarless window */
3212 static void test_scroll(void)
3217 HWND hwnd
= CreateWindowExA(0, "Static", "Wine test window",
3218 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
| WS_POPUP
,
3219 100, 100, 200, 200, 0, 0, 0, NULL
);
3221 ret
= GetScrollRange( hwnd
, SB_HORZ
, &min
, &max
);
3222 ok( ret
, "GetScrollRange returns FALSE\n");
3223 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3224 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3225 si
.cbSize
= sizeof( si
);
3226 si
.fMask
= SIF_PAGE
;
3227 si
.nPage
= 0xdeadbeef;
3228 ret
= GetScrollInfo( hwnd
, SB_HORZ
, &si
);
3229 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3230 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3232 ret
= GetScrollRange( hwnd
, SB_VERT
, &min
, &max
);
3233 ok( ret
, "GetScrollRange returns FALSE\n");
3234 ok( min
== 0, "minimum scroll pos is %d (should be zero)\n", min
);
3235 ok( max
== 0, "maximum scroll pos is %d (should be zero)\n", min
);
3236 si
.cbSize
= sizeof( si
);
3237 si
.fMask
= SIF_PAGE
;
3238 si
.nPage
= 0xdeadbeef;
3239 ret
= GetScrollInfo( hwnd
, SB_VERT
, &si
);
3240 ok( !ret
, "GetScrollInfo returns %d (should be zero)\n", ret
);
3241 ok( si
.nPage
== 0xdeadbeef, "unexpected value for nPage is %d\n", si
.nPage
);
3243 DestroyWindow( hwnd
);
3246 static void test_scrolldc( HWND parent
)
3249 HRGN exprgn
, tmprgn
, hrgn
;
3250 RECT rc
, rc2
, rcu
, cliprc
;
3254 hrgn
= CreateRectRgn(0,0,0,0);
3255 tmprgn
= CreateRectRgn(0,0,0,0);
3256 exprgn
= CreateRectRgn(0,0,0,0);
3258 hwnd1
= CreateWindowExA(0, "static", NULL
,
3259 WS_CHILD
| WS_VISIBLE
,
3260 25, 50, 100, 100, parent
, 0, 0, NULL
);
3261 ShowWindow( parent
, SW_SHOW
);
3262 UpdateWindow( parent
);
3263 flush_events( TRUE
);
3264 GetClientRect( hwnd1
, &rc
);
3265 hdc
= GetDC( hwnd1
);
3266 /* paint the upper half of the window black */
3268 rc2
.bottom
= ( rc
.top
+ rc
.bottom
) /2;
3269 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3270 /* clip region is the lower half */
3272 cliprc
.top
= (rc
.top
+ rc
.bottom
) /2;
3273 /* test whether scrolled pixels are properly clipped */
3274 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3275 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3276 /* this scroll should not cause any visible changes */
3277 ScrollDC( hdc
, 5, -20, &rc
, &cliprc
, hrgn
, &rcu
);
3278 colr
= GetPixel( hdc
, (rc
.left
+rc
.right
)/2, ( rc
.top
+ rc
.bottom
) /2 - 1);
3279 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3280 /* test with NULL clip rect */
3281 ScrollDC( hdc
, 20, -20, &rc
, NULL
, hrgn
, &rcu
);
3282 /*FillRgn(hdc, hrgn, GetStockObject(WHITE_BRUSH));*/
3283 trace("update rect: %d,%d - %d,%d\n",
3284 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3285 if (winetest_debug
> 0) dump_region(hrgn
);
3286 SetRect(&rc2
, 0, 0, 100, 100);
3287 ok(EqualRect(&rcu
, &rc2
), "rects do not match (%d,%d-%d,%d) / (%d,%d-%d,%d)\n",
3288 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
, rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
3290 SetRectRgn( exprgn
, 0, 0, 20, 80);
3291 SetRectRgn( tmprgn
, 0, 80, 100, 100);
3292 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3293 if (winetest_debug
> 0) dump_region(exprgn
);
3294 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3295 /* test clip rect > scroll rect */
3296 FillRect( hdc
, &rc
, GetStockObject(WHITE_BRUSH
));
3298 InflateRect( &rc2
, -(rc
.right
-rc
.left
)/4, -(rc
.bottom
-rc
.top
)/4);
3299 FillRect( hdc
, &rc2
, GetStockObject(BLACK_BRUSH
));
3300 ScrollDC( hdc
, 10, 10, &rc2
, &rc
, hrgn
, &rcu
);
3301 SetRectRgn( exprgn
, 25, 25, 75, 35);
3302 SetRectRgn( tmprgn
, 25, 35, 35, 75);
3303 CombineRgn(exprgn
, exprgn
, tmprgn
, RGN_OR
);
3304 ok(EqualRgn(exprgn
, hrgn
), "wrong update region\n");
3305 colr
= GetPixel( hdc
, 80, 80);
3306 ok ( colr
== 0, "pixel should be black, color is %08x\n", colr
);
3307 trace("update rect: %d,%d - %d,%d\n",
3308 rcu
.left
, rcu
.top
, rcu
.right
, rcu
.bottom
);
3309 if (winetest_debug
> 0) dump_region(hrgn
);
3313 DeleteObject(exprgn
);
3314 DeleteObject(tmprgn
);
3315 DestroyWindow(hwnd1
);
3318 static void test_params(void)
3323 /* Just a param check */
3324 SetLastError(0xdeadbeef);
3325 rc
= GetWindowText(hwndMain2
, NULL
, 1024);
3326 ok( rc
==0, "GetWindowText: rc=%d err=%d\n",rc
,GetLastError());
3328 SetLastError(0xdeadbeef);
3329 hwnd
=CreateWindow("LISTBOX", "TestList",
3330 (LBS_STANDARD
& ~LBS_SORT
),
3332 NULL
, (HMENU
)1, NULL
, 0);
3334 ok(!hwnd
, "CreateWindow with invalid menu handle should fail\n");
3335 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
|| /* NT */
3336 GetLastError() == 0xdeadbeef, /* Win9x */
3337 "wrong last error value %d\n", GetLastError());
3340 static void test_AWRwindow(LPCSTR
class, LONG style
, LONG exStyle
, BOOL menu
)
3344 hwnd
= CreateWindowEx(exStyle
, class, class, style
,
3351 trace("Failed to create window class=%s, style=0x%08x, exStyle=0x%08x\n", class, style
, exStyle
);
3354 ShowWindow(hwnd
, SW_SHOW
);
3356 test_nonclient_area(hwnd
);
3359 DestroyWindow(hwnd
);
3362 static BOOL
AWR_init(void)
3366 class.style
= CS_HREDRAW
| CS_VREDRAW
;
3367 class.lpfnWndProc
= DefWindowProcA
;
3368 class.cbClsExtra
= 0;
3369 class.cbWndExtra
= 0;
3370 class.hInstance
= 0;
3371 class.hIcon
= LoadIcon (0, IDI_APPLICATION
);
3372 class.hCursor
= LoadCursor (0, IDC_ARROW
);
3373 class.hbrBackground
= 0;
3374 class.lpszMenuName
= 0;
3375 class.lpszClassName
= szAWRClass
;
3377 if (!RegisterClass (&class)) {
3378 ok(FALSE
, "RegisterClass failed\n");
3382 hmenu
= CreateMenu();
3385 ok(hmenu
!= 0, "Failed to create menu\n");
3386 ok(AppendMenu(hmenu
, MF_STRING
, 1, "Test!"), "Failed to create menu item\n");
3392 static void test_AWR_window_size(BOOL menu
)
3396 WS_MAXIMIZE
, WS_BORDER
, WS_DLGFRAME
,
3399 WS_MINIMIZEBOX
, WS_MAXIMIZEBOX
,
3400 WS_HSCROLL
, WS_VSCROLL
3404 WS_EX_TOOLWINDOW
, WS_EX_WINDOWEDGE
,
3407 /* These styles have problems on (at least) WinXP (SP2) and Wine */
3408 WS_EX_DLGMODALFRAME
,
3415 /* A exhaustive check of all the styles takes too long
3416 * so just do a (hopefully representative) sample
3418 for (i
= 0; i
< COUNTOF(styles
); ++i
)
3419 test_AWRwindow(szAWRClass
, styles
[i
], 0, menu
);
3420 for (i
= 0; i
< COUNTOF(exStyles
); ++i
) {
3421 test_AWRwindow(szAWRClass
, WS_POPUP
, exStyles
[i
], menu
);
3422 test_AWRwindow(szAWRClass
, WS_THICKFRAME
, exStyles
[i
], menu
);
3427 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
3429 static void test_AdjustWindowRect(void)
3434 SHOWSYSMETRIC(SM_CYCAPTION
);
3435 SHOWSYSMETRIC(SM_CYSMCAPTION
);
3436 SHOWSYSMETRIC(SM_CYMENU
);
3437 SHOWSYSMETRIC(SM_CXEDGE
);
3438 SHOWSYSMETRIC(SM_CYEDGE
);
3439 SHOWSYSMETRIC(SM_CXVSCROLL
);
3440 SHOWSYSMETRIC(SM_CYHSCROLL
);
3441 SHOWSYSMETRIC(SM_CXFRAME
);
3442 SHOWSYSMETRIC(SM_CYFRAME
);
3443 SHOWSYSMETRIC(SM_CXDLGFRAME
);
3444 SHOWSYSMETRIC(SM_CYDLGFRAME
);
3445 SHOWSYSMETRIC(SM_CXBORDER
);
3446 SHOWSYSMETRIC(SM_CYBORDER
);
3448 test_AWR_window_size(FALSE
);
3449 test_AWR_window_size(TRUE
);
3453 #undef SHOWSYSMETRIC
3456 /* Global variables to trigger exit from loop */
3457 static int redrawComplete
, WMPAINT_count
;
3459 static LRESULT WINAPI
redraw_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3464 trace("doing WM_PAINT %d\n", WMPAINT_count
);
3466 if (WMPAINT_count
> 10 && redrawComplete
== 0) {
3468 BeginPaint(hwnd
, &ps
);
3469 EndPaint(hwnd
, &ps
);
3474 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3477 /* Ensure we exit from RedrawNow regardless of invalidated area */
3478 static void test_redrawnow(void)
3483 cls
.style
= CS_DBLCLKS
;
3484 cls
.lpfnWndProc
= redraw_window_procA
;
3487 cls
.hInstance
= GetModuleHandleA(0);
3489 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3490 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3491 cls
.lpszMenuName
= NULL
;
3492 cls
.lpszClassName
= "RedrawWindowClass";
3494 if(!RegisterClassA(&cls
)) {
3495 trace("Register failed %d\n", GetLastError());
3499 hwndMain
= CreateWindowA("RedrawWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3500 CW_USEDEFAULT
, 0, 100, 100, NULL
, NULL
, 0, NULL
);
3502 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3503 ShowWindow(hwndMain
, SW_SHOW
);
3504 ok( WMPAINT_count
== 0, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3505 RedrawWindow(hwndMain
, NULL
,NULL
,RDW_UPDATENOW
| RDW_ALLCHILDREN
);
3506 ok( WMPAINT_count
== 1, "Multiple unexpected WM_PAINT calls %d\n", WMPAINT_count
);
3507 redrawComplete
= TRUE
;
3508 ok( WMPAINT_count
< 10, "RedrawWindow (RDW_UPDATENOW) never completed (%d)\n", WMPAINT_count
);
3511 DestroyWindow( hwndMain
);
3514 struct parentdc_stat
{
3520 struct parentdc_test
{
3521 struct parentdc_stat main
, main_todo
;
3522 struct parentdc_stat child1
, child1_todo
;
3523 struct parentdc_stat child2
, child2_todo
;
3526 static LRESULT WINAPI
parentdc_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3531 struct parentdc_stat
*t
= (struct parentdc_stat
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
3536 trace("doing WM_PAINT on %p\n", hwnd
);
3537 GetClientRect(hwnd
, &rc
);
3538 CopyRect(&t
->client
, &rc
);
3539 trace("client rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3540 GetWindowRect(hwnd
, &rc
);
3541 trace("window rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3542 BeginPaint(hwnd
, &ps
);
3543 CopyRect(&t
->paint
, &ps
.rcPaint
);
3544 GetClipBox(ps
.hdc
, &rc
);
3545 CopyRect(&t
->clip
, &rc
);
3546 trace("clip rect (%d, %d)-(%d, %d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3547 trace("paint rect (%d, %d)-(%d, %d)\n", ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
3548 EndPaint(hwnd
, &ps
);
3551 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
3554 static void zero_parentdc_stat(struct parentdc_stat
*t
)
3556 SetRectEmpty(&t
->client
);
3557 SetRectEmpty(&t
->clip
);
3558 SetRectEmpty(&t
->paint
);
3561 static void zero_parentdc_test(struct parentdc_test
*t
)
3563 zero_parentdc_stat(&t
->main
);
3564 zero_parentdc_stat(&t
->child1
);
3565 zero_parentdc_stat(&t
->child2
);
3568 #define parentdc_field_ok(t, w, r, f, got) \
3569 ok (t.w.r.f==got.w.r.f, "window " #w ", rect " #r ", field " #f \
3570 ": expected %d, got %d\n", \
3573 #define parentdc_todo_field_ok(t, w, r, f, got) \
3574 if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
3575 else parentdc_field_ok(t, w, r, f, got)
3577 #define parentdc_rect_ok(t, w, r, got) \
3578 parentdc_todo_field_ok(t, w, r, left, got); \
3579 parentdc_todo_field_ok(t, w, r, top, got); \
3580 parentdc_todo_field_ok(t, w, r, right, got); \
3581 parentdc_todo_field_ok(t, w, r, bottom, got);
3583 #define parentdc_win_ok(t, w, got) \
3584 parentdc_rect_ok(t, w, client, got); \
3585 parentdc_rect_ok(t, w, clip, got); \
3586 parentdc_rect_ok(t, w, paint, got);
3588 #define parentdc_ok(t, got) \
3589 parentdc_win_ok(t, main, got); \
3590 parentdc_win_ok(t, child1, got); \
3591 parentdc_win_ok(t, child2, got);
3593 static void test_csparentdc(void)
3595 WNDCLASSA clsMain
, cls
;
3596 HWND hwndMain
, hwnd1
, hwnd2
;
3599 struct parentdc_test test_answer
;
3601 #define nothing_todo {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
3602 const struct parentdc_test test1
=
3604 {{0, 0, 150, 150}, {0, 0, 150, 150}, {0, 0, 150, 150}}, nothing_todo
,
3605 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3606 {{0, 0, 40, 40}, {-40, -40, 110, 110}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3609 const struct parentdc_test test2
=
3611 {{0, 0, 150, 150}, {0, 0, 50, 50}, {0, 0, 50, 50}}, nothing_todo
,
3612 {{0, 0, 40, 40}, {-20, -20, 30, 30}, {0, 0, 30, 30}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3613 {{0, 0, 40, 40}, {-40, -40, 10, 10}, {0, 0, 10, 10}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3616 const struct parentdc_test test3
=
3618 {{0, 0, 150, 150}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3619 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3620 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3623 const struct parentdc_test test4
=
3625 {{0, 0, 150, 150}, {40, 40, 50, 50}, {40, 40, 50, 50}}, nothing_todo
,
3626 {{0, 0, 40, 40}, {20, 20, 30, 30}, {20, 20, 30, 30}}, nothing_todo
,
3627 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3630 const struct parentdc_test test5
=
3632 {{0, 0, 150, 150}, {20, 20, 60, 60}, {20, 20, 60, 60}}, nothing_todo
,
3633 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3634 {{0, 0, 40, 40}, {-20, -20, 20, 20}, {0, 0, 20, 20}}, {{0, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 0}},
3637 const struct parentdc_test test6
=
3639 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3640 {{0, 0, 40, 40}, {0, 0, 10, 10}, {0, 0, 10, 10}}, nothing_todo
,
3641 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3644 const struct parentdc_test test7
=
3646 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3647 {{0, 0, 40, 40}, {-20, -20, 130, 130}, {0, 0, 40, 40}}, {{0, 0, 0, 0}, {1, 1, 1, 1}, {0, 0, 0, 0}},
3648 {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, nothing_todo
,
3652 clsMain
.style
= CS_DBLCLKS
;
3653 clsMain
.lpfnWndProc
= parentdc_window_procA
;
3654 clsMain
.cbClsExtra
= 0;
3655 clsMain
.cbWndExtra
= 0;
3656 clsMain
.hInstance
= GetModuleHandleA(0);
3658 clsMain
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3659 clsMain
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3660 clsMain
.lpszMenuName
= NULL
;
3661 clsMain
.lpszClassName
= "ParentDcMainWindowClass";
3663 if(!RegisterClassA(&clsMain
)) {
3664 trace("Register failed %d\n", GetLastError());
3668 cls
.style
= CS_DBLCLKS
| CS_PARENTDC
;
3669 cls
.lpfnWndProc
= parentdc_window_procA
;
3672 cls
.hInstance
= GetModuleHandleA(0);
3674 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
3675 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
3676 cls
.lpszMenuName
= NULL
;
3677 cls
.lpszClassName
= "ParentDcWindowClass";
3679 if(!RegisterClassA(&cls
)) {
3680 trace("Register failed %d\n", GetLastError());
3684 SetRect(&rc
, 0, 0, 150, 150);
3685 AdjustWindowRectEx(&rc
, WS_OVERLAPPEDWINDOW
, FALSE
, 0);
3686 hwndMain
= CreateWindowA("ParentDcMainWindowClass", "Main Window", WS_OVERLAPPEDWINDOW
,
3687 CW_USEDEFAULT
, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, NULL
, NULL
, 0, NULL
);
3688 SetWindowLongPtrA(hwndMain
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.main
);
3689 hwnd1
= CreateWindowA("ParentDcWindowClass", "Child Window 1", WS_CHILD
,
3690 20, 20, 40, 40, hwndMain
, NULL
, 0, NULL
);
3691 SetWindowLongPtrA(hwnd1
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child1
);
3692 hwnd2
= CreateWindowA("ParentDcWindowClass", "Child Window 2", WS_CHILD
,
3693 40, 40, 40, 40, hwndMain
, NULL
, 0, NULL
);
3694 SetWindowLongPtrA(hwnd2
, GWLP_USERDATA
, (DWORD_PTR
)&test_answer
.child2
);
3695 ShowWindow(hwndMain
, SW_SHOW
);
3696 ShowWindow(hwnd1
, SW_SHOW
);
3697 ShowWindow(hwnd2
, SW_SHOW
);
3698 flush_events( TRUE
);
3700 zero_parentdc_test(&test_answer
);
3701 InvalidateRect(hwndMain
, NULL
, TRUE
);
3702 flush_events( TRUE
);
3703 parentdc_ok(test1
, test_answer
);
3705 zero_parentdc_test(&test_answer
);
3706 SetRect(&rc
, 0, 0, 50, 50);
3707 InvalidateRect(hwndMain
, &rc
, TRUE
);
3708 flush_events( TRUE
);
3709 parentdc_ok(test2
, test_answer
);
3711 zero_parentdc_test(&test_answer
);
3712 SetRect(&rc
, 0, 0, 10, 10);
3713 InvalidateRect(hwndMain
, &rc
, TRUE
);
3714 flush_events( TRUE
);
3715 parentdc_ok(test3
, test_answer
);
3717 zero_parentdc_test(&test_answer
);
3718 SetRect(&rc
, 40, 40, 50, 50);
3719 InvalidateRect(hwndMain
, &rc
, TRUE
);
3720 flush_events( TRUE
);
3721 parentdc_ok(test4
, test_answer
);
3723 zero_parentdc_test(&test_answer
);
3724 SetRect(&rc
, 20, 20, 60, 60);
3725 InvalidateRect(hwndMain
, &rc
, TRUE
);
3726 flush_events( TRUE
);
3727 parentdc_ok(test5
, test_answer
);
3729 zero_parentdc_test(&test_answer
);
3730 SetRect(&rc
, 0, 0, 10, 10);
3731 InvalidateRect(hwnd1
, &rc
, TRUE
);
3732 flush_events( TRUE
);
3733 parentdc_ok(test6
, test_answer
);
3735 zero_parentdc_test(&test_answer
);
3736 SetRect(&rc
, -5, -5, 65, 65);
3737 InvalidateRect(hwnd1
, &rc
, TRUE
);
3738 flush_events( TRUE
);
3739 parentdc_ok(test7
, test_answer
);
3741 DestroyWindow(hwndMain
);
3742 DestroyWindow(hwnd1
);
3743 DestroyWindow(hwnd2
);
3746 static LRESULT WINAPI
def_window_procA(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3748 return DefWindowProcA(hwnd
, msg
, wparam
, lparam
);
3751 static LRESULT WINAPI
def_window_procW(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3753 return DefWindowProcW(hwnd
, msg
, wparam
, lparam
);
3756 static void test_IsWindowUnicode(void)
3758 static const char ansi_class_nameA
[] = "ansi class name";
3759 static const WCHAR ansi_class_nameW
[] = {'a','n','s','i',' ','c','l','a','s','s',' ','n','a','m','e',0};
3760 static const char unicode_class_nameA
[] = "unicode class name";
3761 static const WCHAR unicode_class_nameW
[] = {'u','n','i','c','o','d','e',' ','c','l','a','s','s',' ','n','a','m','e',0};
3766 memset(&classW
, 0, sizeof(classW
));
3767 classW
.hInstance
= GetModuleHandleA(0);
3768 classW
.lpfnWndProc
= def_window_procW
;
3769 classW
.lpszClassName
= unicode_class_nameW
;
3770 if (!RegisterClassW(&classW
)) return; /* this catches Win9x as well */
3772 memset(&classA
, 0, sizeof(classA
));
3773 classA
.hInstance
= GetModuleHandleA(0);
3774 classA
.lpfnWndProc
= def_window_procA
;
3775 classA
.lpszClassName
= ansi_class_nameA
;
3776 assert(RegisterClassA(&classA
));
3778 /* unicode class: window proc */
3779 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3780 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3783 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3784 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3785 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3786 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3787 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3789 DestroyWindow(hwnd
);
3791 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3792 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3795 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3796 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3797 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3798 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3799 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3801 DestroyWindow(hwnd
);
3803 /* ansi class: window proc */
3804 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3805 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3808 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3809 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3810 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3811 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3812 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3814 DestroyWindow(hwnd
);
3816 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3817 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3820 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3821 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3822 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3823 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3824 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3826 DestroyWindow(hwnd
);
3828 /* unicode class: class proc */
3829 hwnd
= CreateWindowExW(0, unicode_class_nameW
, NULL
, WS_POPUP
,
3830 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3833 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3834 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3835 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3836 /* do not restore class window proc back to unicode */
3838 DestroyWindow(hwnd
);
3840 hwnd
= CreateWindowExA(0, unicode_class_nameA
, NULL
, WS_POPUP
,
3841 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3844 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3845 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3846 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3848 DestroyWindow(hwnd
);
3850 /* ansi class: class proc */
3851 hwnd
= CreateWindowExW(0, ansi_class_nameW
, NULL
, WS_POPUP
,
3852 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3855 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3856 SetClassLongPtrW(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procW
);
3857 ok(!IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return FALSE\n");
3858 /* do not restore class window proc back to ansi */
3860 DestroyWindow(hwnd
);
3862 hwnd
= CreateWindowExA(0, ansi_class_nameA
, NULL
, WS_POPUP
,
3863 0, 0, 100, 100, GetDesktopWindow(), 0, 0, NULL
);
3866 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3867 SetClassLongPtrA(hwnd
, GCLP_WNDPROC
, (ULONG_PTR
)def_window_procA
);
3868 ok(IsWindowUnicode(hwnd
), "IsWindowUnicode expected to return TRUE\n");
3870 DestroyWindow(hwnd
);
3873 static LRESULT CALLBACK
minmax_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3877 if (msg
!= WM_GETMINMAXINFO
)
3878 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3880 minmax
= (MINMAXINFO
*)lp
;
3882 if ((GetWindowLong(hwnd
, GWL_STYLE
) & WS_CHILD
))
3884 minmax
->ptReserved
.x
= 0;
3885 minmax
->ptReserved
.y
= 0;
3886 minmax
->ptMaxSize
.x
= 400;
3887 minmax
->ptMaxSize
.y
= 400;
3888 minmax
->ptMaxPosition
.x
= 300;
3889 minmax
->ptMaxPosition
.y
= 300;
3890 minmax
->ptMaxTrackSize
.x
= 200;
3891 minmax
->ptMaxTrackSize
.y
= 200;
3892 minmax
->ptMinTrackSize
.x
= 100;
3893 minmax
->ptMinTrackSize
.y
= 100;
3896 DefWindowProc(hwnd
, msg
, wp
, lp
);
3900 static int expected_cx
, expected_cy
;
3901 static RECT expected_rect
;
3903 static LRESULT CALLBACK
winsizes_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
)
3907 case WM_GETMINMAXINFO
:
3910 GetWindowRect( hwnd
, &rect
);
3911 ok( !rect
.left
&& !rect
.top
&& !rect
.right
&& !rect
.bottom
,
3912 "wrong rect %d,%d-%d,%d\n", rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3913 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3918 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lp
;
3920 GetWindowRect( hwnd
, &rect
);
3921 trace( "hwnd %p msg %x size %dx%d rect %d,%d-%d,%d\n",
3922 hwnd
, msg
, cs
->cx
, cs
->cy
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3923 ok( cs
->cx
== expected_cx
, "wrong x size %d/%d\n", cs
->cx
, expected_cx
);
3924 ok( cs
->cy
== expected_cy
, "wrong y size %d/%d\n", cs
->cy
, expected_cy
);
3925 ok( rect
.right
- rect
.left
== expected_rect
.right
- expected_rect
.left
&&
3926 rect
.bottom
- rect
.top
== expected_rect
.bottom
- expected_rect
.top
,
3927 "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
3928 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3929 expected_rect
.left
, expected_rect
.top
, expected_rect
.right
, expected_rect
.bottom
);
3930 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3934 RECT rect
, *r
= (RECT
*)lp
;
3935 GetWindowRect( hwnd
, &rect
);
3936 ok( !memcmp( &rect
, r
, sizeof(rect
) ),
3937 "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
3938 r
->left
, r
->top
, r
->right
, r
->bottom
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
);
3939 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3942 return DefWindowProc(hwnd
, msg
, wp
, lp
);
3946 static void test_CreateWindow(void)
3954 #define expect_menu(window, menu) \
3955 SetLastError(0xdeadbeef); \
3956 ok(GetMenu(window) == (HMENU)menu, "GetMenu error %d\n", GetLastError())
3958 #define expect_style(window, style)\
3959 ok(GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
3961 #define expect_ex_style(window, ex_style)\
3962 ok(GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
3964 hmenu
= CreateMenu();
3966 parent
= GetDesktopWindow();
3967 assert(parent
!= 0);
3969 SetLastError(0xdeadbeef);
3970 ok(IsMenu(hmenu
), "IsMenu error %d\n", GetLastError());
3973 SetLastError(0xdeadbeef);
3974 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
,
3975 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3976 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3977 expect_menu(hwnd
, 1);
3978 expect_style(hwnd
, WS_CHILD
);
3979 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
3980 DestroyWindow(hwnd
);
3982 SetLastError(0xdeadbeef);
3983 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_CAPTION
,
3984 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3985 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3986 expect_menu(hwnd
, 1);
3987 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
3988 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
3989 DestroyWindow(hwnd
);
3991 SetLastError(0xdeadbeef);
3992 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
,
3993 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
3994 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
3995 expect_menu(hwnd
, 1);
3996 expect_style(hwnd
, WS_CHILD
);
3997 expect_ex_style(hwnd
, 0);
3998 DestroyWindow(hwnd
);
4000 SetLastError(0xdeadbeef);
4001 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_CAPTION
,
4002 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4003 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4004 expect_menu(hwnd
, 1);
4005 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
);
4006 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4007 DestroyWindow(hwnd
);
4010 SetLastError(0xdeadbeef);
4011 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
,
4012 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4013 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4014 expect_menu(hwnd
, hmenu
);
4015 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4016 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4017 DestroyWindow(hwnd
);
4018 SetLastError(0xdeadbeef);
4019 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4020 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4022 hmenu
= CreateMenu();
4024 SetLastError(0xdeadbeef);
4025 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4026 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4027 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4028 expect_menu(hwnd
, hmenu
);
4029 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4030 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4031 DestroyWindow(hwnd
);
4032 SetLastError(0xdeadbeef);
4033 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4034 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4036 hmenu
= CreateMenu();
4038 SetLastError(0xdeadbeef);
4039 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
,
4040 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4041 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4042 expect_menu(hwnd
, hmenu
);
4043 expect_style(hwnd
, WS_POPUP
| WS_CLIPSIBLINGS
);
4044 expect_ex_style(hwnd
, 0);
4045 DestroyWindow(hwnd
);
4046 SetLastError(0xdeadbeef);
4047 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4048 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4050 hmenu
= CreateMenu();
4052 SetLastError(0xdeadbeef);
4053 hwnd
= CreateWindowEx(0, "static", NULL
, WS_POPUP
| WS_CAPTION
,
4054 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4055 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4056 expect_menu(hwnd
, hmenu
);
4057 expect_style(hwnd
, WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4058 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4059 DestroyWindow(hwnd
);
4060 SetLastError(0xdeadbeef);
4061 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4062 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4064 /* WS_CHILD | WS_POPUP */
4065 SetLastError(0xdeadbeef);
4066 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4067 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4068 ok(!hwnd
, "CreateWindowEx should fail\n");
4069 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4071 hmenu
= CreateMenu();
4073 SetLastError(0xdeadbeef);
4074 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
,
4075 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4076 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4077 expect_menu(hwnd
, hmenu
);
4078 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4079 expect_ex_style(hwnd
, WS_EX_APPWINDOW
);
4080 DestroyWindow(hwnd
);
4081 SetLastError(0xdeadbeef);
4082 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4083 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4085 SetLastError(0xdeadbeef);
4086 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4087 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4088 ok(!hwnd
, "CreateWindowEx should fail\n");
4089 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4091 hmenu
= CreateMenu();
4093 SetLastError(0xdeadbeef);
4094 hwnd
= CreateWindowEx(WS_EX_APPWINDOW
, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4095 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4096 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4097 expect_menu(hwnd
, hmenu
);
4098 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4099 expect_ex_style(hwnd
, WS_EX_APPWINDOW
| WS_EX_WINDOWEDGE
);
4100 DestroyWindow(hwnd
);
4101 SetLastError(0xdeadbeef);
4102 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4103 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4105 SetLastError(0xdeadbeef);
4106 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4107 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4108 ok(!hwnd
, "CreateWindowEx should fail\n");
4109 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4111 hmenu
= CreateMenu();
4113 SetLastError(0xdeadbeef);
4114 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
,
4115 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4116 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4117 expect_menu(hwnd
, hmenu
);
4118 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CLIPSIBLINGS
);
4119 expect_ex_style(hwnd
, 0);
4120 DestroyWindow(hwnd
);
4121 SetLastError(0xdeadbeef);
4122 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4123 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4125 SetLastError(0xdeadbeef);
4126 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4127 0, 0, 100, 100, parent
, (HMENU
)1, 0, NULL
);
4128 ok(!hwnd
, "CreateWindowEx should fail\n");
4129 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4131 hmenu
= CreateMenu();
4133 SetLastError(0xdeadbeef);
4134 hwnd
= CreateWindowEx(0, "static", NULL
, WS_CHILD
| WS_POPUP
| WS_CAPTION
,
4135 0, 0, 100, 100, parent
, hmenu
, 0, NULL
);
4136 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4137 expect_menu(hwnd
, hmenu
);
4138 expect_style(hwnd
, WS_CHILD
| WS_POPUP
| WS_CAPTION
| WS_CLIPSIBLINGS
);
4139 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4140 DestroyWindow(hwnd
);
4141 SetLastError(0xdeadbeef);
4142 ok(!IsMenu(hmenu
), "IsMenu should fail\n");
4143 ok(GetLastError() == ERROR_INVALID_MENU_HANDLE
, "IsMenu set error %d\n", GetLastError());
4145 /* test child window sizing */
4147 cls
.lpfnWndProc
= minmax_wnd_proc
;
4150 cls
.hInstance
= GetModuleHandle(0);
4152 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4153 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4154 cls
.lpszMenuName
= NULL
;
4155 cls
.lpszClassName
= "MinMax_WndClass";
4156 RegisterClass(&cls
);
4158 SetLastError(0xdeadbeef);
4159 parent
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4160 0, 0, 100, 100, 0, 0, 0, NULL
);
4161 ok(parent
!= 0, "CreateWindowEx error %d\n", GetLastError());
4162 expect_menu(parent
, 0);
4163 expect_style(parent
, WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
| WS_CLIPSIBLINGS
);
4164 expect_ex_style(parent
, WS_EX_WINDOWEDGE
);
4166 memset(&minmax
, 0, sizeof(minmax
));
4167 SendMessage(parent
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4168 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxSize
.x
, minmax
.ptMaxSize
.y
);
4169 ok(IsRectEmpty(&rc_minmax
), "ptMaxSize is not empty\n");
4170 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4171 ok(IsRectEmpty(&rc_minmax
), "ptMaxTrackSize is not empty\n");
4173 GetWindowRect(parent
, &rc
);
4174 ok(!IsRectEmpty(&rc
), "parent window rect is empty\n");
4175 GetClientRect(parent
, &rc
);
4176 ok(!IsRectEmpty(&rc
), "parent client rect is empty\n");
4178 InflateRect(&rc
, 200, 200);
4179 trace("creating child with rect (%d,%d-%d,%d)\n", rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
4181 SetLastError(0xdeadbeef);
4182 hwnd
= CreateWindowEx(0, "MinMax_WndClass", NULL
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
,
4183 rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
4184 parent
, (HMENU
)1, 0, NULL
);
4185 ok(hwnd
!= 0, "CreateWindowEx error %d\n", GetLastError());
4186 expect_menu(hwnd
, 1);
4187 expect_style(hwnd
, WS_CHILD
| WS_CAPTION
| WS_SYSMENU
| WS_THICKFRAME
);
4188 expect_ex_style(hwnd
, WS_EX_WINDOWEDGE
);
4190 memset(&minmax
, 0, sizeof(minmax
));
4191 SendMessage(hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&minmax
);
4192 SetRect(&rc_minmax
, 0, 0, minmax
.ptMaxTrackSize
.x
, minmax
.ptMaxTrackSize
.y
);
4194 GetWindowRect(hwnd
, &rc
);
4195 OffsetRect(&rc
, -rc
.left
, -rc
.top
);
4196 ok(EqualRect(&rc
, &rc_minmax
), "rects don't match: (%d,%d-%d,%d) and (%d,%d-%d,%d)\n",
4197 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
4198 rc_minmax
.left
, rc_minmax
.top
, rc_minmax
.right
, rc_minmax
.bottom
);
4199 DestroyWindow(hwnd
);
4201 cls
.lpfnWndProc
= winsizes_wnd_proc
;
4202 cls
.lpszClassName
= "Sizes_WndClass";
4203 RegisterClass(&cls
);
4205 expected_cx
= expected_cy
= 200000;
4206 SetRect( &expected_rect
, 0, 0, 200000, 200000 );
4207 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, 300000, 300000, 200000, 200000, parent
, 0, 0, NULL
);
4208 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4209 GetClientRect( hwnd
, &rc
);
4210 ok( rc
.right
== 200000, "invalid rect right %u\n", rc
.right
);
4211 ok( rc
.bottom
== 200000, "invalid rect bottom %u\n", rc
.bottom
);
4212 DestroyWindow(hwnd
);
4214 expected_cx
= expected_cy
= -10;
4215 SetRect( &expected_rect
, 0, 0, 0, 0 );
4216 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -20, -20, -10, -10, parent
, 0, 0, NULL
);
4217 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4218 GetClientRect( hwnd
, &rc
);
4219 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4220 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4221 DestroyWindow(hwnd
);
4223 expected_cx
= expected_cy
= -200000;
4224 SetRect( &expected_rect
, 0, 0, 0, 0 );
4225 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_CHILD
, -300000, -300000, -200000, -200000, parent
, 0, 0, NULL
);
4226 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4227 GetClientRect( hwnd
, &rc
);
4228 ok( rc
.right
== 0, "invalid rect right %u\n", rc
.right
);
4229 ok( rc
.bottom
== 0, "invalid rect bottom %u\n", rc
.bottom
);
4230 DestroyWindow(hwnd
);
4232 /* top level window */
4233 expected_cx
= expected_cy
= 200000;
4234 SetRect( &expected_rect
, 0, 0, GetSystemMetrics(SM_CXMAXTRACK
), GetSystemMetrics(SM_CYMAXTRACK
) );
4235 hwnd
= CreateWindowExA(0, "Sizes_WndClass", NULL
, WS_OVERLAPPEDWINDOW
, 300000, 300000, 200000, 200000, 0, 0, 0, NULL
);
4236 ok( hwnd
!= 0, "creation failed err %u\n", GetLastError());
4237 GetClientRect( hwnd
, &rc
);
4238 ok( rc
.right
<= expected_cx
, "invalid rect right %u\n", rc
.right
);
4239 ok( rc
.bottom
<= expected_cy
, "invalid rect bottom %u\n", rc
.bottom
);
4240 DestroyWindow(hwnd
);
4242 DestroyWindow(parent
);
4244 UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
4245 UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
4249 #undef expect_ex_style
4252 /* function that remembers whether the system the test is running on sets the
4253 * last error for user32 functions to make the tests stricter */
4254 static int check_error(DWORD actual
, DWORD expected
)
4256 static int sets_last_error
= -1;
4257 if (sets_last_error
== -1)
4258 sets_last_error
= (actual
!= 0xdeadbeef);
4259 return (!sets_last_error
&& (actual
== 0xdeadbeef)) || (actual
== expected
);
4262 static void test_SetWindowLong(void)
4265 WNDPROC old_window_procW
;
4267 SetLastError(0xdeadbeef);
4268 retval
= SetWindowLongPtr(NULL
, GWLP_WNDPROC
, 0);
4269 ok(!retval
, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval
);
4270 ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE
),
4271 "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instad of %d\n", GetLastError());
4273 SetLastError(0xdeadbeef);
4274 retval
= SetWindowLongPtr(hwndMain
, 0xdeadbeef, 0);
4275 ok(!retval
, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval
);
4276 ok(check_error(GetLastError(), ERROR_INVALID_INDEX
),
4277 "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instad of %d\n", GetLastError());
4279 SetLastError(0xdeadbeef);
4280 retval
= SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4281 ok((WNDPROC
)retval
== main_window_procA
,
4282 "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval
);
4283 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4284 retval
= GetWindowLongPtr(hwndMain
, GWLP_WNDPROC
);
4285 ok((WNDPROC
)retval
== main_window_procA
,
4286 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4287 ok(!IsWindowUnicode(hwndMain
), "hwndMain shouldn't be Unicode\n");
4289 old_window_procW
= (WNDPROC
)GetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
);
4290 SetLastError(0xdeadbeef);
4291 retval
= SetWindowLongPtrW(hwndMain
, GWLP_WNDPROC
, 0);
4292 if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED
)
4294 ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
4295 ok(retval
!= 0, "SetWindowLongPtr error %d\n", GetLastError());
4296 ok((WNDPROC
)retval
== old_window_procW
,
4297 "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval
);
4298 ok(IsWindowUnicode(hwndMain
), "hwndMain should now be Unicode\n");
4300 /* set it back to ANSI */
4301 SetWindowLongPtr(hwndMain
, GWLP_WNDPROC
, 0);
4305 static void test_ShowWindow(void)
4312 SetRect(&rcMain
, 120, 120, 210, 210);
4314 hwnd
= CreateWindowEx(0, "MainWindowClass", NULL
,
4315 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4316 WS_MAXIMIZEBOX
| WS_POPUP
,
4317 rcMain
.left
, rcMain
.top
,
4318 rcMain
.right
- rcMain
.left
, rcMain
.bottom
- rcMain
.top
,
4322 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4323 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4324 ok(!(style
& WS_VISIBLE
), "window should not be visible\n");
4325 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4326 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4327 GetWindowRect(hwnd
, &rc
);
4328 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4330 ret
= ShowWindow(hwnd
, SW_SHOW
);
4331 ok(!ret
, "not expected ret: %lu\n", ret
);
4332 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4333 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4334 ok(style
& WS_VISIBLE
, "window should be visible\n");
4335 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4336 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4337 GetWindowRect(hwnd
, &rc
);
4338 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4340 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4341 ok(ret
, "not expected ret: %lu\n", ret
);
4342 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4343 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4344 ok(style
& WS_VISIBLE
, "window should be visible\n");
4345 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4346 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4347 GetWindowRect(hwnd
, &rc
);
4348 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4350 ShowWindow(hwnd
, SW_RESTORE
);
4351 ok(ret
, "not expected ret: %lu\n", ret
);
4352 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4353 ok(!(style
& WS_DISABLED
), "window should not be disabled\n");
4354 ok(style
& WS_VISIBLE
, "window should be visible\n");
4355 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4356 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4357 GetWindowRect(hwnd
, &rc
);
4358 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4360 ret
= EnableWindow(hwnd
, FALSE
);
4361 ok(!ret
, "not expected ret: %lu\n", ret
);
4362 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4363 ok(style
& WS_DISABLED
, "window should be disabled\n");
4365 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
4366 ok(!ret
, "not expected ret: %lu\n", ret
);
4367 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4368 ok(style
& WS_DISABLED
, "window should be disabled\n");
4369 ok(style
& WS_VISIBLE
, "window should be visible\n");
4370 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4371 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4372 GetWindowRect(hwnd
, &rc
);
4373 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4375 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
4376 ok(!ret
, "not expected ret: %lu\n", ret
);
4377 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4378 ok(style
& WS_DISABLED
, "window should be disabled\n");
4379 ok(style
& WS_VISIBLE
, "window should be visible\n");
4380 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4381 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4382 GetWindowRect(hwnd
, &rc
);
4383 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4385 ret
= ShowWindow(hwnd
, SW_MINIMIZE
);
4386 ok(ret
, "not expected ret: %lu\n", ret
);
4387 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4388 ok(style
& WS_DISABLED
, "window should be disabled\n");
4389 ok(style
& WS_VISIBLE
, "window should be visible\n");
4390 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4391 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4392 GetWindowRect(hwnd
, &rc
);
4393 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4395 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
4396 ok(!ret
, "not expected ret: %lu\n", ret
);
4397 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4398 ok(style
& WS_DISABLED
, "window should be disabled\n");
4399 ok(style
& WS_VISIBLE
, "window should be visible\n");
4400 ok(style
& WS_MINIMIZE
, "window should be minimized\n");
4401 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4402 GetWindowRect(hwnd
, &rc
);
4403 ok(!EqualRect(&rcMain
, &rc
), "rects shouldn't match\n");
4405 ret
= ShowWindow(hwnd
, SW_RESTORE
);
4406 ok(ret
, "not expected ret: %lu\n", ret
);
4407 style
= GetWindowLong(hwnd
, GWL_STYLE
);
4408 ok(style
& WS_DISABLED
, "window should be disabled\n");
4409 ok(style
& WS_VISIBLE
, "window should be visible\n");
4410 ok(!(style
& WS_MINIMIZE
), "window should not be minimized\n");
4411 ok(!(style
& WS_MAXIMIZE
), "window should not be maximized\n");
4412 GetWindowRect(hwnd
, &rc
);
4413 ok(EqualRect(&rcMain
, &rc
), "rects should match\n");
4415 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4416 ok(!ret
, "not expected ret: %lu\n", ret
);
4417 ok(IsWindow(hwnd
), "window should exist\n");
4419 ret
= EnableWindow(hwnd
, TRUE
);
4420 ok(ret
, "not expected ret: %lu\n", ret
);
4422 ret
= DefWindowProc(hwnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
4423 ok(!ret
, "not expected ret: %lu\n", ret
);
4424 ok(!IsWindow(hwnd
), "window should not exist\n");
4427 static void test_gettext(void)
4430 LPCSTR clsname
= "gettexttest";
4434 memset( &cls
, 0, sizeof cls
);
4435 cls
.lpfnWndProc
= DefWindowProc
;
4436 cls
.lpszClassName
= clsname
;
4437 cls
.hInstance
= GetModuleHandle(NULL
);
4439 if (!RegisterClass( &cls
)) return;
4441 hwnd
= CreateWindow( clsname
, "test text", WS_OVERLAPPED
, 0, 0, 10, 10, 0, NULL
, NULL
, NULL
);
4442 ok( hwnd
!= NULL
, "window was null\n");
4444 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10, 0x1000);
4445 ok( r
== 0, "settext should return zero\n");
4447 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x10000, 0);
4448 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4450 r
= SendMessage( hwnd
, WM_GETTEXT
, 0xff000000, 0x1000);
4451 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4453 r
= SendMessage( hwnd
, WM_GETTEXT
, 0x1000, 0xff000000);
4454 ok( r
== 0, "settext should return zero (%ld)\n", r
);
4456 DestroyWindow(hwnd
);
4457 UnregisterClass( clsname
, NULL
);
4461 static void test_GetUpdateRect(void)
4464 BOOL ret
, parent_wm_paint
, grandparent_wm_paint
;
4466 HWND hgrandparent
, hparent
, hchild
;
4468 static const char classNameA
[] = "GetUpdateRectClass";
4470 hgrandparent
= CreateWindowA("static", "grandparent", WS_OVERLAPPEDWINDOW
,
4471 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4473 hparent
= CreateWindowA("static", "parent", WS_CHILD
|WS_VISIBLE
,
4474 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4476 hchild
= CreateWindowA("static", "child", WS_CHILD
|WS_VISIBLE
,
4477 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4479 ShowWindow(hgrandparent
, SW_SHOW
);
4480 UpdateWindow(hgrandparent
);
4481 flush_events( TRUE
);
4483 ShowWindow(hchild
, SW_HIDE
);
4484 SetRect(&rc2
, 0, 0, 0, 0);
4485 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4486 ok(!ret
, "GetUpdateRect returned not empty region\n");
4487 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4488 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4489 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4491 SetRect(&rc2
, 10, 10, 40, 40);
4492 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4493 ok(ret
, "GetUpdateRect returned empty region\n");
4494 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4495 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4496 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4498 parent_wm_paint
= FALSE
;
4499 grandparent_wm_paint
= FALSE
;
4500 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4502 if (msg
.message
== WM_PAINT
)
4504 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4505 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4507 DispatchMessage(&msg
);
4509 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4510 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4512 DestroyWindow(hgrandparent
);
4515 cls
.lpfnWndProc
= DefWindowProcA
;
4518 cls
.hInstance
= GetModuleHandleA(0);
4520 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
4521 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4522 cls
.lpszMenuName
= NULL
;
4523 cls
.lpszClassName
= classNameA
;
4525 if(!RegisterClassA(&cls
)) {
4526 trace("Register failed %d\n", GetLastError());
4530 hgrandparent
= CreateWindowA(classNameA
, "grandparent", WS_OVERLAPPEDWINDOW
,
4531 0, 0, 100, 100, NULL
, NULL
, 0, NULL
);
4533 hparent
= CreateWindowA(classNameA
, "parent", WS_CHILD
|WS_VISIBLE
,
4534 0, 0, 100, 100, hgrandparent
, NULL
, 0, NULL
);
4536 hchild
= CreateWindowA(classNameA
, "child", WS_CHILD
|WS_VISIBLE
,
4537 10, 10, 30, 30, hparent
, NULL
, 0, NULL
);
4539 ShowWindow(hgrandparent
, SW_SHOW
);
4540 UpdateWindow(hgrandparent
);
4541 flush_events( TRUE
);
4543 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4544 ok(!ret
, "GetUpdateRect returned not empty region\n");
4546 ShowWindow(hchild
, SW_HIDE
);
4548 SetRect(&rc2
, 0, 0, 0, 0);
4549 ret
= GetUpdateRect(hgrandparent
, &rc1
, FALSE
);
4550 ok(!ret
, "GetUpdateRect returned not empty region\n");
4551 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4552 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4553 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4555 SetRect(&rc2
, 10, 10, 40, 40);
4556 ret
= GetUpdateRect(hparent
, &rc1
, FALSE
);
4557 ok(ret
, "GetUpdateRect returned empty region\n");
4558 ok(EqualRect(&rc1
, &rc2
), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
4559 rc1
.left
, rc1
.top
, rc1
.right
, rc1
.bottom
,
4560 rc2
.left
, rc2
.top
, rc2
.right
, rc2
.bottom
);
4562 parent_wm_paint
= FALSE
;
4563 grandparent_wm_paint
= FALSE
;
4564 while (PeekMessage(&msg
, 0, 0, 0, PM_REMOVE
))
4566 if (msg
.message
== WM_PAINT
)
4568 if (msg
.hwnd
== hgrandparent
) grandparent_wm_paint
= TRUE
;
4569 if (msg
.hwnd
== hparent
) parent_wm_paint
= TRUE
;
4571 DispatchMessage(&msg
);
4573 ok(parent_wm_paint
, "WM_PAINT should have been received in parent\n");
4574 ok(!grandparent_wm_paint
, "WM_PAINT should NOT have been received in grandparent\n");
4576 DestroyWindow(hgrandparent
);
4580 static LRESULT CALLBACK
TestExposedRegion_WndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4588 const int waitTime
= 2000;
4590 BeginPaint(hwnd
, &ps
);
4592 /* create and destroy window to create an exposed region on this window */
4593 win
= CreateWindowA("static", "win", WS_VISIBLE
,
4594 10,10,50,50, NULL
, NULL
, 0, NULL
);
4597 waitResult
= MsgWaitForMultipleObjects( 0, NULL
, FALSE
, waitTime
, QS_PAINT
);
4599 ValidateRect(hwnd
, NULL
);
4600 EndPaint(hwnd
, &ps
);
4602 if(waitResult
!= WAIT_TIMEOUT
)
4604 GetUpdateRect(hwnd
, &updateRect
, FALSE
);
4607 ok(!IsRectEmpty(&updateRect
), "Exposed rect should not be empty\n");
4613 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
4616 static void test_Expose(void)
4621 memset(&cls
, 0, sizeof(WNDCLASSA
));
4622 cls
.lpfnWndProc
= TestExposedRegion_WndProc
;
4623 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
4624 cls
.lpszClassName
= "TestExposeClass";
4625 atom
= RegisterClassA(&cls
);
4627 mw
= CreateWindowA("TestExposeClass", "MainWindow", WS_VISIBLE
|WS_OVERLAPPEDWINDOW
,
4628 0, 0, 200, 100, NULL
, NULL
, 0, NULL
);
4634 static void test_GetWindowModuleFileName(void)
4639 char buf1
[MAX_PATH
], buf2
[MAX_PATH
];
4641 hwnd
= CreateWindowExA(0, "static", NULL
, WS_POPUP
, 0,0,0,0, 0, 0, 0, NULL
);
4644 hinst
= (HINSTANCE
)GetWindowLongPtr(hwnd
, GWLP_HINSTANCE
);
4645 ok(hinst
== 0, "expected 0, got %p\n", hinst
);
4648 SetLastError(0xdeadbeef);
4649 ret1
= GetModuleFileName(hinst
, buf1
, sizeof(buf1
));
4650 ok(ret1
, "GetModuleFileName error %u\n", GetLastError());
4653 SetLastError(0xdeadbeef);
4654 ret2
= GetWindowModuleFileName(hwnd
, buf2
, sizeof(buf2
));
4655 ok(ret2
, "GetWindowModuleFileName error %u\n", GetLastError());
4657 ok(ret1
== ret2
, "%u != %u\n", ret1
, ret2
);
4658 ok(!strcmp(buf1
, buf2
), "%s != %s\n", buf1
, buf2
);
4660 hinst
= GetModuleHandle(0);
4662 /* MSDN mentions ERROR_INSUFFICIENT_BUFFER, but XP doesn't do it */
4663 SetLastError(0xdeadbeef);
4664 ret2
= GetModuleFileName(hinst
, buf2
, ret1
- 2);
4665 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4666 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4668 SetLastError(0xdeadbeef);
4669 ret2
= GetModuleFileName(hinst
, buf2
, 0);
4670 ok(!ret2
, "GetModuleFileName should return 0\n");
4671 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4673 SetLastError(0xdeadbeef);
4674 ret2
= GetWindowModuleFileName(hwnd
, buf2
, ret1
- 2);
4675 ok(ret2
== ret1
- 2, "expected %u, got %u\n", ret1
- 2, ret2
);
4676 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4678 SetLastError(0xdeadbeef);
4679 ret2
= GetWindowModuleFileName(hwnd
, buf2
, 0);
4680 ok(!ret2
, "expected 0, got %u\n", ret2
);
4681 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
4683 DestroyWindow(hwnd
);
4686 hwnd
= (HWND
)0xdeadbeef;
4687 SetLastError(0xdeadbeef);
4688 ret1
= GetWindowModuleFileName(hwnd
, buf1
, sizeof(buf1
));
4689 ok(!ret1
, "expected 0, got %u\n", ret1
);
4690 ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE
, "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
4692 hwnd
= GetDesktopWindow();
4693 ok(IsWindow(hwnd
), "got invalid desktop window %p\n", hwnd
);
4694 SetLastError(0xdeadbeef);
4695 ret1
= GetWindowModuleFileName(hwnd
, buf1
, sizeof(buf1
));
4696 ok(!ret1
, "expected 0, got %u\n", ret1
);
4698 hwnd
= FindWindow("Shell_TrayWnd", NULL
);
4699 ok(IsWindow(hwnd
), "got invalid tray window %p\n", hwnd
);
4700 SetLastError(0xdeadbeef);
4701 ret1
= GetWindowModuleFileName(hwnd
, buf1
, sizeof(buf1
));
4702 ok(!ret1
, "expected 0, got %u\n", ret1
);
4707 pGetAncestor
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
4708 pGetWindowInfo
= (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetWindowInfo" );
4710 hwndMain
= CreateWindowExA(0, "static", NULL
, 0, 0, 0, 0, 0, HWND_MESSAGE
, 0, 0, NULL
);
4713 ok(!GetParent(hwndMain
), "GetParent should return 0 for message only windows\n");
4716 hwndMessage
= pGetAncestor(hwndMain
, GA_PARENT
);
4717 ok(hwndMessage
!= 0, "GetAncestor(GA_PARENT) should not return 0 for message only windows\n");
4718 trace("hwndMessage %p\n", hwndMessage
);
4720 DestroyWindow(hwndMain
);
4723 trace("CreateWindowExA with parent HWND_MESSAGE failed\n");
4725 if (!RegisterWindowClasses()) assert(0);
4727 hhook
= SetWindowsHookExA(WH_CBT
, cbt_hook_proc
, 0, GetCurrentThreadId());
4730 hwndMain
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
4731 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4732 WS_MAXIMIZEBOX
| WS_POPUP
,
4734 0, 0, GetModuleHandle(0), NULL
);
4735 test_nonclient_area(hwndMain
);
4737 hwndMain2
= CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
4738 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
4739 WS_MAXIMIZEBOX
| WS_POPUP
,
4741 0, 0, GetModuleHandle(0), NULL
);
4743 assert( hwndMain2
);
4745 our_pid
= GetWindowThreadProcessId(hwndMain
, NULL
);
4747 /* Add the tests below this line */
4749 test_GetWindowModuleFileName();
4752 test_capture_3(hwndMain
, hwndMain2
);
4754 test_CreateWindow();
4755 test_parent_owner();
4757 test_shell_window();
4761 test_SetWindowPos(hwndMain
);
4762 test_SetMenu(hwndMain
);
4763 test_SetFocus(hwndMain
);
4764 test_SetActiveWindow(hwndMain
);
4765 test_SetForegroundWindow(hwndMain
);
4767 test_children_zorder(hwndMain
);
4768 test_popup_zorder(hwndMain2
, hwndMain
);
4769 test_keyboard_input(hwndMain
);
4770 test_mouse_input(hwndMain
);
4771 test_validatergn(hwndMain
);
4772 test_nccalcscroll( hwndMain
);
4773 test_scrollvalidate( hwndMain
);
4774 test_scrolldc( hwndMain
);
4776 test_IsWindowUnicode();
4777 test_vis_rgn(hwndMain
);
4779 test_AdjustWindowRect();
4780 test_window_styles();
4783 test_SetWindowLong();
4786 test_GetUpdateRect();
4789 /* add the tests above this line */
4790 UnhookWindowsHookEx(hhook
);