Solved

Splitters, Views, and Menus

Posted on 1998-08-03
3
183 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
How to know only "File created" with EventLog 3 29
centeredAverage challenge 8 123
fix34  challenge 9 97
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now