Search code examples
c++winapisystemconsole-applicationsystem-tray

C++ Windows System Tray wont display message


I have been stuck here for 4 days. I made a function that puts a program in the system tray but the problem here is that it wont show balloon title and message. What Am I doing Wrong? I even made a separate function to determine what windows os we are running on and initialize cbSize based on the Os detected. Any help will be appreciated. Bellow is the function.

EDIT: I am using Windows 7 and the Icon shows up in the system tray but wont show the message or title. I am also doing this Console Application right now as this will be used as a plugin in Unity3D. I want a solution that uses windows api but not windows form as I don't want any new window to open from this.

void createSystemTray()
{
    HWND wHandler = GetDesktopWindow();
    NOTIFYICONDATA iData;
    ZeroMemory(&iData,sizeof(iData));



    if(getOsVersion()=="Windows Vista" || getOsVersion()=="Windows 7" || getOsVersion()=="Windows 8" || getOsVersion()=="Windows 8.1")
    {
        iData.cbSize = sizeof(NOTIFYICONDATA);
    }

    else if (getOsVersion()=="Windows XP"||getOsVersion()=="Windows XP Professional x64 Edition")
    {
        iData.cbSize = NOTIFYICONDATA_V3_SIZE;
    }

    else if (getOsVersion()=="Windows 2000")
    {
        iData.cbSize = NOTIFYICONDATA_V2_SIZE;
    }

    else if (getOsVersion()=="UNKNOWN OS")
    {
//Assume we have old Windows Os such as Me,95....
        iData.cbSize = NOTIFYICONDATA_V1_SIZE;
    }
    iData.hWnd = wHandler;
    iData.uID = 100;
    iData.uVersion = NOTIFYICON_VERSION_4;
    iData.uCallbackMessage = WM_MESSAGE;
    iData.hIcon = LoadIcon(NULL,(LPCTSTR)IDI_WARNING);
    lstrcpy(iData.szTip,"My First Tray Icon");
    lstrcpy(iData.szInfo,"My App Info");
    lstrcpy(iData.szInfoTitle,"My Info Title");
    iData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
    Shell_NotifyIcon(NIM_SETVERSION,&iData); //called only when usingNIM_ADD
    Shell_NotifyIcon(NIM_ADD,&iData);
}

Solution

  • I added NIF_INFO to the uFlags and the problem is gone. Now it displays everything including text, title and info title. The code below is what solved it.

    iData.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP|NIF_SHOWTIP|NIF_INFO;