Posted on 1999-07-07
Medium Priority
Last Modified: 2013-11-20
if an application is mdi, who is the parent of the view window(either mdichild or mdimainframe). GetParentFrame inside view will give pointer to child or mainframe
Question by:sunraj
  • 2
LVL 23

Accepted Solution

naveenkohli earned 20 total points
ID: 1309211
GetParentFrame will give you the child frame of view. To get to main frame of app, call AfxGetMainWnd and then cast it to CFrameWnd.

CWnd *pWnd = AfxGetMainWnd ();
CFrameWnd *pFrame = static_cast<CFrameWnd *>(pWnd);

Author Comment

ID: 1309212
what does the keyword static_cast mean here...

can you please tell what is static_cast
LVL 23

Expert Comment

ID: 1309213
This is one of the casting operators. Its recommended to use the casting operators. static_cast is not very safe cause it does not do any run time checking for the casting. e.g. in this case we know that pWnd is CFrameWnd type object, so i safely u sed static_cast. The safe one is dynamic_cast. It does the runtime checking to check if the pointer is being casted to right type.
Lets say that i have an pointer to CTreeCtrl and if i try to cast it as CEdit then i am totally screwing up the memory of that object. And if i try to use that pointer , it will Assert...

so the right way is that first i make sure that the pointer is of type to which i am casting ..


if (pWnd->IsKindOf (RUNTIME_CLASS (CEdit)) {
CEdit *pEdit = dynamic_cast<CEdit *>(pWnd);

For more information .. have look at the online documentation for these casting operators. Its way of making sure that we are not doing any illegal pointer castings.

Hope this info helps!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

600 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