Click here to Skip to main content
Licence 
First Posted 15 Jan 2001
Views 97,160
Bookmarked 24 times

CView Access From Anywhere

By | 15 Jan 2001 | Article
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

About the Author

kin



Europe Europe

Member

no need for this information at this moment

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneraltheApp Instead of AfxGetApp() PinmemberJusef Marzbany9:01 26 Feb '09  
GeneralFor another View in MDI PinmemberIbrahim Hamoud13:14 22 Jul '03  
GeneralRe: For another View in MDI Pinmemberrj4521:41 27 Oct '03  
GeneralOrder of includes is important! PinmemberSlawa4:26 19 May '03  
GeneralRe: Order of includes is important! PinmemberSlawa5:29 19 May '03  
GeneralAnother possibility... PinmemberBrendan Tregear15:49 30 Jan '01  
GeneralRe: Another possibility... Pinmembereric kaminski10:50 11 Nov '02  
QuestionWhy? PinmemberAlexMarbus12:10 22 Jan '01  
AnswerRe: Why? Pinmemberdswigger9:19 28 Jul '01  
GeneralRe: Why? PinmemberSwinefeaster12:48 7 Nov '03  
GeneralBreaking the framework. PinmemberAnonymous2:38 21 Jan '01  
GeneralRe: Breaking the framework. PinmemberPaul Belikian13:33 26 Sep '02  
GeneralRe: Breaking the framework. (I agree) Pinmemberrj4521:39 27 Oct '03  
GeneralAlternative: easier and more robust PinmemberCraig Henderson1:29 17 Jan '01  
GeneralRe: Alternative: easier and more robust PinmemberAnonymous9:28 18 Jan '01  
GeneralRe: Alternative: easier and more robust PinmemberGilad Novik8:15 12 Jun '01  
Generalgreat idea PinmemberAnonymous23:27 16 Jan '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 16 Jan 2001
Article Copyright 2001 by kin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid