Solved

Views sharing menus, or is it menus sharing views?

Posted on 1999-01-29
5
319 Views
Last Modified: 2013-11-20
I have an MDI application with a default document view that opens when the program starts. The document is actually data coming in from banks of remote testers. I am opening another view of this document (a chart instead of raw numbers) but the framework is greying out most of my menu items.

How do I open a new view and get it to share the same Main Frame menu of my default view? I won't show you how I'm creating the new view in case someone has a better way altogether. The original view is done pretty much per the app wizard with a CMultiDocTemplate.

Thanks,
NC
0
Comment
Question by:nchenkin
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:MelissaC
ID: 1328529
Hi Nchenkin,
You can manipulate your menu-items with the OnUpdate-functions. Just go to the class wizard and select the ID of a menu item. Then select UPDATE_COMMAND_UI and add a handler. In this handler, you can define when the items must be enabled or not, example:

void CMainFrame::OnUpdateFileConnect(CCmdUI* pCmdUI)
{
   pCmdUI->Enable( GetDocument()->IsDatabaseConnected() )      
}

When you let the document and the mainframe deal with all those things, you are not dependent of what kind of view you have displayed.
You can manipulate the views in turn with CDocument::UpdateAllViews(...)
Hope this is what you need,

Melissa

0
 

Author Comment

by:nchenkin
ID: 1328530
Hi Melissa,

Thanks for your answer. It provided me with some new information but wasn't quite what I was looking for. In your case I would have to go and create an UPDATE_COMMAND_UI for each menu item, which seems painful.

There <must> be some way of associating an entire menu with a new view and making that menu identical to an existing one. Somewhere at this level:

RECT rect;                  // fill it in with some stuff....

CCreateContext cc;
cc.m_pNewViewClass     = pViewClass;   // yes, the new view class
cc.m_pCurrentDoc          = pDoc;             // and our existing doc full of data
cc.m_pNewDocTemplate = NULL;            // do I need something here?
cc.m_pLastView             = NULL;            // how about these guys??
cc.m_pCurrentFrame       = NULL;

CMDIChildWnd* pFrame = new CMDIChildWnd;
pFrame->Create(NULL, "", WS_CHILD|WS_OVERLAPPEDWINDOW, rect, NULL, &cc );

There must be something really simple to do here to associate my resources in the existing view with this new view, I woukd think. Or, is this the right way to create a new view window at all??

Nelson
0
 
LVL 2

Expert Comment

by:MelissaC
ID: 1328531
Hi Nelson,

Now I see what you mean. In the Applications InitInstance function, you can register the different kinds of documents your app will support with a document template. A document template defines the relationships among three types of classes: the document class, the view class and the mainframe. Just add another document template, which uses the same document class and mainframe class, but with another view class, like this:

CMultiDocTemplate* pDocTemplate2;
pDocTemplate2 = new CMultiDocTemplate(
    IDR_SECONDVIEWTYPE,   //ID of the menu
    RUNTIME_CLASS(CMyDoc),  //
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CSecondView));
AddDocTemplate(pDocTemplate2);

Hope this helps, good luck.

Melissa


0
 
LVL 2

Accepted Solution

by:
MelissaC earned 100 total points
ID: 1328532
Hi Nelson,

Now I see what you mean. In the Applications InitInstance function, you can register the different kinds of documents your app will support with a document template. A document template defines the relationships among three types of classes: the document class, the view class and the mainframe. Just add another document template, which uses the same document class and mainframe class, but with another view class, like this:

CMultiDocTemplate* pDocTemplate2;
pDocTemplate2 = new CMultiDocTemplate(
    IDR_SECONDVIEWTYPE,   //ID of the menu
    RUNTIME_CLASS(CMyDoc),  //
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CSecondView));
AddDocTemplate(pDocTemplate2);

Hope this helps, good luck.

Melissa


0
 

Author Comment

by:nchenkin
ID: 1328533
Hello Melissa,

As I was driving home last night I thought of this as a likely solution, but I don't think I'll actually test it out until Monday.

One final question if you don't mind. Later, I guess I'll open my window something like so:

CChildFrame* pFrame = (CChildFrame*)                             pDocTemplate2->CreateNewFrame(pDocument, NULL);
// check we got it...
pDocTemplate2->InitialUpdateFrame(pFrame, pDocument);

Correct? Then how do I get back my pDocTemplate2 pointer at a distant time and place (a menu handler function to be precise)?

Thanks again,
Nelson
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 95
zeroFront challenge 7 99
Thin secure Windows 10 5 98
Capture logon name 13 73
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question