如何获得一个给定的HWND工具提示文本? [英] How to get tooltip text for a given HWND?
问题描述
我正在寻找一种方式来获得工具提示控件(如果有的话),这是一个给定的HWND关联。工具提示控件的文本就足够了。我发现的最接近的就是 TTM_GETTEXT 消息的,但它意味着被发送到工具提示控制本身,而不是它的相关联的工具。我没有一个句柄工具提示控件虽然。是否有人知道如何做到这一点?
I'm looking for a way to get the tooltip control (if any) which is associated with a given HWND. The text of the tooltip control would be sufficient, too. The closest thing I found is the TTM_GETTEXT message, but it's meant to be sent to the tooltip control itself instead of the tool it's associated with. I don't have a handle to the tooltip control though. Does anybody know how to do this?
所有这一切都是在C ++中使用普通的Windows API来完成。
All this is done using plain Windows API in C++.
推荐答案
似乎没有成为一个特定的消息,以获得尖端或从控制它的文本,但是这是MFC的CWnd类是如何实现OnToolHitTest()你应该能够适应的Win32:
There doesn't seem to be a specific message to get the tip or its text from the control, but this is how MFC's CWnd class implements OnToolHitTest(), which you should be able to adapt to Win32:
INT_PTR SomeFunction(HWND hWndChild, TOOLINFO *pTI)
{
if (hWndChild != NULL) // Your HWND being tested
{
// return positive hit if control ID isn't -1
INT_PTR nHit = _AfxGetDlgCtrlID(hWndChild);
// Replace with GetDlgCtrlID().
// hits against child windows always center the tip
if (pTI != NULL && pTI->cbSize >= sizeof(AFX_OLDTOOLINFO))
{
// setup the TOOLINFO structure
pTI->hwnd = m_hWnd;
pTI->uId = (UINT_PTR)hWndChild;
pTI->uFlags |= TTF_IDISHWND;
pTI->lpszText = LPSTR_TEXTCALLBACK;
// set TTF_NOTBUTTON and TTF_CENTERTIP if it isn't a button
if (!(::SendMessage(hWndChild, WM_GETDLGCODE, 0, 0) & DLGC_BUTTON))
pTI->uFlags |= TTF_NOTBUTTON|TTF_CENTERTIP;
}
return nHit;
}
return -1; // not found
}
希望这将是有益的。
Hopefully this will be useful.
这篇关于如何获得一个给定的HWND工具提示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!