hillpath
hillpath

Reputation: 57

Display balloon tooltip in systemtray

this is my code..

set trayicon .......

NOTIFYICONDATA data;//this is global variable.
case WM_CREATE :
data.cbSize = sizeof(NOTIFYICONDATA);
data.hWnd =hWnd;
data.uID = IDR_MAINFRAME;
data.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
data.uCallbackMessage = ID_TRAYICON_NOTIFY;
data.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_INFO));

wcscpy_s(data.szTip,128,a);

Shell_NotifyIcon( NIM_ADD, &data );

........

and set balloon ......

case WM_RBUTTONDBLCLK:
data.hWnd = hWnd;
data.cbSize =sizeof(NOTIFYICONDATA);
data.hIcon =  LoadIcon(hInst, MAKEINTRESOURCE(IDI_INFO));
data.uTimeout = 5000;
data.uFlags = NIF_INFO;
data.dwInfoFlags = NIIF_INFO;
_tcscpy_s(data.szInfoTitle,_T("TITLE"));
_tcscpy_s(data.szInfo,_T("SOME TEXT"));
Shell_NotifyIcon(NIM_MODIFY,&data);

.......

but, can't show balloon tooltip

plz teach me.

Upvotes: 0

Views: 4633

Answers (2)

Daniel
Daniel

Reputation: 629

I found the code in the official docs for detecting windows versions wasn't quite right. This should work better:

Try this for size (literally):

BOOL CheckWindowsVersion(DWORD dwMajor, DWORD dwMinor, DWORD dwBuild)
{
    // Initialize the OSVERSIONINFOEX structure.
    OSVERSIONINFOEX osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    osvi.dwMajorVersion = dwMajor;
    osvi.dwMinorVersion = dwMinor;
    osvi.dwBuildNumber = dwBuild;

    // Initialize the condition mask.
    DWORDLONG dwlConditionMask = 0;
    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
    VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);


    // Perform the test.
    return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask);
}

Then when you want to set the icon you can test for the correct windows version. For some reason in the official docs they were only checking for 6.1, when it should be 6.0.6 + all the other windows versions...

if( CheckWindowsVersion(6, 0, 6))
    data.cbSize = sizeof(NOTIFYICONDATA);
else if( CheckWindowsVersion(6, 0, 0))
    data.cbSize = NOTIFYICONDATA_V3_SIZE;
else if( CheckWindowsVersion(5, 0, 0))
    data.cbSize = NOTIFYICONDATA_V2_SIZE;
else
    data.cbSize = NOTIFYICONDATA_V1_SIZE;

I didn't fully test the VER_BUILDNUMBER part yet, but I presume this must be close.

Upvotes: 0

Cat Plus Plus
Cat Plus Plus

Reputation: 130004

You should check shell32.dll version, and set cbSize to (as described in the Remarks section of the NOTIFYICONDATA docs):

  • sizeof(NOTIFYICONDATA) if version is >=6.0.6
  • NOTIFYICONDATA_V3_SIZE if version is 6.0 (WinXP)
  • NOTIFYICONDATA_V2_SIZE if version is 5.0 (Win2000)
  • NOTIFYICONDATA_V1_SIZE if version is <5.0 (NT4/95/98)

Upvotes: 3

Related Questions