Windows 黄色工具提示多行?
是否可以在 Windows 多行中制作黄色工具提示?
我尝试使用 \n< /code> 但它不起作用。
编辑:
这是我的代码中的函数。我按照 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);
}
谢谢,
伊利亚
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有 3 种工具提示。您的屏幕截图显示了跟踪工具提示。然后是多行工具提示,发送 TTM_SETMAXTIPWIDTH 并响应 TTN_GETDISPINFO。并且有气球工具提示,指定 TTS_BALLOON 窗口样式标志。后两者符合您的要求。
SDK 文章中有很好的代码示例对于他们来说。
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.
您可以使用以下技巧强制标准工具提示控件执行多行操作:
在 TTN_NEEDTEXT 处理程序中:
无论如何,通过设置宽度,我就可以绘制多行提示:
其中 kToolTipWidth 是一些有用的最大宽度,例如 600-800。
奇怪的是,我必须在 TTN_NEEDTEXT 处理程序中重新发出此消息,而不仅仅是在创建窗口时。我们的 MFC 应用程序就是如此,其中 MFC 使用每线程全局工具提示控件,每次创建新对话框时该控件可能会重置为默认值。因此,对于非 MFC 应用程序,您可能只能初始化一次。
享受!
You can force the standard tooltip control to do multiline using the following trick:
In your TTN_NEEDTEXT handler:
Regardless, by setting the width, then I'm able to draw muiltiline tips:
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!
我发现 \n 适用于普通工具提示,但 \n 和 \r\n 都不适用于气球工具提示。我没有使用 Unicode。
I've found that \n works for normal tooltips, but neither \n nor \r\n works for balloon tooltips. I am not using Unicode.