This class helps the user in adding tooltip to any control in the dialog.
Tooltip information can be more than one line.
- Add MFECToolTip.h and MFECToolTip.cpp in your project
- In OnInitDialog, call the Create function and add the tooltip information to
any control you would like to have.For example:
In SampleDlg.h add a variableMFECToolTip m_toolTip;
In SampleDlg.cpp
SampleDlg::OnInitDialog() { m_toolTip.Create( this ); // after creating, add the information m_toolTip.AddControlInfo( contol_ID, information, background_color, text_color ); // control ID is of type UINT // information is of type CStringArray. // background_color and text_color are optional }
- Override the dialog’s PreTranslateMessage to handle mouse movement.
BOOL CToolTipExDlg::PreTranslateMessage( MSG *pMsg ) { if( pMsg->message == WM_MOUSEMOVE ) { POINT pt = pMsg->pt; ScreenToClient( &pt ); // this is the only function to call m_toolTip.ShowToolTip( (CPoint)pt ); } return CDialog::PreTranslateMessage(pMsg); }
- explicitly show the tooltip in a particular control, call
ShowToolTip( controlID ) with control ID as parameter. Make sure you
call AddControlInfo() to add information for this control, otherwise no
tooltip is displayed. - Delete or remove the existing tooltip information, call
RemoveControlInfo( controlID ) and pass the control ID. If not found
nothing happens. - So, you can add and remove tooltip at runtime. Try!