从文档更新CMFCRibbonBar元素 [英] Updating CMFCRibbonBar elements from document

查看:190
本文介绍了从文档更新CMFCRibbonBar元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从CDocument派生类更新功能区,因为与功能区状态相关的信息存储在此处.由向导创建并在资源管理器中编辑

I would like to update the ribbon from the CDocument derived class because the information relevant for ribbon's status is stored there. The was created by the Wizard and edited in resource manager

某些元素(按钮,复选框)可以使用ON_UPDATE_COMMAND_UI宏进行更新.

Some elements (Buttons, checkboxes) can be updated with ON_UPDATE_COMMAND_UI macro.

但是我对更新其他诸如CMFCRibbonComboBox或CMFCRibbonProgressBar之类的内容感到头疼,因为CCmdUI没有提供合适的函数来处理它们(即AddItem)

But I have a headache with update other things like CMFCRibbonComboBox or CMFCRibbonProgressBar because CCmdUI doesn't provide suitable functions to deal with them (ie AddItem)

使用GetDlgItem的其他选项不起作用,因为CDocument和RibbonBar元素都不是从CWnd派生的.

Other option using GetDlgItem doesn't work, because neither CDocument nor RibbonBar elements are derived from CWnd.

那么更新CMFCRibbonComboBox和其他的方式是什么?

So what is the way to update CMFCRibbonComboBox and others?

推荐答案

我首先尝试了RogerRowland的解决方案,但很快就为每个琐事向MainFrame添加一个函数变得烦人,然后从文档中调用AfxGetMainWnd()并在其上应用static_cast它.

I first tried RogerRowland's solution, but it soon became annoying to add a function to MainFrame for every trifle , then to call AfxGetMainWnd() from document and apply static_cast on it.

现在,我现在将指针存储到文档中的ProgressBar和组合框.我将方法添加到CMainFrame中以获取它们,并删除了其余的方法.

Instead I now store pointers to the ProgressBar and the combobox inside the document. I added the methods to CMainFrame to get them and removed the rest.

唯一困难的是,文档是在主窗口之前构建的.因此,我必须延迟上述指针的初始化.我通过在文档中添加setRibbonBarPointers()并从视图的OnInitialUpdate()调用来解决它

The only dificulty with it is the fact that the document is constructed before the main window. So I have to delay the initialisation of the mentioned pointers. I solved it by adding setRibbonBarPointers() to the document and calling it from OnInitialUpdate() of the view

这篇关于从文档更新CMFCRibbonBar元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆