1,.h
afx_msg BOOL Ontooltiptext(UINT, NMHDR* pnmhdr, LRESULT* presult);
2,.cpp
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xffff, Ontooltiptext)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xffff, Ontooltiptext)
3,
BOOL CXXXDlg::Ontooltiptext(UINT, NMHDR* pnmhdr, LRESULT* presult)
{
int AFXAPI AfxLoadString(UINT nIDS, LPTSTR lpszBuf, UINT nMaxBuf = 256);
ASSERT(pnmhdr->code == TTN_NEEDTEXTA || pnmhdr->code == TTN_NEEDTEXTW);
// allow top level routing frame to handle the message
if (GetRoutingFrame() != NULL)
return FALSE;
// need to handle both ansi and unicode versions of the message
TOOLTIPTEXTA* pttta = (TOOLTIPTEXTA*)pnmhdr;
TOOLTIPTEXTW* ptttw = (TOOLTIPTEXTW*)pnmhdr;
TCHAR szfulltext[256];
CString csttiptext;
CString cststatustext;
UINT nid = pnmhdr->idFrom;
if (pnmhdr->code == TTN_NEEDTEXTA && (pttta->uFlags & TTF_IDISHWND) ||
pnmhdr->code == TTN_NEEDTEXTW && (ptttw->uFlags & TTF_IDISHWND))
{
// idfrom is actually the hwnd of the tool
nid = ((UINT)(WORD)::GetDlgCtrlID((HWND)nid));
}
if (nid != 0) // will be zero on a separator
{
AfxLoadString(nid, szfulltext);
// this is the command id, not the button index
AfxExtractSubString(csttiptext, szfulltext, 1, '/n');
AfxExtractSubString(cststatustext, szfulltext, 0, '/n');
}
// non-unicode strings only are shown in the tooltip window...
if (pnmhdr->code == TTN_NEEDTEXTA)
lstrcpyn(pttta->szText, csttiptext,
(sizeof(pttta->szText)/sizeof(pttta->szText[0])));
else
_mbstowcsz(ptttw->szText, csttiptext,
(sizeof(ptttw->szText)/sizeof(ptttw->szText[0])));
*presult = 0;
// bring the tooltip window above other popup windows
::SetWindowPos(pnmhdr->hwndFrom, HWND_TOP, 0, 0, 0, 0,
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOSIZE);
return TRUE; // message was handled
}