简体   繁体   English

Windows黄色工具提示多行?

[英]Windows yellow tooltip multiline?

Is it possible to make yellow tooltip in windows multiline? 是否可以在Windows多行中制作黄色工具提示?

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

I tried with \\n but it's not working. 我试过\\n但是它不起作用。

EDIT: 编辑:

This is the function I have in my code. 这是我在代码中的功能。 I followed instructions from MSDN but couldn't get it working (look at the comment: // Multiline tooltip ). 我按照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);
}

Thanks, 谢谢,
Ilija 伊利亚·

There are 3 kinds of tooltips. 有3种工具提示。 Your screenshot shows a tracking tooltip. 您的屏幕截图显示了跟踪工具提示。 Then there's a multiline tooltip, send TTM_SETMAXTIPWIDTH and respond to TTN_GETDISPINFO. 然后是多行工具提示,发送TTM_SETMAXTIPWIDTH并响应TTN_GETDISPINFO。 And there are balloon tooltips, specify the TTS_BALLOON window style flag. 并且有气球工具提示,指定TTS_BALLOON窗口样式标志。 The latter two fit your bill. 后两者适合你的账单。

There are good code examples in the SDK article for them. SDK文章中有很好的代码示例。

You can force the standard tooltip control to do multiline using the following trick: 您可以使用以下技巧强制标准工具提示控件执行多行:

In your TTN_NEEDTEXT handler: 在您的TTN_NEEDTEXT处理程序中:

// force multi-line tool tips
::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, kToolTipWidth);

Regardless, by setting the width, then I'm able to draw muiltiline tips: 无论如何,通过设置宽度,我就可以绘制muiltiline提示:

pToolTipText->lpszText = _T("blah blah blah\r\nmore blah blah\r\nline 3 of blah");

Where kToolTipWidth is some useful maximum width, say 600-800. 其中kToolTipWidth是一些有用的最大宽度,比如600-800。

Strangely, I have to reissue this message in the TTN_NEEDTEXT handler, and not just at say window creation. 奇怪的是,我必须在TTN_NEEDTEXT处理程序中重新发出此消息,而不仅仅是说窗口创建。 This is true of our MFC application, where MFC uses a per-thread global tool tip control, which is probably reset to default values each time a new dialog is created. 我们的MFC应用程序也是如此,其中MFC使用每线程全局工具提示控件,每次创建新对话框时,可能会将其重置为默认值。 So It's just possible that for a non-MFC app you might be able to initialize it just once. 因此,对于非MFC应用程序,您可能只能初始化它一次。

Enjoy! 请享用!

Windows uses \\r\\n for line breaks. Windows使用\\r\\n进行换行。 Try it instead, it should work. 试试它,它应该工作。 See MSDN . 请参阅MSDN

I've found that \\n works for normal tooltips, but neither \\n nor \\r\\n works for balloon tooltips. 我发现\\ n适用于普通工具提示,但是\\ n和\\ r \\ n都不适用于气球工具提示。 I am not using Unicode. 我没有使用Unicode。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM