|
-
April 8th, 2009, 09:14 PM
#1
CButton Tooltips dont popup intermittently
VS2005 C++ (v8.0.50727.867), WinXP SP2
I have a standard MFC CDialog with some CButtons. The CButtons are using CToolTipCtrl to display a popup tooltip box.
When my Program starts up, all the tooltips work fine.
When I click a Button, the Tooltip never pops up anymore.
Is there bug in CToolTipCtrl?
This happens in two of my MFC programs that use CToolTips differently. One of the programs is using the CButtonST class by Davide Calabro, the other Program is using the ToolTipButton class made by ?? (downloaded from codeguru or Codeproject) which is basically a class that adds tooltips to CButton.
It happens with Static buttons, and buttons created on the fly.
Here is the code from BtnST.cpp
Code:
void CButtonST::InitToolTip()
{
if (m_ToolTip.m_hWnd == NULL)
{
// Create ToolTip control
m_ToolTip.Create(this, m_dwToolTipStyle);
// Create inactive
m_ToolTip.Activate(FALSE);
// Enable multiline
m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400);
//m_ToolTip.SendMessage(TTM_SETTITLE, TTI_INFO, (LPARAM)_T("Title"));
} // if
}
void CButtonST::SetTooltipText(int nText, BOOL bActivate)
{
CString sText;
// Load string resource
sText.LoadString(nText);
// If string resource is not empty
if (sText.IsEmpty() == FALSE) SetTooltipText((LPCTSTR)sText, bActivate);
}
void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
{
// We cannot accept NULL pointer
if (lpszText == NULL) return;
// Initialize ToolTip
InitToolTip();
// If there is no tooltip defined then add it
if (m_ToolTip.GetToolCount() == 0)
{
CRect rectBtn;
GetClientRect(rectBtn);
m_ToolTip.AddTool(this, lpszText, rectBtn, 1);
} // if
// Set text for tooltip
m_ToolTip.UpdateTipText(lpszText, this, 1);
m_ToolTip.Activate(bActivate);
}
void CButtonST::ActivateTooltip(BOOL bActivate)
{
// If there is no tooltip then do nothing
if (m_ToolTip.GetToolCount() == 0) return;
// Activate tooltip
m_ToolTip.Activate(bActivate);
}
BOOL CButtonST::PreTranslateMessage(MSG* pMsg)
{
InitToolTip();
m_ToolTip.RelayEvent(pMsg);
if (pMsg->message == WM_LBUTTONDBLCLK)
pMsg->message = WM_LBUTTONDOWN;
return CButton::PreTranslateMessage(pMsg);
}
Last edited by Anarchi; April 9th, 2009 at 01:00 AM.
-
April 10th, 2009, 04:17 AM
#2
Re: CButton Tooltips dont popup intermittently
If you can post a sample project I can help you, I had similar problems with my custom irregular shaped rollover button tooltips, sometimes after clicking the buttons CToolTipCtrl doesnt receive the proper MouseMove message after the buttonup even has been fired. I can't really tell if that's the case for you but if you post a sample project ( attach ) I can probably fix it.
-
April 10th, 2009, 12:47 PM
#3
Re: CButton Tooltips dont popup intermittently
ok thanks kilkoo.
I created a sample app but the tooltips work every time now (its always the case lol).
Please check this thread tomorrow, I'll see if I can replicate it again then post the attachment
-
April 10th, 2009, 10:56 PM
#4
Re: CButton Tooltips dont popup intermittently
I tried replicating it in a test app but I couldnt get it working. My main app is too large.
I found that:
If you push a button but drag the cursor away from the button (without lifting up the mouse button), the tooltip still fails.
When the tooltip doesnt work, the Button is still receiving WM_MOUSEMOVE messages in PreTranslateMessages
When the tooltip doesnt work, the CToolTip pointer is still valid
When the tooltip doesnt work, m_ToolTip.GetToolCount() is above 0
Workaround Fix:
If I call CButton->m_ToolTip.UpdateTipText(lpszText, this, 1) from CDialog::OnCommand when the mouse button is clicked, the tooltip comes back.
-
April 11th, 2009, 09:32 AM
#5
Re: CButton Tooltips dont popup intermittently
This was exactly my problem, when u click the left button hold it move the mouse away from the button the tooltip wont receive the WM_MOUSEMOVE message. The way i worked around it was in the LeftButtonUp handler i just sent a notification to my tooltip ( if i had one ) that the mouse has moved:
Code:
UINT lParam=0;
lParam|=point.y<<16;
lParam|=(WORD)point.x;
m_ToolTip.SendMessage(WM_MOUSEMOVE,0,lParam);
Last edited by kolkoo; April 11th, 2009 at 02:53 PM.
-
April 11th, 2009, 11:59 AM
#6
Re: CButton Tooltips dont popup intermittently
Interesting, I'll keep that in mind. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|