What We Have Here Is a Failure to Communicate

Dear Dr. GUI:

I'm using Visual C++ 1.5. My application has a dialog box that creates another dialog box (while the first dialog box is still active). What I want to do is pass data from/to my document and the second dialog. Unfortunately, I'm not in the view, so I can't use GetDocument to get the pointer to the document.

What I'm doing now is to store the pointer to the document in the dialog before I activate it from the view using GetDocument. Then when I'm in the dialog I can use the pointer I had previously stored in the dialog to access the data.

There must be an easier way to get a dialog view so I can use something like GetDocument instead of having to store the pointer in the dialog. Can you help? Thanks.

Joe Mintzer
Gilbert, Arizona

Dr. GUI replies:

I am so glad that you came to me for the answer. There is, indeed, an easier way to do this. Just pass a pointer to your view window to the constructor for your CDialog-derived dialog box. From within the dialog box, you can call CWnd::GetParent to get a CWnd pointer to the view class as follows:

CMyDialog MyDlg(&MyView) ;
CWnd* pMyView = MyDlg.GetParent() ;

Voilą! You now have the pointer you need to make your call to GetDocument.