Solved

MainFrame <=> Doc/View communications

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 71
string initialization in java 11 117
withoutTen challenge 14 137
My project did see openJDK that I installed. What could be the problem 7 161
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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

763 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