1 year ago
#335320
Bill Heitler
How to share a menu between different CMultiDocTemplate instances
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.
c++
menu
mfc
mdi
0 Answers
Your Answer