c++ - Windows 黄色工具提示多行?

标签 c++ windows tooltip multiline

是否可以在 windows 多行中制作黄色工具提示?

http://img830.imageshack.us/img830/6117/tooltip.gif

我尝试使用 \n 但它不起作用。

编辑:

这是我的代码中的函数。我按照 MSDN 的说明进行操作,但无法正常工作(查看评论://Multiline tooltip)。

void CreateToolTipForRect(HWND hwndParent)
{
    if (!bCanCreateToolTips)
        return;
    // Get list of areas we want tooltips on
    NSUI::TButton* tbt;
    tbt = gUserInterface->buttonList;

    HWND hwndTT;

    // Array to store all tooltip texts
    static char string[100][ RM_SCROLLTEXT_MAXLEN + 2 ];

    // Go through the list
    while (tbt != NULL)
    {
        // Check id there is a tooltip text defined for this area
        int sid = GetResourceIdFromButtonId(tbt->id);
        if (sid == -1)
        {
            tbt = tbt->next;
            continue;
        }

        if (!ttwnd[tbt->id])
        {
            // Create a ToolTip.
            hwndTT = CreateWindowEx(WS_EX_TOPMOST,
                TOOLTIPS_CLASS, NULL,
                WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,                       
                CW_USEDEFAULT, CW_USEDEFAULT,
                CW_USEDEFAULT, CW_USEDEFAULT,
                hwndParent, NULL, (( QunicApp * )CQMainGetApp())->CQWinApp_GetHInst(),NULL);

            ttwnd[tbt->id] = hwndTT;

            SetWindowPos(hwndTT, HWND_TOPMOST,
                0, 0, 0, 0,
                SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
            // Get tooltip from resources
            int res = LoadString((( QunicApp * )CQMainGetApp())->CQWinApp_GetHInst(), sid, string[tbt->id], RM_SCROLLTEXT_MAXLEN );
        }
        // Set up "tool" information.
        TOOLINFO ti = { 0 };
        ti.cbSize = sizeof(TOOLINFO);
        ti.uFlags = TTF_SUBCLASS;
        ti.hwnd = hwndParent;
        ti.hinst = (( QunicApp * )CQMainGetApp())->CQWinApp_GetHInst();

        ti.lpszText = string[tbt->id];

        // Set area
        ti.rect.left = tbt->tx;
        ti.rect.right = tbt->bx;
        ti.rect.top = tbt->ty;
        ti.rect.bottom = tbt->by;

        // Associate the ToolTip with the "tool" window.
        SendMessage(ttwnd[tbt->id], TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);

        // Multiline tooltip - Ilija tried with this
        /*LPNMTTDISPINFO pInfo = (LPNMTTDISPINFO)tbt;
        SendMessage(pInfo->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, 0, 150);*/

        tbt = tbt->next;
    }
    // Extra one, area or button is not known yet
    // Create a ToolTip.
    hwndTT = CreateWindowEx(WS_EX_TOPMOST,
        TOOLTIPS_CLASS, NULL,
        WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,                       
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        hwndParent, NULL, (( QunicApp * )CQMainGetApp())->CQWinApp_GetHInst(),NULL);

    SetWindowPos(hwndTT, HWND_TOPMOST,
        0, 0, 0, 0,
        SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

    // Set up "tool" information.
    TOOLINFO ti = { 0 };
    ti.cbSize = sizeof(TOOLINFO);
    ti.uFlags = TTF_SUBCLASS;
    ti.hwnd = hwndParent;
    ti.hinst = (( QunicApp * )CQMainGetApp())->CQWinApp_GetHInst();

    // Get tooltip from resources
    int res = LoadString( ti.hinst, IDS_PREVIEW, string[99], RM_SCROLLTEXT_MAXLEN );

    ti.lpszText = string[99];

    // Set area
    ti.rect.left = 7;
    ti.rect.right = 104;
    ti.rect.top = 131;
    ti.rect.bottom = 145;

    // Associate the ToolTip with the "tool" window.
    SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
}

谢谢,
伊利亚

最佳答案

有 3 种工具提示。您的屏幕截图显示了跟踪工具提示。然后是多行工具提示,发送 TTM_SETMAXTIPWIDTH 并响应 TTN_GETDISPINFO。并且有气球工具提示,指定TTS_BALLOON 窗口样式标志。后两者符合您的要求。

SDK article 中有很好的代码示例为他们。

关于c++ - Windows 黄色工具提示多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345790/

相关文章:

c++ - 带有参数 std::unique_ptr<T>&& 的 std::move 或 std::forward

c++ - printf 与 long long int 的结果不一致?

windows - 为什么我的 Windows 程序死机时会卡住(蓝灰色)窗体或窗口?

windows - PyCharm:未找到 Anaconda 安装

c# - 有没有办法在调用 SetToolTip 时抑制 ToolTip Popup 事件?

javascript - FullCalendar 在尝试添加工具提示时返回 "Failure Parsing JSON"

JQuery 工具提示不显示

c++ - 如何正确从 D 接口(interface)到 C++?

c++ - Visual Studio-自动完成不起作用

windows - 脚本大胆