如何在运行时设置 CMenu 项提示?我知道它可以在 VS 中的资源编辑器中完成,但我没有这样的资源并动态创建菜单和它的项目。
如果您使用 MFC 功能包,则需要覆盖OnMenuButtonToolHitTest
MainFrame 类的 :
BOOL CMainFrame::OnMenuButtonToolHitTest(CMFCToolBarButton* pButton, TOOLINFO* pTI)
{
if(!pButton)
return FALSE;
if(!pTI)
return FALSE;
if (pButton->m_nID == UINT(-1)) //not a menu-item, but an opener menu for a sub-menu
return FALSE;
// Stolen from CMFCToolBar::OnToolHitTest on file afxtoolbar.cpp
// It is not needed to do the GetMessageString part, because it already done
// on function CMFCPopupMenuBar::OnToolHitTest of afxpopupmenubar.cpp file, which
// supplies the two parts to the Tooltip Manager
CString strTipText;
TCHAR szFullText[256];
AfxLoadString(pButton->m_nID, szFullText);
AfxExtractSubString(strTipText, szFullText, 1, '\n');
pTI->lpszText = _tcsdup(strTipText);
return TRUE;
}
您必须在资源文件字符串中定义与菜单完全相同的 ID;他们的格式是Prompt text\nPrompt title
. 我不确定,但我认为您可以拥有的唯一新行是将标题与文本分开的行。
除了在使用鼠标悬停菜单时简单地显示提示之外,您可能还想做一些事情。您可以通过覆盖OnMenuSelect
您的MainFrame
班级来做到这一点:
void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
if (nItemID == ID_MENU_I_WANT_TO_PROCESS)
{
DoThings();
}
__super::OnMenuSelect(nItemID, nFlags, hSysMenu);
}
我建议您覆盖GetMessageString
MainFrame 类的功能,并在那里放置一个断点,以便您查看流程的进展情况。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句