Display help for dialog controls on the status bar | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.