?
Solved

Splitters, Views, and Menus

Posted on 1998-08-03
3
Medium Priority
?
197 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
[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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
jstolan earned 150 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

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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 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