Solved

MainFrame <=> Doc/View communications

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

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