using functions in View class from dialog class

HI
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

Thanks
KingPie
kingpieAsked:
Who is Participating?
 
tma050898Commented:
kingpie,

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);
 dlg.DoModal();
}

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.

Tom

0
 
kingpieAuthor Commented:
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.
KingPie

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

0
 
tma050898Commented:
kingpie,

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.

Tom

0
 
kingpieAuthor Commented:
thanks, that works fine, I eventually used the one in the VC++ FAQ which amounts to the same thing.
KingPie
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.