Solved

MainFrame <=> Doc/View communications

Posted on 2000-04-14
2
917 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

18 Experts available now in Live!

Get 1:1 Help Now