Handling TTN_NEEDTEXT Notification for Tool Tips
As part of enabling tool tips, you handle the TTN_NEEDTEXT message by adding the following entry to your owner window’s message map:
ON_NOTIFY_EX(TTN_NEEDTEXT, 0**,memberFxn)**
memberFxn
The member function to be called when text is needed for this button.
Note that the ID of a tool tip is always 0.
Declare your handler function in the class definition as follows:
BOOL CMyClass**::memberFxn(UINTid,NMHDR** * pTTTStruct**,LRESULT*pResult);**
where the italicized parameters are:
id Identifier of the control that sent the notification. Not used. The control id is taken from the NMHDR structure.
pTTTStruct A pointer to the structure. This structure is also discussed further in The TOOLTIPTEXT Structure.
pResult A pointer to result code you can set before you return. TTN_NEEDTEXT handlers can ignore the pResult parameter.
As an example of a form-view notification handler:
BOOL CMyFormView::OnToolTipNotify( UINT id, 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);
}
void CTestView::OnInitialUpdate()
{
CMyFormView::OnInitialUpdate();
EnableToolTips(TRUE);
}