Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CView Access From Anywhere

0.00/5 (No votes)
15 Jan 2001 1  
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.

  1. In you CWinApp, create two functions: a void function StoreMyView (CView* pView) and a CView* function GetMyView ().
  2. Declare a pointer of type CView in the CWinApp class.
  3. In CView constructor, get the application using the following lines:
    CWinApp* pApp = (CWinApp*) AfxGetApp ();
    pApp->StoreMyView (this);
  4. In CWinApp GetMyView (), return your declared pointer.
  5. 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;
  6. Now you can access your view using the application object, i.e.,
    CWinApp * pApp = (CWinApp*) AfxGetApp ();
    CView * pView = pApp. GetMyView ();
  7. 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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here