[英]Ribbon UI dynamic button menu edit
I have an application with a ribbon UI. 我有一个功能区UI的应用程序。 In this UI a button exists with a menu attached to it.
在此UI中,存在一个按钮,并附加有一个菜单。 What I wish to do is access the menu from the button handler to dynamically add and remove menu items.
我希望做的是从按钮处理程序访问菜单,以动态添加和删除菜单项。
void
CMyScrollView::OnMenuButtonHandler ()
{
// TODO: Add your command handler code here
CMFCRibbonBar *pRibbon = ((CMDIFrameWndEx*)GetTopLevelFrame())GetRibbonBar()
// Control ID_BTN_EDIT_MENU
// This where I would like to isolate and vary menu contents
}
In the CMainFRame window create a handler for the AFX_WM_ON_BEFORE_SHOW_RIBBON_ITEM_MENU message (ON_REGISTERED_MESSAGE). 在CMainFRame窗口中,为AFX_WM_ON_BEFORE_SHOW_RIBBON_ITEM_MENU消息(ON_located_MESSAGE)创建一个处理程序。
Check for the Id of the button. 检查按钮的ID。 Remove all previous items and add the one, you want.
删除所有先前的项目,然后添加所需的项目。
LRESULT CMainFrame::OnBeforeShowRibbonItemMenu(WPARAM,LPARAM lp)
{
CMFCRibbonBaseElement *pElement = reinterpret_cast<CMFCRibbonBaseElement*>(lp);
// Try to get our menu button
switch (pElement->GetID())
{
case ID_RIBBON_DROPDOWN_BUTTON:
{
CMFCRibbonButton *pButton = DYNAMIC_DOWNCAST(CMFCRibbonButton, pElement);
if (pButton)
{
// MY_LIST copntains members with the ID and the text: m_uiCmdId, m_strTitle
const MY_LIST &list = ....;
if (list.size()!=0)
{
pButton->RemoveAllSubItems();
for (it = list.begin(); it!=list.end(); ++it)
pButton->AddSubItem(new CSomeKindOfRibbonButton(it->m_uiCmdId, it->m_strTitle));
}
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.