![]() |
Menu via CMultiDocTemplate? |
Post Reply
|
| Author | |
Ashok
Senior Member
Joined: 02 May 2007 Status: Offline Points: 164 |
Post Options
Thanks(0)
Quote Reply
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. |
|
![]() |
|
mgampi
Senior Member
Joined: 14 July 2003 Status: Offline Points: 1210 |
Post Options
Thanks(0)
Quote Reply
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 |
|
![]() |
|
Ashok
Senior Member
Joined: 02 May 2007 Status: Offline Points: 164 |
Post Options
Thanks(0)
Quote Reply
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?
|
|
![]() |
|
mgampi
Senior Member
Joined: 14 July 2003 Status: Offline Points: 1210 |
Post Options
Thanks(0)
Quote Reply
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 |
|
![]() |
|
Ashok
Senior Member
Joined: 02 May 2007 Status: Offline Points: 164 |
Post Options
Thanks(0)
Quote Reply
Posted: 29 February 2008 at 8:34am |
|
Hi,
Will you please help with code. Thanks in advance.
|
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |