尽管正确设置了szTip,但通知图标工具提示仍未显示

时间:2012-02-26 04:53:46

标签: winapi visual-c++ user-interface tooltip notification-area

我正在尝试制作一个只有上下文菜单作为GUI的小型系统托盘程序。

但是,我无法获得工具提示。我正确设置了NOTIFYICONDATA的szTip,其他一切似乎都有效......什么阻止了工具提示在鼠标悬停时显示?

void main()
{
    int result;

    hinst = GetModuleHandle( NULL );

    memset( &wnd, 0, sizeof( wnd ) );
    wnd.cbSize = sizeof( wnd );
    wnd.lpszClassName = "MainWClass";
    wnd.lpfnWndProc = MainWProc;
    wnd.hInstance = hinst;
    result = RegisterClassEx( &wnd );

    hwnd = CreateWindowEx
        (
        0, //extended styles
        wnd.lpszClassName, //class name
        "Main Window", //window name
        WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL | WS_MINIMIZEBOX, //style tags
        CW_USEDEFAULT, //horizontal position
        CW_USEDEFAULT, //vertical position
        CW_USEDEFAULT, //width
        CW_USEDEFAULT, //height
        (HWND) NULL, //parent window
        (HMENU) NULL, //class menu
        (HINSTANCE) wnd.hInstance, //some HINSTANCE pointer
        NULL //Create Window Data?
        );

    nid.cbSize = sizeof( nid );
    nid.hWnd = hwnd;
    nid.uID = 1;
    nid.uVersion = NOTIFYICON_VERSION_4;
    nid.uCallbackMessage = WM_CONTEXTMENU;
    nid.hIcon = LoadIcon( hinst, MAKEINTRESOURCE( IDI_ICON1 ) );
    strcpy( nid.szTip, "My Tooltip!" );
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;

    if( ! Shell_NotifyIcon( NIM_ADD, &nid ) )
    {
        printf("Shell_NotifyIcon( NIM_ADD, &nid ) failed.\r\n");
        Sleep( INFINITE );
    }
    if( ! Shell_NotifyIcon( NIM_SETVERSION, &nid ) )
    {
        printf("Shell_NotifyIcon( NIM_SETVERSION, &nid ) failed.\r\n");
        Sleep( INFINITE );
    }

    UpdateWindow( hwnd );
    while( true )
    {
        //Dispatch for main window
        if( PeekMessage( &msg, hwnd, NULL, NULL, PM_REMOVE ) )
        {
            DispatchMessage( &msg );
        }
    }
}

1 个答案:

答案 0 :(得分:4)

尝试添加NIF_SHOWTIP标记,根据MSDNNOTIFYICON_VERSION_4要求工具提示为用户提取。