How to add description in dynamically created CMFC

2019-09-19 13:33发布

The CMFCToolbar Inherits the function EnableToolTip which does not help the developer if he is creating the toolbar dynamically and not adding the Description and title in resource. I made an extension for CMFCToolBar and wrote a function :

BOOL CMFCToolBarEx::OnNeedTipText(UINT /*id*/, NMHDR* pNMH, LRESULT* /*pResult*/)
{
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMH;
   // UINT nID = static_cast<int>(pNMH->idFrom);
    CString strTip = _T("");

    CPoint point;
    ::GetCursorPos(&point);
    ScreenToClient(&point);
    INT_PTR nHit = ((CMFCToolBar*)this)->HitTest(point);

    if(nHit == -1)
        return FALSE;

    CMFCToolBarButton* pButton = GetButton((int)nHit);
    strTip = pButton->m_strText;
    _tcscpy(pTTT->lpszText , strTip.GetBuffer(0));

    return TRUE;
}

to show tooltip in cmfctoolbar button.

The cmfctoolbar button takes no parameter and has no function to set description. The constructor takes parameter like :

pToolBarButton = new CMFCToolBarButton(nId, nIconIndex, lpszText);

If I set the parameter lpszText with title only the tooltip appears like this

I need to add description to this toolbar and view it like this if anyone can suggest a better way to do it

1条回答
Emotional °昔
2楼-- · 2019-09-19 13:35

Anyone looking for answer. Here you go just add

CTooltipManager::SetTooltipText((TOOLINFO*) pTTT, m_pToolTip, AFX_TOOLTIP_TYPE_TOOLBAR, strTip, strDescr); 

to your overridden onneedtiptext function.

查看更多
登录 后发表回答