Tooltip for disabled controls (2)

As an alternative to the method suggested by Ran Almog, you can replicate MFCs fix in the dialog's PreTranslateMessage override.

The MFC code to look at is in the function RelayToolTipMessage in the file TOOLTIP.CPP.

This method has the advantage that it uses the tooltip itself to find the child window, the relevant CToolTipCtrl function is CToolTipCtrl::OnWindowFromPoint() - which has other fixes for special cases as well as the disabled control case.

Example: if using the DeveloperStudio Tooltip component, change the block it adds in PreTranslateMessage from:
	// CG: The following block was added by the ToolTips component.
	{
		// Let the ToolTip process this message.
		m_tooltip.RelayEvent(pMsg);
	}

to:

	// CG: The following block was added by the ToolTips component.
	{
		// transate the message based on TTM_WINDOWFROMPOINT
		MSG msg = *pMsg;
		msg.hwnd = (HWND)m_tooltip.SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
		CPoint pt = pMsg->pt;
		if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
			::ScreenToClient(msg.hwnd, &pt);
		msg.lParam = MAKELONG(pt.x, pt.y);

		// Let the ToolTip process this message.
		m_tooltip.RelayEvent(&msg);
	}

Last updated: 22 June 1998



Comments

  • tooltips in disabled buttons

    Posted by Legacy on 01/27/2004 12:00am

    Originally posted by: Jos� Miguel Gomes

    I'm using a custom class of flat buttons that inherits from CButton and I wanted those buttons to show tooltips when disabled. Where do I put the code you wrote?

    Reply
  • Fix: disabled buttons show tips but respond to clicks

    Posted by Legacy on 02/22/1999 12:00am

    Originally posted by: Mike Harnad

    In my case, Ray's code worked fine except for one small oversight.
    
    Disabled controls now show tooltips, but, in the case of CBitmapButtons,
    they now respond to button clicks even if disabled. I tweaked the
    code to the following to get tooltips AND prevent button clicks on
    disabled controls.

    BOOL YourClass::PreTranslateMessage( MSG* pMsg )
    {
    MSG msg = *pMsg;

    if ( msg.message == WM_MOUSEMOVE )
    {
    // translate the message based on TTM_WINDOWFROMPOINT.
    // this allows us to display tooltips for disabled controls.
    msg.hwnd = (HWND)m_tooltip.SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
    CPoint pt = pMsg->pt;
    ::ScreenToClient(msg.hwnd, &pt);
    msg.lParam = MAKELONG(pt.x, pt.y);

    m_tooltip.Activate(TRUE); // make sure tooltip is active
    m_tooltip.RelayEvent(&msg); // Let the ToolTip process this message.
    }

    return CDialog::PreTranslateMessage(&msg);

    }

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds