Solved

Views sharing menus, or is it menus sharing views?

Posted on 1999-01-29
5
328 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
lucky13 challenge 11 158
building a service to accessed via telnet client, want colors ? 4 95
Line meaning 9 89
how to split multiple lines delimiter : 8 119
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: 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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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