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: a void
function StoreMyView (CView* pView)
and a CView*
function GetMyView ()
.
- Declare a pointer of type
CView
in the CWinApp
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 is m_pView
and parameter is pView
; so m_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