1 /* Unit tests for systray
3 * Copyright 2007 Mikolaj Zalewski
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
19 #define _WIN32_IE 0x600
25 #include "wine/test.h"
29 static BOOL (WINAPI
*pShell_NotifyIconW
)(DWORD
,PNOTIFYICONDATAW
);
30 static HMONITOR (WINAPI
*pMonitorFromWindow
)(HWND
, DWORD
);
32 void test_cbsize(void)
36 if (pShell_NotifyIconW
)
40 ZeroMemory(&nidW
, sizeof(nidW
));
41 nidW
.cbSize
= NOTIFYICONDATAW_V1_SIZE
;
44 nidW
.uFlags
= NIF_ICON
|NIF_MESSAGE
;
45 nidW
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
46 nidW
.uCallbackMessage
= WM_USER
+17;
47 ok(pShell_NotifyIconW(NIM_ADD
, &nidW
), "NIM_ADD failed!\n");
49 /* using an invalid cbSize does work */
53 ok(pShell_NotifyIconW(NIM_DELETE
, &nidW
), "NIM_DELETE failed!\n");
54 /* as icon doesn't exist anymore - now there will be an error */
55 nidW
.cbSize
= sizeof(nidW
);
56 ok(!pShell_NotifyIconW(NIM_DELETE
, &nidW
), "The icon was not deleted\n");
59 /* same for Shell_NotifyIconA */
60 ZeroMemory(&nidA
, sizeof(nidA
));
61 nidA
.cbSize
= NOTIFYICONDATAA_V1_SIZE
;
64 nidA
.uFlags
= NIF_ICON
|NIF_MESSAGE
;
65 nidA
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
66 nidA
.uCallbackMessage
= WM_USER
+17;
67 ok(Shell_NotifyIconA(NIM_ADD
, &nidA
), "NIM_ADD failed!\n");
69 /* using an invalid cbSize does work */
73 ok(Shell_NotifyIconA(NIM_DELETE
, &nidA
), "NIM_DELETE failed!\n");
74 /* as icon doesn't exist anymore - now there will be an error */
75 nidA
.cbSize
= sizeof(nidA
);
76 ok(!Shell_NotifyIconA(NIM_DELETE
, &nidA
), "The icon was not deleted\n");
79 static void test_SHAppBarMessage(void)
85 memset(&abd
, 0xcc, sizeof(abd
));
86 abd
.cbSize
= sizeof(abd
);
87 abd
.uEdge
= ABE_BOTTOM
;
89 hwnd
= (HWND
)SHAppBarMessage(ABM_GETAUTOHIDEBAR
, &abd
);
90 ok(hwnd
== NULL
|| IsWindow(hwnd
), "ret %p which is not a window\n", hwnd
);
91 ok(abd
.hWnd
== (HWND
)0xcccccccc, "hWnd overwritten\n");
93 if (!pMonitorFromWindow
)
95 skip("MonitorFromWindow is not available\n");
99 /* Presumably one can pass a hwnd with ABM_GETAUTOHIDEBAR to specify a monitor.
100 Pass the foreground window and check */
101 foregnd
= GetForegroundWindow();
105 hwnd
= (HWND
)SHAppBarMessage(ABM_GETAUTOHIDEBAR
, &abd
);
106 ok(hwnd
== NULL
|| IsWindow(hwnd
), "ret %p which is not a window\n", hwnd
);
107 ok(abd
.hWnd
== foregnd
, "hWnd overwritten\n");
110 HMONITOR appbar_mon
, foregnd_mon
;
111 appbar_mon
= pMonitorFromWindow(hwnd
, MONITOR_DEFAULTTONEAREST
);
112 foregnd_mon
= pMonitorFromWindow(foregnd
, MONITOR_DEFAULTTONEAREST
);
113 ok(appbar_mon
== foregnd_mon
, "Windows on different monitors\n");
118 memset(&abd
, 0xcc, sizeof(abd
));
119 abd
.cbSize
= sizeof(abd
);
120 ret
= SHAppBarMessage(ABM_GETTASKBARPOS
, &abd
);
123 ok(abd
.hWnd
== (HWND
)0xcccccccc, "hWnd overwritten\n");
126 ok(abd
.uEdge
>= ABE_LEFT
&& abd
.uEdge
<= ABE_BOTTOM
, "uEdge not returned\n");
127 ok(abd
.rc
.left
!= 0xcccccccc, "rc not updated\n");
139 HMODULE huser32
, hshell32
;
141 hshell32
= GetModuleHandleA("shell32.dll");
142 pShell_NotifyIconW
= (void*)GetProcAddress(hshell32
, "Shell_NotifyIconW");
144 huser32
= GetModuleHandleA("user32.dll");
145 pMonitorFromWindow
= (void*)GetProcAddress(huser32
, "MonitorFromWindow");
147 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
150 wc
.hInstance
= GetModuleHandleA(NULL
);
152 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
153 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
154 wc
.lpszMenuName
= NULL
;
155 wc
.lpszClassName
= "MyTestWnd";
156 wc
.lpfnWndProc
= DefWindowProc
;
159 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
160 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
161 GetClientRect(hMainWnd
, &rc
);
162 ShowWindow(hMainWnd
, SW_SHOW
);
167 while(GetMessageA(&msg
,0,0,0)) {
168 TranslateMessage(&msg
);
169 DispatchMessageA(&msg
);
171 DestroyWindow(hMainWnd
);
173 test_SHAppBarMessage();