|
Hi Ashok;
In our project we have about 15 different document types and each document has its own menu resource. In InitInstance we call CDocManager::AddDocTemplate(). Thats it; the framework switches the menu resources according to the active document type.
pDocTemplate = new CMultiDocTemplate(IDR_STANDARDTRENDTYPE,
RUNTIME_CLASS(CTrendDoc),
RUNTIME_CLASS(CTrendFrame),
RUNTIME_CLASS(CTrendView)); // Trend document type
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(IDR_PHASETYPE,
RUNTIME_CLASS(CPhaseDoc),
RUNTIME_CLASS(CPhaseFrame),
RUNTIME_CLASS(CPhaseView));
AddDocTemplate(pDocTemplate); // Another template type
IDR_STANDARDTRENDTYPE and IDR_PHASETYPE are resource IDs (icon and menu).
Normally when you add more than one document template to CDocManager, a dialog appears whenever a new document has to be created. To prevent this dialog from showing, you have to create your own OpenNewDocument() function like this:
CDocument* CXRVisualizerApp::OpenNewDocument(const CString &strTarget){
CString strDocName;
CDocTemplate* pSelectedTemplate;
CWaitCursor Wait;
POSITION pos = GetFirstDocTemplatePosition();
while (pos != NULL)
{
pSelectedTemplate = (CDocTemplate*)GetNextDocTemplate(pos);
ASSERT(pSelectedTemplate != NULL);
ASSERT(pSelectedTemplate->IsKindOf(RUNTIME_CLASS(CDocTemplate)));
pSelectedTemplate->GetDocString(strDocName, CDocTemplate::docName);
if (!strDocName.IsEmpty() && (strDocName == strTarget))
{
CDocument* pDoc=pSelectedTemplate->OpenDocumentFile(NULL);
return pDoc; // Success
}
}
return NULL; // Failure
}
Then, when you have to create a new document, call this function in your OnNewMyDocument() command handler.
Hope this helps.
------------- Martin
Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022
|