VS2008SP1/VS2010新建的SDI/MDI程序,为菜单项添加ToolTip信息

//在CMainFrame类中添加处理虚函数
//virtual BOOL OnMenuButtonToolHitTest(CMFCToolBarButton* pButton, TOOLINFO* pTI);
// MSDN: Override this method if you want to provide a tooltip information about a specific menu item. 

BOOL CMainFrame::OnMenuButtonToolHitTest (CMFCToolBarButton* pButton, TOOLINFO* pTI)
{
    ASSERT_VALID (pButton);
    ASSERT (pTI != NULL);

    if (pButton->m_nID == 0 || pButton->m_nID == (UINT)-1)
    {
        return FALSE;
    }

    CString strText = pButton->m_strText;
    strText.Remove (_T('&'));

    if (strText.IsEmpty ())
    {
        return FALSE;
    }

    if (pTI)
    {
        pTI->lpszText = (LPTSTR) ::calloc ((strText.GetLength () + 1), sizeof (TCHAR));
        if (pTI->lpszText)
        {
            lstrcpy (pTI->lpszText, strText);
        }
    }

    return TRUE;
}

 // 效果如下所示:
VS2008SP1/VS2010新建的SDI/MDI程序,为菜单项添加ToolTip信息_第1张图片

你可能感兴趣的:(null,menu,2010)