Reputation: 421
I am using MFC CToolTipCtrl for creating tooltip for a button. Now I have problem when I run the application in Windows XP.When I place mouse over the button,tooltip will popup but after clicking the button no tooltip is shown.In windows 7 there is no such problem. I've used the following code to create tooltip
pToolTip->Create(this);
TOOLINFO ToolInfo;
ToolInfo.cbSize = sizeof(TOOLINFO);
ToolInfo.lpszText = const_cast<LPTSTR>(szToolTipText);
ToolInfo.hinst = AfxGetInstanceHandle();
ToolInfo.hwnd = pButton->m_hWnd;
ToolInfo.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
ToolInfo.uId = (UINT)pButton->m_hWnd;
pToolTip->SendMessage(TTM_ADDTOOL, 0, (LPARAM) &ToolInfo);
Upvotes: 1
Views: 1493
Reputation: 6050
Try call relayevent in the preTanslateMessage
function.
From MSDN: http://msdn.microsoft.com/en-US/library/x61cthdf(v=vs.80).aspx
In order for the tool tip control to be notified of important messages, such as WM_LBUTTONXXX messages, you must relay the messages to your tool tip control. The best method for this relay is to make a call to CToolTipCtrl::RelayEvent, in the PreTranslateMessage function of the owner window.
The following example illustrates one possible method (assuming the tool tip control is called m_ToolTip):
if(pMsg->message== WM_LBUTTONDOWN ||
pMsg->message== WM_LBUTTONUP ||
pMsg->message== WM_MOUSEMOVE)
m_ToolTip.RelayEvent(pMsg);
return CMyView::PreTranslateMessage(pMsg);
If you're using VS2010 above, you can just use CMFCButton, it has a method to set the tooltip, makes life much easier.
Upvotes: 1