How to add description in dynamically created CMFCToolbar's ToolTip?

两盒软妹~` 提交于 2019-12-25 17:14:39

问题


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:


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.



来源:https://stackoverflow.com/questions/52332393/how-to-add-description-in-dynamically-created-cmfctoolbars-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!