Handling TTN_NEEDTEXT Notification for Tool Tips

HomeOverviewHow Do I

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( UINT id, NMHDR * pTTTStruct, LRESULT * pResult );

where the italicized parameters are:

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);
}