-
April 22nd, 2008, 02:10 PM
#1
How to get a View handle?
Hello,
I have an SDI Doc/View application and I need to get access to the CFormView derived class to update some data in the view. Whats the best way to get a handle to the view class from outside that class?
Thanks!
-
April 22nd, 2008, 02:47 PM
#2
Re: How to get a View handle?
From anywhere inside your MFC app, you can call AfxGetMainWnd to get the main frame window. Next call the CFrameWnd methods GetActiveDocument or GetActiveView to get the doc or the view.
-
April 22nd, 2008, 03:30 PM
#3
Re: How to get a View handle?
Actually, the best way (since this is a Doc/View architecture) is to store the data in your document. The view should be responsible for displaying that data to the user however needed.
Now when you need to change the data, change it in the document and then call the document class UpdateAllViews(). This will call the OnUpdate for each view, and the view can then redraw/update itself from the new document data. (Of course, you have to write the code in the OnUpdate handler to do whatever is needed.)
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
April 23rd, 2008, 06:56 AM
#4
Re: How to get a View handle?
Hello,
There are many methods to do this.
Andreas Masur, in his FAQ MFC Doc/View: How to obtain a pointer to various objects gives a good compilation on how to get various objects from any part of the application. MSDN also gives good advice to get document and view from any where in the application in their article How To Get Current CDocument or CView from Anywhere. Another method is to create a variable of application class and initialise the variable with the view / document pointer in the respective constructor.
Regards,
Pravin.
-
April 23rd, 2008, 07:52 AM
#5
Re: How to get a View handle?
Hello,
I tried the following code:
Code:
CDisplayView* view = dynamic_cast<CDisplayView*>(((CFrameWnd*)AfxGetMainWnd())->GetActiveView());
but it gives me an error for DisplayView.h:
error C2065: 'IDD_DISPLAY_FORM' : undeclared identifier
Any idea why I get this error?
Thanks!
-
April 23rd, 2008, 12:23 PM
#6
Re: How to get a View handle?
The IDD_DISPLAY_FORM is a resource id to a dialog or a formview. I believe you just need to include resource.h in the file you are calling GetActiveView.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|