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