Solved

Views sharing menus, or is it menus sharing views?

Posted on 1999-01-29
5
301 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 49
centeredAverage challenge 8 120
fizzArray  challenge 1 47
canBalance challenge 34 65
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now