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
Solved

Splitters, Views, and Menus

Posted on 1998-08-03
3
189 Views
Last Modified: 2013-11-19
I have an app that has two splitter windows, one embedded inside the other so that three different views are visible at any given time. I noticed that my menu handlers and update handlers will only function corectly when I have given focus to the view that is supposed to handle them. For example, if I want view 1 to handle menu item 1 and update handler 1, I have to make sure view 1 has focus. If either view 2 or 3 has focus the handler and update handler do not respond. Is there a way to make this application know which view has a handler and update handler for each menu ID? Is this a command routing issue? The commands don't seem to get routed to all of the views.
0
Comment
Question by:JagerM
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 50 total points
ID: 1320168
This is the way it's supposed to work.  Each view may have different ways of handling the same message.  For example if you have a CListView it may handle a menu item that says "Delete" very diffently from a CEditView.  

If you always want view 1 to handle a given message, you need to be able to pass it from view 2 to view 1.  This also goes for the Update messages.  For example you may have something like this:

void CView1::OnHandleMyMessage()
{
    // Do something
}

void CView1::OnUpdateMyMessage(CCmdUI* pCmdUI)
{
    // Handle update
}

Then in CView2 you would call the CView1 handlers

void CView1::OnHandleMyMessage()
{
    // Get pointer to view2
    CView2* pView2 = GetView2();
    pView2->OnHandleMyMessage();
}

void CView1::OnUpdateMyMessage(CCmdUI* pCmdUI)
{
    // Get pointer to view2
    CView2* pView2 = GetView2();
    pView2->OnUpdateMyMessage(pCmdUI);
}

0
 
LVL 2

Expert Comment

by:jstolan
ID: 1320169
Oops

I see I made a typo.  The last two items should read:

void CView2::OnHandleMyMessage()
{
    // Get pointer to view1
    CView1* pView1 = GetView1();
    pView1->OnHandleMyMessage();
}

void CView2::OnUpdateMyMessage(CCmdUI* pCmdUI)
{
    // Get pointer to view1
    CView1* pView1 = GetView1();
    pView1->OnUpdateMyMessage(pCmdUI);
}

Also note that you will need to have some way of getting the pointers to the otherviews.  The ChildFrame is a good place to put these functions.
0
 

Author Comment

by:JagerM
ID: 1320170
This doesn't seem like a graceful way to handle it, but it's probably the right methodlology. I looked into overridding OnCmdMsg for the MainFrame and routing the messages to all Views, but this is protected in the View classes. It's also tricky because I'm swapping views in two of the splitter windows based on what's happening in the third.

I ended up using a global CMap object that essentially acts as a custom message map. I have an enumerated type:

enum EnViewType
{
VIEW_FILE,
VIEW_PROJECT,
VIEW_WORKGROUP
};

that I map to a View pointer. i.e.

CMap< EnViewType, EnViewType, CView *, CView *> g_mapMessages

In each view's OnCreate member, it registers with this global mapping.

CFileView::OnCreate
{
.
g_mapMessages.SetAt( VIEW_FILE, this );
.
}

I then handle every menu item and update handler in the MainFrame and route it to the appropriate view using this map. Now all of my menus are handled correctly no matter which view is active. Not to graceful either, but it works pretty well.

Thanks for the help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
Separate into files by filename 12 87
Fibonacci challenge 11 132
mapAB Challlenge 35 155
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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