是否有必要销毁工具提示?
在我的应用程序中,我正在处理 WM_HELP
消息,然后使用此方法为控件创建工具提示:
取自:http://msdn.microsoft.com/en-us/library/bb760252(v=vs.85).aspx
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText)
{
if (!toolID || !hDlg || !pszText)
{
return FALSE;
}
// Get the window of the tool.
HWND hwndTool = GetDlgItem(hDlg, toolID);
// Create the tooltip. g_hInst is the global instance handle.
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
g_hInst, NULL);
if (!hwndTool || !hwndTip)
{
return (HWND)NULL;
}
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return hwndTip;
}
库 当我移动鼠标指针时,工具提示就会消失。
我的问题是:
- 工具提示是否已被破坏或只是隐藏了?
- 如果它是隐藏的那么如何销毁它以及何时销毁?
谢谢。
In my application I am handling the WM_HELP
message and then creating a tooltip for a control using this method:
Taken from: http://msdn.microsoft.com/en-us/library/bb760252(v=vs.85).aspx
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText)
{
if (!toolID || !hDlg || !pszText)
{
return FALSE;
}
// Get the window of the tool.
HWND hwndTool = GetDlgItem(hDlg, toolID);
// Create the tooltip. g_hInst is the global instance handle.
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
g_hInst, NULL);
if (!hwndTool || !hwndTip)
{
return (HWND)NULL;
}
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return hwndTip;
}
The tooltip vanishes as soon as I move my mouse pointer.
My questions are:
- Is tooltip is destroyed or is it just hidden ?
- If it is hidden then how to destroy it and when?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经有一段时间没有进行任何 WinAPI 编程了,但如果我没记错的话...
对
CreateWindowEx
的调用将hDlg
作为 hWndParent 参数表示对话框窗口现在是工具提示的父窗口。来自
DestroyWindow< 上的 MSDN 文档/code>
函数它说:
因此,您可以假设您的工具提示窗口最终将被销毁。如果您调用
CreateToolTip
来响应每条WM_HELP
消息,请务必小心,因为您最终会在内存中保留许多工具提示窗口,直到您的对话框关闭并且>DestroyWindow
最终被调用。正如 vz0 指出的,您可以创建一次工具提示,挂在窗口句柄上,然后显示工具提示以响应帮助消息,而不是再次创建它。
在您对 vz0 答案的评论中您说:
所有这些只会导致窗口被隐藏,因此工具提示的句柄仍然有效,并且可以使用 ShowWindow 重新显示。
It's been a while since I've done any WinAPI programming but if my memory serves me...
The call to
CreateWindowEx
passes thehDlg
as the hWndParent parameter meaning the dialog window is now the parent of the tooltip.From the MSDN documentation on the
DestroyWindow
function it says:So you can assume your tooltip window will be destroyed eventually. Be careful if you are calling
CreateToolTip
in response to everyWM_HELP
message as you will end up with a number of tooltip windows hanging around in memory until your dialog is closed andDestroyWindow
is finally called.As vz0 pointed out you could create the tooltip once, hang on to the window handle, then show the tooltip in response to the help message rather than creating it again.
In your comment to vz0's answer you said:
All of those only result in the window being hidden so the handle to the tooltip is still valid and can be redisplayed using
ShowWindow
.对于每个 CreateWindowEx 调用,您需要一个匹配 DestroyWindow 调用。
作为替代方案,您可以使用 ShowWindow 使用
SW_SHOW
和SW_HIDE
调用来显示和隐藏弹出窗口。For every CreateWindowEx call you need a matching DestroyWindow call.
As an alternative, instead of creating and destroying the window every time you can use the ShowWindow call with
SW_SHOW
andSW_HIDE
to show and hide the popup.根据我的经验,我必须在工具提示上执行
DestroyWindow()
,以便正确释放HFONT
(字体 GDI 资源)。两个窗口同时存在父子关系 - 但我的系统在运行时改变了这一点,这可能是罪魁祸首。如果你的系统能够概括它,那么这样做可能没有什么坏处。In my experience, I had to
DestroyWindow()
on the tooltip so anHFONT
(font GDI resource) was properly released. There was a parent-child bond of the two windows at one time - but my system changes this at run-time and could be to blame. Probably no harm in doing it if your system generalizes it.