簡體   English   中英

Windows黃色工具提示多行?

[英]Windows yellow 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文章中有很好的代碼示例。

您可以使用以下技巧強制標准工具提示控件執行多行:

在您的TTN_NEEDTEXT處理程序中:

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

無論如何,通過設置寬度,我就可以繪制muiltiline提示:

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

其中kToolTipWidth是一些有用的最大寬度,比如600-800。

奇怪的是,我必須在TTN_NEEDTEXT處理程序中重新發出此消息,而不僅僅是說窗口創建。 我們的MFC應用程序也是如此,其中MFC使用每線程全局工具提示控件,每次創建新對話框時,可能會將其重置為默認值。 因此,對於非MFC應用程序,您可能只能初始化它一次。

請享用!

Windows使用\\r\\n進行換行。 試試它,它應該工作。 請參閱MSDN

我發現\\ n適用於普通工具提示,但是\\ n和\\ r \\ n都不適用於氣球工具提示。 我沒有使用Unicode。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM