Wednesday, April 06, 2005

How to show tootips of a toolbar in a dialog window?

It is easy to add a toolbar to a dialog window. However, it takes some effort to make the tooltips of the toolbar to work. Here are the steps needed to be taken.

1. Add the following line to the message map in the header file of the dialog box

afx_msg BOOL OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult);

2. Add the following line to the cpp file of the dialog box

ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipText )

3. Add following line to InitDialog()

EnableTooltips();

4. Add the following function


BOOL CConfBrowser_MFCDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =pNMHDR->idFrom;
if (pTTT->uFlags & TTF_IDISHWND)
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
}
if (nID)
{
pTTT->lpszText = MAKEINTRESOURCE(nID);
pTTT->hinst = AfxGetResourceHandle();
return(TRUE);
}
return(FALSE);
}

No comments: