2

我正在尝试制作一个只有上下文菜单作为其 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 );
        }
    }
}
4

1 回答 1

5

尝试添加NIF_SHOWTIP标志,根据MSDNNOTIFYICON_VERSION_4需要用户绘制工具提示。

于 2012-02-26T06:35:22.000 回答