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

Independent Software Vendors: 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
Get filename and folder into excel 7 87
Pressing cancel button with C# UI Automation 3 101
sum67 challenge 35 128
I could not set window to top 4 60
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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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