Solved

using functions in View class from dialog class

Posted on 1998-05-31
5
180 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:kingpie
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 50 total points
Comment Utility
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
 

Author Comment

by:kingpie
Comment Utility
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
 
LVL 3

Expert Comment

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

0
 
LVL 3

Expert Comment

by:tma050898
Comment Utility
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
 

Author Comment

by:kingpie
Comment Utility
thanks, that works fine, I eventually used the one in the VC++ FAQ which amounts to the same thing.
KingPie
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 73
how to monitor remote shell execution on linux 9 92
sum13 challenge 24 77
ShiftLeft challenge 21 65
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now