Click here to Skip to main content
13,799,657 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 15 Jan 2001

CView Access From Anywhere

, 15 Jan 2001
Rate this:
Please Sign up or sign in to vote.
Access your View class from anywhere in the application.


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:


2001-01-15 - First release


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


About the Author

Europe Europe
No Biography provided

You may also be interested in...

Comments and Discussions

GeneraltheApp Instead of AfxGetApp() Pin
Joseph Marzbani26-Feb-09 10:01
memberJoseph Marzbani26-Feb-09 10:01 
GeneralFor another View in MDI Pin
Ibrahim Hamoud22-Jul-03 14:14
memberIbrahim Hamoud22-Jul-03 14:14 
GeneralRe: For another View in MDI Pin
rj4527-Oct-03 22:41
memberrj4527-Oct-03 22:41 
GeneralOrder of includes is important! Pin
Slawa19-May-03 5:26
memberSlawa19-May-03 5:26 
GeneralRe: Order of includes is important! Pin
Slawa19-May-03 6:29
memberSlawa19-May-03 6:29 
GeneralAnother possibility... Pin
Brendan Tregear30-Jan-01 16:49
memberBrendan Tregear30-Jan-01 16:49 
GeneralRe: Another possibility... Pin
eric kaminski11-Nov-02 11:50
membereric kaminski11-Nov-02 11:50 
QuestionWhy? Pin
AlexMarbus22-Jan-01 13:10
memberAlexMarbus22-Jan-01 13:10 
AnswerRe: Why? Pin
dswigger28-Jul-01 10:19
memberdswigger28-Jul-01 10:19 
GeneralRe: Why? Pin
Swinefeaster7-Nov-03 13:48
memberSwinefeaster7-Nov-03 13:48 
GeneralBreaking the framework. Pin
21-Jan-01 3:38
suss21-Jan-01 3:38 
GeneralRe: Breaking the framework. Pin
Paul Belikian26-Sep-02 14:33
memberPaul Belikian26-Sep-02 14:33 
GeneralRe: Breaking the framework. (I agree) Pin
rj4527-Oct-03 22:39
memberrj4527-Oct-03 22:39 
GeneralAlternative: easier and more robust Pin
17-Jan-01 2:29
suss17-Jan-01 2:29 
GeneralRe: Alternative: easier and more robust Pin
18-Jan-01 10:28
suss18-Jan-01 10:28 
GeneralRe: Alternative: easier and more robust Pin
Gilad Novik12-Jun-01 9:15
memberGilad Novik12-Jun-01 9:15 
Generalgreat idea Pin
17-Jan-01 0:27
suss17-Jan-01 0:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.181207.3 | Last Updated 16 Jan 2001
Article Copyright 2001 by kin
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid