CView Access From Anywhere






3.45/5 (19 votes)
Jan 16, 2001

119315

869
Access your View class from anywhere in the application.
Introduction
MFC (Access to CView from Anywhere).
This is the cheats way of getting access to CView
from anywhere in your application.
- In you
CWinApp
, create two functions: avoid
functionStoreMyView (CView* pView)
and aCView*
functionGetMyView ()
. - Declare a pointer of type
CView
in theCWinApp
class. - In
CView
constructor, get the application using the following lines:CWinApp* pApp = (CWinApp*) AfxGetApp (); pApp->StoreMyView (this);
- In
CWinApp GetMyView ()
, return your declared pointer. - In
CWinApp StoreMyView
, point your data member to the parameter value, i.e. say, data member ism_pView
and parameter ispView
; som_pView
=pView
; - Now you can access your view using the application object, i.e.,
CWinApp * pApp = (CWinApp*) AfxGetApp (); CView * pView = pApp. GetMyView ();
- Don't forget to include View.h and Doc.h in CWinApp.h and the view.h is included in .cpp files automatically when you create your data member in VC++.
That's all folks.
Any comments, mail to: kings_oz@yahoo.com.
History
2001-01-15 - First release