Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//
//INCLUDE files for :Provide tooltips fo
// r a dialog box (MFC)
//**************************************
//
In the dialog class header file, instantiate an instance of CToolTipCtrl...
CToolTipCtrl m_ToolTips;
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//
// Name: Provide tooltips for a dialog b
// ox (MFC)
// Description:This example illustrates
// how to provide tooltips for the controls
// in a dialog box in Windows NT/95. All co
// de will be added to your dialog object h
// eader and implementation files. No other
// files are altered.
// By: Found on the World Wide Web
//**************************************
//
In the dialog class implementation file and in the OnInitDialog(...) over-ride, create the control and add tools to it.
// get a pointer to a control that needs a tooltip
CButton * pButton;
pButton = (CButton *)GetDlgItem(IDC_MYBUTTON);
// create the tooltip control with a pointer from the tooltip control's parent
m_ToolTips.Create(this);
// add as many tooltips to as many controls as you have pointers to...
m_ToolTips.AddTool(pButton, "This is the tooltip text for the button");
Over-ride PreTranslateMessage(...) in your dialog class. Use RelayEvent(..) to make sure that the tooltip control is aware of the appropriate mouse messages.
bool CMyDlg::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
m_ToolTips.RelayEvent(pMsg);
}
return CDialog::PreTranslateMessage(pMsg);
}
Note that using tooltips with a static control will require that the static control have the SS_NOTIFY attribute set in addition to whichever other attributes that you may be using.
Other 172 submission(s) by this author