Display help for dialog controls on the status bar

If the user passes the mouse over a button, extra help text for that button should appear in the status bar. To use status bar to display extra help for dialog controls is preaty easy. Every time the mouse passes over a window, the WM_SETCURSOR message is sent to the window's owner. If we catch the message through OnSetCursor, we can easy determine if the mouse is over a dialog control. Then, assuming the control has a string resource with the same ID, we pass the ID to a special function that sets the text in the first status bar pane.

1. Create function to handle WM_SETCURSOR
BOOL CAboutDlg::OnSetCursor(CWnd * pWnd, UINT nHitText, UINT message)
{
	// if the cursor is not over a child window control, revert
	// to the default status bar text

	if(pWnd == this)
		SetPaneText();
	else
		SetPaneText(pWnd->GetDlgCtrlID());

	return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
2. Handle WM_DESTROY message to restore status bar text
void CAboutDlg::OnDestroy()
{
	SetPaneText();
	CDialog::OnDestroy();
}
3. Add SetPaneText helper function
// this part goes to CAboutDlg class declaration
protected:
	void SetPaneText(UINT nID = 0);

// and this is function implementation
void CAboutDlg::SetPaneText(UINT nID)
{
	if(nID == 0)
		nID = AFX_IDS_IDLEMESSAGE;

	CWnd * pWnd = AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	if(pWnd)
	{
		AfxGetMainWnd()->SendMessage(WM_SETMESSAGESTRING, nID);
		pWnd->SendMessage(WM_IDLEUPDATECMDUI);
		pWnd->UpdateWindow();
	}
}
4. And finally do not foget to add following include files
#include  // for WM_SETMESSAGESTRING and WM_IDLEUPDATECMDUI
#include  // for AFX_IDW_STATUS_BAR

Last updated: 11 May 1998



Comments

  • How about menu items

    Posted by Legacy on 10/31/2000 12:00am

    Originally posted by: Jeff Nygren

    This was just what I needed for displaying help text for my controls. I want to do the same thing for popup menu items. How can I detect when the user passes the mouse over the items in a popup menu?

    Reply
  • Missing includefiles on screen...

    Posted by Legacy on 11/20/1998 12:00am

    Originally posted by: Albert van Peppen

    The includefiles are AfxPriv.h and AfxRes.h (VC++ 5.0 at least ;)
    
    

    Greetings,

    Albert van Peppen

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds