systray.c 3.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Unit tests for systray
 *
 * Copyright 2007 Mikolaj Zalewski
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */
#define _WIN32_IE 0x600
#include <stdarg.h>

#include <windows.h>
23
#include "shellapi.h"
24 25 26 27 28

#include "wine/test.h"


static HWND hMainWnd;
29
static BOOL (WINAPI *pShell_NotifyIconW)(DWORD,PNOTIFYICONDATAW);
30

31
static void test_cbsize(void)
32 33
{
    NOTIFYICONDATAA nidA;
34
    BOOL ret;
35

36 37 38
    if (pShell_NotifyIconW)
    {
        NOTIFYICONDATAW nidW;
39

40 41 42 43 44
        ZeroMemory(&nidW, sizeof(nidW));
        nidW.cbSize = NOTIFYICONDATAW_V1_SIZE;
        nidW.hWnd = hMainWnd;
        nidW.uID = 1;
        nidW.uFlags = NIF_ICON|NIF_MESSAGE;
45
        nidW.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
46
        nidW.uCallbackMessage = WM_USER+17;
47
        ret = pShell_NotifyIconW(NIM_ADD, &nidW);
48
        ok(ret, "NIM_ADD failed!\n");
49 50 51 52 53 54 55 56 57
        /* using an invalid cbSize does work */
        nidW.cbSize = 3;
        nidW.hWnd = hMainWnd;
        nidW.uID = 1;
        ret = pShell_NotifyIconW(NIM_DELETE, &nidW);
        ok( ret || broken(!ret), /* nt4 */ "NIM_DELETE failed!\n");
        /* as icon doesn't exist anymore - now there will be an error */
        nidW.cbSize = sizeof(nidW);
        ok(!pShell_NotifyIconW(NIM_DELETE, &nidW) != !ret, "The icon was not deleted\n");
58
    }
59 60 61 62 63 64 65

    /* same for Shell_NotifyIconA */
    ZeroMemory(&nidA, sizeof(nidA));
    nidA.cbSize = NOTIFYICONDATAA_V1_SIZE;
    nidA.hWnd = hMainWnd;
    nidA.uID = 1;
    nidA.uFlags = NIF_ICON|NIF_MESSAGE;
66
    nidA.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
67 68 69 70 71 72 73
    nidA.uCallbackMessage = WM_USER+17;
    ok(Shell_NotifyIconA(NIM_ADD, &nidA), "NIM_ADD failed!\n");

    /* using an invalid cbSize does work */
    nidA.cbSize = 3;
    nidA.hWnd = hMainWnd;
    nidA.uID = 1;
74
    ret = Shell_NotifyIconA(NIM_DELETE, &nidA);
75
    ok(ret, "NIM_DELETE failed!\n");
76 77
    /* as icon doesn't exist anymore - now there will be an error */
    nidA.cbSize = sizeof(nidA);
78
    ok(!Shell_NotifyIconA(NIM_DELETE, &nidA) != !ret, "The icon was not deleted\n");
79 80 81 82 83 84 85
}

START_TEST(systray)
{
    WNDCLASSA wc;
    MSG msg;
    RECT rc;
86
    HMODULE hshell32;
87 88 89

    hshell32 = GetModuleHandleA("shell32.dll");
    pShell_NotifyIconW = (void*)GetProcAddress(hshell32, "Shell_NotifyIconW");
90

91 92 93 94 95
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = GetModuleHandleA(NULL);
    wc.hIcon = NULL;
96
    wc.hCursor = LoadCursorA(NULL, (LPSTR)IDC_IBEAM);
97 98 99
    wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "MyTestWnd";
100
    wc.lpfnWndProc = DefWindowProcA;
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    RegisterClassA(&wc);

    hMainWnd = CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
    GetClientRect(hMainWnd, &rc);
    ShowWindow(hMainWnd, SW_SHOW);

    test_cbsize();

    PostQuitMessage(0);
    while(GetMessageA(&msg,0,0,0)) {
        TranslateMessage(&msg);
        DispatchMessageA(&msg);
    }
    DestroyWindow(hMainWnd);
}