Print Page | Close Window

Menu via CMultiDocTemplate?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=9738
Printed Date: 14 November 2025 at 7:17pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Menu via CMultiDocTemplate?
Posted By: Ashok
Subject: Menu via CMultiDocTemplate?
Date Posted: 29 February 2008 at 2:36am
Hi, I have multiple views in my application, How can I show different menu for different view. For example, If I activate one view I have to display one menu. If I activate another view I have to show another menu.
 
I have a tree view like this in my application:
 
+Folder
  +Section1
      MyWorksheet
  +Section2
      Excel
 
I have 2 Menu resources: IDR_MAIN_MENU for MyWorksheet view , IDR_EXCEL_MENU for Excel view
 
If I open the MyWorksheet(double click).It should display that view menu in the menu bar.
If I open the Excel(double click).It should display that view menu in the menu bar.
 
In my old application(without ToolkitPro) it is working fine because they are calling OnUpdateFrameMenu().
How can I do in my current application by getting the DocTemplate Menu. Please Help.



Replies:
Posted By: mgampi
Date Posted: 29 February 2008 at 3:59am
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


Posted By: Ashok
Date Posted: 29 February 2008 at 7:17am
Hi, Thanks for the valuable suggestion. That's all right the OpenNewDocument will display the right menu for the current view. My question is if both the views are already opened, when I am toggle between one view to another view I want to change the menu. how?


Posted By: mgampi
Date Posted: 29 February 2008 at 7:43am
Hi;
 
Try CMDIFrameWnd::MDIActivate(). I call this when I want to programmatically switch between different open documents. The framework calls the same, when the user clicks into another - not focused - mdi client window. 


-------------
Martin

Product: Xtreme Toolkit v 22.1.0, new Projects v 24.0.0
Platform: Windows 10 v 22H2 (64bit)
Language: VC++ 2022


Posted By: Ashok
Date Posted: 29 February 2008 at 8:34am
Hi,
  Will you please help with code. Thanks in advance.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net