Is it possible to make yellow tooltip in windows multiline?
I tried with \n
but it's not working.
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
).
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. Your screenshot shows a tracking tooltip. Then there's a multiline tooltip, send TTM_SETMAXTIPWIDTH and respond to TTN_GETDISPINFO. And there are balloon tooltips, specify the TTS_BALLOON window style flag. The latter two fit your bill.
There are good code examples in the SDK article for them.
You can force the standard tooltip control to do multiline using the following trick:
In your TTN_NEEDTEXT handler:
// 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:
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.
Strangely, I have to reissue this message in the TTN_NEEDTEXT handler, and not just at say window creation. 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. So It's just possible that for a non-MFC app you might be able to initialize it just once.
Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With