如何在不同的 CMultiDocTemplate 实例之间共享菜单
我有一个数据分析程序(C++、MFC、MDI 接口),可以从多个不同的商业源读取数据,每个源都有自己的文件格式,但为每种源类型提供相同的视图和分析选项。因此,在 mainApp::InitInstance 中,我实例化了几个 CMultiDocTemplate,每个模板都有自己的文档类,但具有相同的框架和视图类。 例如,
pDocTemplate = new CMultiDocTemplate(
IDR_AXONTYPE,
RUNTIME_CLASS(CAxonDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDataView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_CEDTYPE,
RUNTIME_CLASS(CCEDDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDataView));
AddDocTemplate(pDocTemplate);
我因此有多个 nIDResource 值 (IDR_),每个文件类型对应一个。这是必要的,因为每个模板需要不同的资源字符串(不同的文件扩展名等)。然而,每个视图需要显示相同的分析选项菜单,并且IDR_值既指字符串资源又指菜单资源。所以目前,我在 rc 资源文件中有重复的相同菜单。这工作正常,但如果我添加一个新的分析工具,我必须使用 VS 资源编辑器单独更新每个菜单(或直接编辑 rc 代码),这是乏味且容易出错的。
我确信必须有一种方法可以在多个模板之间共享一个菜单资源,这样我只需编辑一个菜单即可更新不同文档的所有视图菜单,但我很不好意思地说我不知道如何最好地实现这一目标。 (很尴尬,因为这个程序已经有 20 多年的历史了,而且已经更新了很多次,但我一直忍受着这种明显的低效率。)
任何帮助/建议将不胜感激。
I have a data analysis program (C++, MFC, MDI interface) that can read data from several different commercial sources, each with its own file format, but which offers the same view and analysis options for each source type. So in the mainApp::InitInstance I instantiate several CMultiDocTemplates each with its own document class, but with the same frame and view class.
e.g.
pDocTemplate = new CMultiDocTemplate(
IDR_AXONTYPE,
RUNTIME_CLASS(CAxonDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDataView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_CEDTYPE,
RUNTIME_CLASS(CCEDDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDataView));
AddDocTemplate(pDocTemplate);
I thus have multiple nIDResource values (IDR_), one for each file type. This is necessary because each template needs a different resource string (different file extenson, etc). However, each view needs to show the same menu of analysis options, and the IDR_ value refers to both the string resource and the menu resource. So at the moment, I have duplicate identical menus in the rc resource file. This works OK, but if I add a new analysis facility, I have to update each menu separately using the VS resource editor (or edit the rc code directly), and that is tedious and error-prone.
I feel sure that there must be a way to have just one menu resource that is shared between the multiple templates, so that I only have to edit the one menu to update all the view menus for the different documents, but I am embarrassed to say that I don't know how best to achieve this. (Embarrassed because the program is 20+ years old and it's been updated numerous times, but I've lived with this obvious inefficiency all this time.)
Any help/suggestions would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论