Solved

MainFrame <=> Doc/View communications

Posted on 2000-04-14
2
923 Views
Last Modified: 2013-11-20
On SDI/MDI applications, the Toolbar(s) belong to CMainFrame. How can I affect their behavior from Doc/View classes? I want to show/hide them on request from menu command.

Of course, I could take menu events in MainFrame class, but it would not be good project design, and besides, the broader question is this: how do I communicate between MainFrame and Doc/View classes?
0
Comment
Question by:Lescha
2 Comments
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2715945
to acess any doc variable from view class use

GetDocument()->



as you pointer

to acess the mainframe from the view class use
((CMainframe*)AfxGetMainWnd())->

as your pointer

notice that the CFrameWnd pointer typecasted to your CMainFrame   class

to acess view from document use


GetActiveView()->

GetNextView()->

etc













0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 30 total points
ID: 2716304
You put the handling code in the document or view itself.

To enable/disable menus/toolbar, you respond to ON_UPDATE_COMMAND_UI and SetEnable etc as required. To respond to a command use ON_COMMAND.

Yourarely need to talk directly between view/doc/mainframe when it comes to menus/toolbars.  MFC routes messages appropriately for you.

When you DO need to, use GetActiveView & GetActiveDocument (from Mainframe); GetDocument & AfxGetMainWnd (from view); GetFirstViewPosition/GetNextView & AfxGetMainWnd (from doc).

But generally, it is best to handle events in the apropriate class in the first place. ie. if a toolbar butto / menu item applies to the current document, then handle it in the document class etc.

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

823 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