Access View Class objects from Mainframe Window Class

Posted on 1999-06-21
Medium Priority
Last Modified: 2013-11-20
How to access View class objects from CMainFrame class?
I my View class is based on CFormView.

Question by:josekv
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Author Comment

ID: 1307528
Edited text of question.
LVL 23

Accepted Solution

naveenkohli earned 400 total points
ID: 1307529
CView *pView = NULL;
CMainFrame *pFrame;

pView = pFrame->GetActiveView ();

Now you canmake calls to access memebrs of your view. Just cast the CView pointer to the view class of your document.

Author Comment

ID: 1307530
Thanks  naveenkohli.

Since I need to access the View objects from my MainFrame
class, is it possible to use the 'this' pointer instead
of the following code?

>>CMainFrame *pFrame;

>>pView = pFrame->GetActiveView ();

Here, how to initialize the *pFrame with  the address of the MainFrame object?

>>pView = pFrame->GetActiveView (); At this point of time
pFrame-> does not contain any valid address.

thanks again...


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 23

Expert Comment

ID: 1307531
You can always get to the active frame of you application.

CWnd *pMainWnd = AfxGetMainWnd ();

CFrameWnd *pFrameWnd = static_cast<CFrameWnd *>(pMainWnd)->GetActiveFrame ();

CView *pView = pFrameWnd->GetActiveView ();

From your frame class you can call GetActiveView. but make sure that the pointer you get back is valid because it may not have been created or is invalid.

Author Comment

ID: 1307532
Thanks Naveen. It works fine.

>>CFrameWnd *pFrameWnd = static_cast<CFrameWnd *>(pMainWnd)->GetActiveFrame ();

In this line I did not understand the construction
"  static_cast<CframeWnd *> " looks similar to a template
definition. What does it actually mean!!!????

I request u to spend couple of miniutes more for me.

Any case I am awarding the points.

Thanks again..

LVL 23

Expert Comment

ID: 1307533
The static_cast operator can be used for operations such as converting a pointer to a base class to a pointer to a derived class.
This is one of the casting operators. SInce pMainWnd is pointer to CWnd, which is base class, therefore we had to cast this pointer to CMainFrame. You could have used the old C style casting like
(CMainFrame *)pMainWnd
But its recommended to choose the new casting operators so that type safety is checked.
I would suggest that you read the documanetation for these new casting operators



Author Comment

ID: 1307534
Very helpful infact.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question