65.9K
CodeProject is changing. Read more.
Home

CView Access From Anywhere

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.45/5 (19 votes)

Jan 16, 2001

viewsIcon

119315

downloadIcon

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.

  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