Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Views sharing menus, or is it menus sharing views?

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
nchenkin
Asked:
nchenkin
  • 3
  • 2
1 Solution
 
MelissaCCommented:
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
 
nchenkinAuthor Commented:
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
 
MelissaCCommented:
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
 
MelissaCCommented:
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
 
nchenkinAuthor Commented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now