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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 108
ffmpeg - "rtsp://...... Operation not permitted" 4 86
centeredAverage challenge 8 179
mapBully challenge 6 154
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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