CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2001
    Posts
    244

    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.

  2. #2
    Join Date
    Jul 2005
    Posts
    266

    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.

  3. #3
    Join Date
    Nov 2001
    Posts
    244

    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

  4. #4
    Join Date
    Nov 2001
    Posts
    244

    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.

  5. #5
    Join Date
    Jul 2005
    Posts
    266

    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.

  6. #6
    Join Date
    Nov 2001
    Posts
    244

    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
  •  





Click Here to Expand Forum to Full Width

Featured