[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

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.


0
josekv
Asked:
josekv
  • 4
  • 3
1 Solution
 
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
 
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
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.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now