在运行时设置CMenu项目提示

编程入门 行业动态 更新时间:2024-10-22 14:38:40
本文介绍了在运行时设置CMenu项目提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在运行时设置CMenu项提示?我知道可以在VS中的资源编辑器中完成此操作,但是我没有这样的资源,无法创建菜单,而且菜单项是动态的.

How can I set a CMenu item prompt at runtime? I know that it can be done in resource editor in VS, but I don't have such resource and create menu and it's items dynamically.

推荐答案

如果使用的是MFC Feature Pack,则需要覆盖MainFrame类的OnMenuButtonToolHitTest:

If you are using MFC Feature Pack, you will need to override the OnMenuButtonToolHitTest of your MainFrame class:

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.我不确定,但是我认为您唯一可以换行的是将标题和文本分开的行.

You will have to define in your resource file strings with the EXACT same ID as your menus; and their format is Prompt text\nPrompt title. I am not sure but I think the only new line you can have is the one that separates title from text.

除了使用鼠标悬停菜单时仅显示提示之外,您可能还需要做其他事情.您可以通过覆盖MainFrame类的OnMenuSelect来做到这一点:

You may also want to do things beyond simply displaying prompts when hovering menus using the mouse. You can do it by overriding OnMenuSelect of your MainFrame class:

void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu) { if (nItemID == ID_MENU_I_WANT_TO_PROCESS) { DoThings(); } __super::OnMenuSelect(nItemID, nFlags, hSysMenu); }

我建议您对MainFrame类上的GetMessageString函数进行覆盖,并在其中放置一个断点,以了解流程的进行.

I recommend you to make an override to GetMessageString function on your MainFrame class and put a breakpoint there for you see how the flow goes.

更多推荐

在运行时设置CMenu项目提示

本文发布于:2023-06-10 22:53:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:提示   项目   CMenu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!