PRB: Tool Tips Stop Showing After WM_xBUTTONDOWN

ID: Q148495


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, 32-bit Editions, versions 2.1, 2.2, 4.0, 4.1


SYMPTOMS

If you hold a mouse button down while the pointer is over a tool and then move the mouse off of the window that contains the tool before releasing the mouse button, then tool tips will no longer be displayed for that tool until you click it again.


CAUSE

By design, the Tooltip control won't display tool tips while a mouse button is down. This is correct behavior. However, the Tooltip control needs to see the WM_xBUTTONUP message to know that the mouse button has been released and it is okay to show tool tips again.

If the WM_xBUTTONDOWN message is sent to a Tooltip control and the corresponding WM_xBUTTONUP message is not (as in the scenario outlined above), then the Tooltip control will behave as if the mouse button is still down, so it will not show any further tool tips.

NOTE: This won't be a problem if the window with the Tooltip control captures the mouse using SetCapture() when it gets WM_xBUTTONDOWN and then releases it when it gets WM_xBUTTONUP using ReleaseCapture().


RESOLUTION

As previously explained, this behavior occurs because the WM_xBUTTONUP message is not being relayed to the Tooltip control.

To work around this behavior, relay a fabricated WM_xBUTTONUP message when it is known that a WM_xBUTTONDOWN message has been received but that a corresponding WM_xBUTTONUP message was not received even though the button is no longer pressed.

This case can be determined by examining the wParam that is sent in the WM_MOUSEMOVE message. Tooltip messages are normally relayed from the owner window's PreTranslateMessage() function, so the workaround can be implemented in the PreTranslateMessage() function.

NOTE: You still won't see the tip when you first move the mouse pointer back over the tool. This is expected behavior because it is the same behavior you get if you move the mouse over a tool and single click on that tool; that is, no more tool tips will appear until you move the mouse pointer off the tool and then back onto the tool.

Sample Code


// Add members to the class definition:

    class CMyWnd : public CSomeWnd
    {
        ...

    protected:
        BOOL m_bButtonDown;
        virtual BOOL PreTranslateMessage(MSG *pMsg);

        ...
    };

// Initialize the m_bButtonDown to FALSE in the constructor:

CMyWnd::CMyWnd()
{
    m_bButtonDown=FALSE;

    ...
}

// Implement the PreTranslateMessage() function:

BOOL CMyWnd::PreTranslateMessage(MSG *pMsg)
{
  static MSG msgLButtonUp = { NULL,WM_LBUTTONUP,0,0,0,0 };

  switch(pMsg->message)
  {
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    case WM_MBUTTONDOWN:
      m_bButtonDown=TRUE;
      m_ToolTip.RelayEvent(pMsg);
      break;

    case WM_LBUTTONUP:
    case WM_MBUTTONUP:
    case WM_RBUTTONUP:
      m_bButtonDown=FALSE;
      m_ToolTip.RelayEvent(pMsg);
      break;

    case WM_MOUSEMOVE:
      if( m_bButtonDown &&
        !(pMsg->wParam & MK_LBUTTON) &&
        !(pMsg->wParam & MK_MBUTTON) &&
        !(pMsg->wParam & MK_RBUTTON) )
      {
        m_ToolTip.RelayEvent(&msgLButtonUp);
        m_bButtonDown=FALSE;
      }
      m_ToolTip.RelayEvent(pMsg);
      break;
  }

  // Rest of PreTranslateMessage goes here
  return CWnd::PreTranslateMessage(pMsg);
} 


STATUS

This behavior is by design.

Additional query words: 2.10 2.20 3.10 3.20 4.00 4.10 CToolTipCtrl TTM_RELAYEVENT

Keywords : kbcode kbMFC KbUIDesign kbVC
Version : 2.10 2.20 4.00 4.10
Platform : NT WINDOWS
Issue type :


Last Reviewed: July 29, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.