Access View Class objects from Mainframe Window Class

How to access View class objects from CMainFrame class?
I my View class is based on CFormView.


josekvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

josekvAuthor Commented:
Edited text of question.
0
naveenkohliCommented:
CView *pView = NULL;
CMainFrame *pFrame;

pView = pFrame->GetActiveView ();
ASSERT_VALID (pView);

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
josekvAuthor Commented:
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...
Jose.

 


0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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

CWnd *pMainWnd = AfxGetMainWnd ();
ASSERT_VALID (pMainWnd);

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.
0
josekvAuthor Commented:
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..
Jose.

0
naveenkohliCommented:
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

staic_cast
dynamic_cast
const_cast

0
josekvAuthor Commented:
Very helpful infact.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.