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

x
?
Solved

MainFrame <=> Doc/View communications

Posted on 2000-04-14
2
Medium Priority
?
942 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 120 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 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