Solved

Views sharing menus, or is it menus sharing views?

Posted on 1999-01-29
5
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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