Microsoft KB Archive/148495

= PRB: Tool Tips Stop Showing After WM_xBUTTONDOWN =

Article ID: 148495

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 2.1

 Microsoft Visual C++ 2.2

 Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q148495

<div class="symptoms_section">

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.

<div class="cause_section">

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.

<div class="resolution_section">

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); }

<div class="status_section">

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 kbprb kbtooltip kbuidesign KB148495

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.