Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Menu via CMultiDocTemplate?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Menu via CMultiDocTemplate?

 Post Reply Post Reply
Author
Message
Ashok View Drop Down
Senior Member
Senior Member


Joined: 02 May 2007
Status: Offline
Points: 164
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ashok Quote  Post ReplyReply Direct Link To This Post Topic: Menu via CMultiDocTemplate?
    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.
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1210
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Ashok View Drop Down
Senior Member
Senior Member


Joined: 02 May 2007
Status: Offline
Points: 164
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ashok Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1210
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Ashok View Drop Down
Senior Member
Senior Member


Joined: 02 May 2007
Status: Offline
Points: 164
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ashok Quote  Post ReplyReply Direct Link To This Post Posted: 29 February 2008 at 8:34am
Hi,
  Will you please help with code. Thanks in advance.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.