[SHELL32_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / shell32 / systray.c
1 /* Unit tests for systray
2 *
3 * Copyright 2007 Mikolaj Zalewski
4 *
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.
9 *
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.
14 *
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
18 */
19 #define _WIN32_IE 0x600
20 #include <stdarg.h>
21
22 #include <windows.h>
23
24 #include "wine/test.h"
25
26
27 static HWND hMainWnd;
28 static BOOL (WINAPI *pShell_NotifyIconW)(DWORD,PNOTIFYICONDATAW);
29
30 static void test_cbsize(void)
31 {
32 NOTIFYICONDATAA nidA;
33 BOOL ret;
34
35 if (pShell_NotifyIconW)
36 {
37 NOTIFYICONDATAW nidW;
38
39 ZeroMemory(&nidW, sizeof(nidW));
40 nidW.cbSize = NOTIFYICONDATAW_V1_SIZE;
41 nidW.hWnd = hMainWnd;
42 nidW.uID = 1;
43 nidW.uFlags = NIF_ICON|NIF_MESSAGE;
44 nidW.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
45 nidW.uCallbackMessage = WM_USER+17;
46 ret = pShell_NotifyIconW(NIM_ADD, &nidW);
47 ok(ret, "NIM_ADD failed!\n");
48 /* using an invalid cbSize does work */
49 nidW.cbSize = 3;
50 nidW.hWnd = hMainWnd;
51 nidW.uID = 1;
52 ret = pShell_NotifyIconW(NIM_DELETE, &nidW);
53 ok( ret || broken(!ret), /* nt4 */ "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) != !ret, "The icon was not deleted\n");
57 }
58
59 /* same for Shell_NotifyIconA */
60 ZeroMemory(&nidA, sizeof(nidA));
61 nidA.cbSize = NOTIFYICONDATAA_V1_SIZE;
62 nidA.hWnd = hMainWnd;
63 nidA.uID = 1;
64 nidA.uFlags = NIF_ICON|NIF_MESSAGE;
65 nidA.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
66 nidA.uCallbackMessage = WM_USER+17;
67 ok(Shell_NotifyIconA(NIM_ADD, &nidA), "NIM_ADD failed!\n");
68
69 /* using an invalid cbSize does work */
70 nidA.cbSize = 3;
71 nidA.hWnd = hMainWnd;
72 nidA.uID = 1;
73 ret = Shell_NotifyIconA(NIM_DELETE, &nidA);
74 ok(ret, "NIM_DELETE failed!\n");
75 /* as icon doesn't exist anymore - now there will be an error */
76 nidA.cbSize = sizeof(nidA);
77 ok(!Shell_NotifyIconA(NIM_DELETE, &nidA) != !ret, "The icon was not deleted\n");
78 }
79
80 START_TEST(systray)
81 {
82 WNDCLASSA wc;
83 MSG msg;
84 RECT rc;
85 HMODULE hshell32;
86
87 hshell32 = GetModuleHandleA("shell32.dll");
88 pShell_NotifyIconW = (void*)GetProcAddress(hshell32, "Shell_NotifyIconW");
89
90 wc.style = CS_HREDRAW | CS_VREDRAW;
91 wc.cbClsExtra = 0;
92 wc.cbWndExtra = 0;
93 wc.hInstance = GetModuleHandleA(NULL);
94 wc.hIcon = NULL;
95 wc.hCursor = LoadCursorA(NULL, (LPSTR)IDC_IBEAM);
96 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
97 wc.lpszMenuName = NULL;
98 wc.lpszClassName = "MyTestWnd";
99 wc.lpfnWndProc = DefWindowProcA;
100 RegisterClassA(&wc);
101
102 hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
103 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
104 GetClientRect(hMainWnd, &rc);
105 ShowWindow(hMainWnd, SW_SHOW);
106
107 test_cbsize();
108
109 PostQuitMessage(0);
110 while(GetMessageA(&msg,0,0,0)) {
111 TranslateMessage(&msg);
112 DispatchMessageA(&msg);
113 }
114 DestroyWindow(hMainWnd);
115 }