using functions in View class from dialog class

Posted on 1998-05-31
Last Modified: 2013-11-19
I need to access functions in my View class from a user dialog class, how (if this is the correct thing to do) do I get a pointer to the current View so that I can call say, MyView->Monitor().. etc

Question by:kingpie
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
  • 3
  • 2

Accepted Solution

tma050898 earned 50 total points
ID: 1315812

Unfortunately, you don't give many details. Which view? Is the app and MDI app? Did the view display the dialog? Whether you are doing the correct thing or not by having your data in the view that the dialog needs depends on whose data it is.

Going on the assumption that the view displayed the dialog and that the view should be responsible for the data that you are referring to, the easiest thing to do would be to overload the dialog's constructor and pass the view's pointer to the dialog.

For example, your view function might look like this...
void CYourView::DoWhatever()
 CYourDialog dlg(this);

Then, your dlg can save the view's point in a member variable and have access to it from within any of its non-static functions.



Author Comment

ID: 1315813
I have a modeless dialog box that is created in CMyApp::InitInstance. A button on this dialog box is handled by a function in the dialog class.  It is from this function in the dialog class that I want to call the CMyView::Monitor() function.


Expert Comment

ID: 1315814
That just means that you'll have to a little bit more work. Is the app an sdi or mdi app?


Expert Comment

ID: 1315815

The document contains a list of all attached views. Therefore, you need to get the document first.

You can do this in an sdi app by saving the document pointer in the app object and calling AfxGetApp and then calling a helper function to get the document pointer. Another way to do this with either an sdi or mdi app is to call AfxGetMainWnd to get the mainframe object, followed by the frame's GetActiveDocument.

Once you have the document, you need to use the GetFirstViewPosition and GetNextView functions to iterate through the document's attached views until you get the one you want. Obviously, in an sdi app you know that the first view is the correct view.

Lemme know if you need any more details.



Author Comment

ID: 1315816
thanks, that works fine, I eventually used the one in the VC++ FAQ which amounts to the same thing.

Featured Post

Technology Partners: 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 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