1 /* Unit tests for appbars
3 * Copyright 2008 Vincent Povirk for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 #define MSG_APPBAR WM_APP
29 static const CHAR testwindow_class
[] = "testwindow";
31 static HMONITOR (WINAPI
*pMonitorFromWindow
)(HWND
, DWORD
);
33 typedef BOOL (*boolean_function
)(void);
35 struct testwindow_info
45 static struct testwindow_info windows
[3];
47 static int expected_bottom
;
49 static void testwindow_setpos(HWND hwnd
)
51 struct testwindow_info
* info
= (struct testwindow_info
*)GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
55 ok(info
!= NULL
, "got unexpected ABN_POSCHANGED notification\n");
57 if (!info
|| !info
->registered
)
62 if (info
->to_be_deleted
)
64 win_skip("Some Win95 and NT4 systems send messages to removed taskbars\n");
68 abd
.cbSize
= sizeof(abd
);
70 abd
.uEdge
= info
->edge
;
71 abd
.rc
= info
->desired_rect
;
72 ret
= SHAppBarMessage(ABM_QUERYPOS
, &abd
);
73 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
77 ok(info
->desired_rect
.top
== abd
.rc
.top
, "ABM_QUERYPOS changed top of rect from %i to %i\n", info
->desired_rect
.top
, abd
.rc
.top
);
78 abd
.rc
.top
= abd
.rc
.bottom
- (info
->desired_rect
.bottom
- info
->desired_rect
.top
);
81 ok(info
->desired_rect
.right
== abd
.rc
.right
, "ABM_QUERYPOS changed right of rect from %i to %i\n", info
->desired_rect
.right
, abd
.rc
.right
);
82 abd
.rc
.right
= abd
.rc
.left
+ (info
->desired_rect
.right
- info
->desired_rect
.left
);
85 ok(info
->desired_rect
.left
== abd
.rc
.left
, "ABM_QUERYPOS changed left of rect from %i to %i\n", info
->desired_rect
.left
, abd
.rc
.left
);
86 abd
.rc
.left
= abd
.rc
.right
- (info
->desired_rect
.right
- info
->desired_rect
.left
);
89 ok(info
->desired_rect
.bottom
== abd
.rc
.bottom
, "ABM_QUERYPOS changed bottom of rect from %i to %i\n", info
->desired_rect
.bottom
, abd
.rc
.bottom
);
90 abd
.rc
.bottom
= abd
.rc
.top
+ (info
->desired_rect
.bottom
- info
->desired_rect
.top
);
94 ret
= SHAppBarMessage(ABM_SETPOS
, &abd
);
95 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
97 info
->allocated_rect
= abd
.rc
;
98 MoveWindow(hwnd
, abd
.rc
.left
, abd
.rc
.top
, abd
.rc
.right
-abd
.rc
.left
, abd
.rc
.bottom
-abd
.rc
.top
, TRUE
);
101 static LRESULT CALLBACK
testwindow_wndproc(HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
110 testwindow_setpos(hwnd
);
117 return DefWindowProc(hwnd
, msg
, wparam
, lparam
);
120 /* process pending messages until a condition is true or 3 seconds pass */
121 static void do_events_until(boolean_function test
)
127 timerid
= SetTimer(0, 0, 3000, NULL
);
131 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
133 if (msg
.hwnd
== 0 && msg
.message
== WM_TIMER
&& msg
.wParam
== timerid
)
135 TranslateMessage(&msg
);
136 DispatchMessageA(&msg
);
138 if (timedout
|| test())
143 KillTimer(0, timerid
);
146 /* process any pending messages */
147 static void do_events(void)
151 while (PeekMessageA(&msg
, NULL
, 0, 0, PM_REMOVE
))
153 TranslateMessage(&msg
);
154 DispatchMessageA(&msg
);
158 static BOOL
no_appbars_intersect(void)
165 for (j
=i
+1; j
<3; j
++)
167 if (windows
[i
].registered
&& windows
[j
].registered
&&
168 IntersectRect(&rc
, &windows
[i
].allocated_rect
, &windows
[j
].allocated_rect
))
175 static BOOL
got_expected_bottom(void)
177 return (no_appbars_intersect() && windows
[1].allocated_rect
.bottom
== expected_bottom
);
180 static void register_testwindow_class(void)
184 ZeroMemory(&cls
, sizeof(cls
));
185 cls
.cbSize
= sizeof(cls
);
187 cls
.lpfnWndProc
= testwindow_wndproc
;
188 cls
.hInstance
= NULL
;
189 cls
.hCursor
= LoadCursor(0, IDC_ARROW
);
190 cls
.hbrBackground
= (HBRUSH
) COLOR_WINDOW
;
191 cls
.lpszClassName
= testwindow_class
;
193 RegisterClassExA(&cls
);
196 #define test_window_rects(a, b) \
197 ok(!IntersectRect(&rc, &windows[a].allocated_rect, &windows[b].allocated_rect), \
198 "rectangles intersect (%i,%i,%i,%i)/(%i,%i,%i,%i)\n", \
199 windows[a].allocated_rect.left, windows[a].allocated_rect.top, windows[a].allocated_rect.right, windows[a].allocated_rect.bottom, \
200 windows[b].allocated_rect.left, windows[b].allocated_rect.top, windows[b].allocated_rect.right, windows[b].allocated_rect.bottom)
202 static void test_setpos(void)
206 int screen_width
, screen_height
;
210 screen_width
= GetSystemMetrics(SM_CXSCREEN
);
211 screen_height
= GetSystemMetrics(SM_CYSCREEN
);
213 /* create and register windows[0] */
214 windows
[0].hwnd
= CreateWindowExA(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
,
215 testwindow_class
, testwindow_class
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0,
216 NULL
, NULL
, NULL
, NULL
);
217 ok(windows
[0].hwnd
!= NULL
, "couldn't create window\n");
219 abd
.cbSize
= sizeof(abd
);
220 abd
.hWnd
= windows
[0].hwnd
;
221 abd
.uCallbackMessage
= MSG_APPBAR
;
222 ret
= SHAppBarMessage(ABM_NEW
, &abd
);
223 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
225 /* ABM_NEW should return FALSE if the window is already registered */
226 ret
= SHAppBarMessage(ABM_NEW
, &abd
);
227 ok(ret
== FALSE
, "SHAppBarMessage returned %i\n", ret
);
230 /* dock windows[0] to the bottom of the screen */
231 windows
[0].registered
= TRUE
;
232 windows
[0].to_be_deleted
= FALSE
;
233 windows
[0].edge
= ABE_BOTTOM
;
234 windows
[0].desired_rect
.left
= 0;
235 windows
[0].desired_rect
.right
= screen_width
;
236 windows
[0].desired_rect
.top
= screen_height
- 15;
237 windows
[0].desired_rect
.bottom
= screen_height
;
238 SetWindowLongPtr(windows
[0].hwnd
, GWLP_USERDATA
, (LONG_PTR
)&windows
[0]);
239 testwindow_setpos(windows
[0].hwnd
);
242 /* create and register windows[1] */
243 windows
[1].hwnd
= CreateWindowExA(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
,
244 testwindow_class
, testwindow_class
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0,
245 NULL
, NULL
, NULL
, NULL
);
246 ok(windows
[1].hwnd
!= NULL
, "couldn't create window\n");
247 abd
.hWnd
= windows
[1].hwnd
;
248 ret
= SHAppBarMessage(ABM_NEW
, &abd
);
249 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
251 /* dock windows[1] to the bottom of the screen */
252 windows
[1].registered
= TRUE
;
253 windows
[1].to_be_deleted
= FALSE
;
254 windows
[1].edge
= ABE_BOTTOM
;
255 windows
[1].desired_rect
.left
= 0;
256 windows
[1].desired_rect
.right
= screen_width
;
257 windows
[1].desired_rect
.top
= screen_height
- 10;
258 windows
[1].desired_rect
.bottom
= screen_height
;
259 SetWindowLongPtr(windows
[1].hwnd
, GWLP_USERDATA
, (LONG_PTR
)&windows
[1]);
260 testwindow_setpos(windows
[1].hwnd
);
262 /* the windows are adjusted to they don't overlap */
263 do_events_until(no_appbars_intersect
);
264 test_window_rects(0, 1);
266 /* make windows[0] larger, forcing windows[1] to move out of its way */
267 windows
[0].desired_rect
.top
= screen_height
- 20;
268 testwindow_setpos(windows
[0].hwnd
);
269 do_events_until(no_appbars_intersect
);
270 test_window_rects(0, 1);
272 /* create and register windows[2] */
273 windows
[2].hwnd
= CreateWindowExA(WS_EX_TOOLWINDOW
|WS_EX_TOPMOST
,
274 testwindow_class
, testwindow_class
, WS_POPUP
|WS_VISIBLE
, 0, 0, 0, 0,
275 NULL
, NULL
, NULL
, NULL
);
276 ok(windows
[2].hwnd
!= NULL
, "couldn't create window\n");
279 abd
.hWnd
= windows
[2].hwnd
;
280 ret
= SHAppBarMessage(ABM_NEW
, &abd
);
281 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
283 /* dock windows[2] to the bottom of the screen */
284 windows
[2].registered
= TRUE
;
285 windows
[2].to_be_deleted
= FALSE
;
286 windows
[2].edge
= ABE_BOTTOM
;
287 windows
[2].desired_rect
.left
= 0;
288 windows
[2].desired_rect
.right
= screen_width
;
289 windows
[2].desired_rect
.top
= screen_height
- 10;
290 windows
[2].desired_rect
.bottom
= screen_height
;
291 SetWindowLongPtr(windows
[2].hwnd
, GWLP_USERDATA
, (LONG_PTR
)&windows
[2]);
292 testwindow_setpos(windows
[2].hwnd
);
294 do_events_until(no_appbars_intersect
);
295 test_window_rects(0, 1);
296 test_window_rects(0, 2);
297 test_window_rects(1, 2);
299 /* move windows[2] to the right side of the screen */
300 windows
[2].edge
= ABE_RIGHT
;
301 windows
[2].desired_rect
.left
= screen_width
- 15;
302 windows
[2].desired_rect
.right
= screen_width
;
303 windows
[2].desired_rect
.top
= 0;
304 windows
[2].desired_rect
.bottom
= screen_height
;
305 testwindow_setpos(windows
[2].hwnd
);
307 do_events_until(no_appbars_intersect
);
308 test_window_rects(0, 1);
309 test_window_rects(0, 2);
310 test_window_rects(1, 2);
312 /* move windows[1] to the top of the screen */
313 windows
[1].edge
= ABE_TOP
;
314 windows
[1].desired_rect
.left
= 0;
315 windows
[1].desired_rect
.right
= screen_width
;
316 windows
[1].desired_rect
.top
= 0;
317 windows
[1].desired_rect
.bottom
= 15;
318 testwindow_setpos(windows
[1].hwnd
);
320 do_events_until(no_appbars_intersect
);
321 test_window_rects(0, 1);
322 test_window_rects(0, 2);
323 test_window_rects(1, 2);
325 /* move windows[1] back to the bottom of the screen */
326 windows
[1].edge
= ABE_BOTTOM
;
327 windows
[1].desired_rect
.left
= 0;
328 windows
[1].desired_rect
.right
= screen_width
;
329 windows
[1].desired_rect
.top
= screen_height
- 10;
330 windows
[1].desired_rect
.bottom
= screen_height
;
331 testwindow_setpos(windows
[1].hwnd
);
333 do_events_until(no_appbars_intersect
);
334 test_window_rects(0, 1);
335 test_window_rects(0, 2);
336 test_window_rects(1, 2);
338 /* removing windows[0] will cause windows[1] to move down into its space */
339 expected_bottom
= max(windows
[0].allocated_rect
.bottom
, windows
[1].allocated_rect
.bottom
);
340 org_bottom1
= windows
[1].allocated_rect
.bottom
;
341 ok(windows
[0].allocated_rect
.bottom
> windows
[1].allocated_rect
.bottom
,
342 "Expected windows[0] to be lower than windows[1]\n");
344 abd
.hWnd
= windows
[0].hwnd
;
345 windows
[0].to_be_deleted
= TRUE
;
346 ret
= SHAppBarMessage(ABM_REMOVE
, &abd
);
347 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
348 windows
[0].registered
= FALSE
;
349 DestroyWindow(windows
[0].hwnd
);
351 do_events_until(got_expected_bottom
);
353 if (windows
[1].allocated_rect
.bottom
== org_bottom1
)
354 win_skip("Some broken Vista boxes don't move the higher appbar down\n");
356 ok(windows
[1].allocated_rect
.bottom
== expected_bottom
,
357 "windows[1]'s bottom is %i, expected %i\n",
358 windows
[1].allocated_rect
.bottom
, expected_bottom
);
360 test_window_rects(1, 2);
362 /* remove the other windows */
363 abd
.hWnd
= windows
[1].hwnd
;
364 windows
[1].to_be_deleted
= TRUE
;
365 ret
= SHAppBarMessage(ABM_REMOVE
, &abd
);
366 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
367 windows
[1].registered
= FALSE
;
368 DestroyWindow(windows
[1].hwnd
);
370 abd
.hWnd
= windows
[2].hwnd
;
371 windows
[2].to_be_deleted
= TRUE
;
372 ret
= SHAppBarMessage(ABM_REMOVE
, &abd
);
373 ok(ret
== TRUE
, "SHAppBarMessage returned %i\n", ret
);
374 windows
[2].registered
= FALSE
;
375 DestroyWindow(windows
[2].hwnd
);
378 static void test_appbarget(void)
381 HWND hwnd
, foregnd
, unset_hwnd
;
384 memset(&abd
, 0xcc, sizeof(abd
));
385 memset(&unset_hwnd
, 0xcc, sizeof(unset_hwnd
));
386 abd
.cbSize
= sizeof(abd
);
387 abd
.uEdge
= ABE_BOTTOM
;
389 hwnd
= (HWND
)SHAppBarMessage(ABM_GETAUTOHIDEBAR
, &abd
);
390 ok(hwnd
== NULL
|| IsWindow(hwnd
), "ret %p which is not a window\n", hwnd
);
391 ok(abd
.hWnd
== unset_hwnd
, "hWnd overwritten %p\n",abd
.hWnd
);
393 if (!pMonitorFromWindow
)
395 win_skip("MonitorFromWindow is not available\n");
399 /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
400 Pass the foreground window and check */
401 foregnd
= GetForegroundWindow();
405 hwnd
= (HWND
)SHAppBarMessage(ABM_GETAUTOHIDEBAR
, &abd
);
406 ok(hwnd
== NULL
|| IsWindow(hwnd
), "ret %p which is not a window\n", hwnd
);
407 ok(abd
.hWnd
== foregnd
, "hWnd overwritten\n");
410 HMONITOR appbar_mon
, foregnd_mon
;
411 appbar_mon
= pMonitorFromWindow(hwnd
, MONITOR_DEFAULTTONEAREST
);
412 foregnd_mon
= pMonitorFromWindow(foregnd
, MONITOR_DEFAULTTONEAREST
);
413 ok(appbar_mon
== foregnd_mon
, "Windows on different monitors\n");
418 memset(&abd
, 0xcc, sizeof(abd
));
419 abd
.cbSize
= sizeof(abd
);
420 ret
= SHAppBarMessage(ABM_GETTASKBARPOS
, &abd
);
423 ok(abd
.hWnd
== (HWND
)0xcccccccc, "hWnd overwritten\n");
424 ok(abd
.uEdge
<= ABE_BOTTOM
||
425 broken(abd
.uEdge
== 0xcccccccc), /* Some Win95 and NT4 */
426 "uEdge not returned\n");
427 ok(abd
.rc
.left
!= 0xcccccccc, "rc not updated\n");
437 huser32
= GetModuleHandleA("user32.dll");
438 pMonitorFromWindow
= (void*)GetProcAddress(huser32
, "MonitorFromWindow");
440 register_testwindow_class();