Re: unable to call public function in SDI MainFrame from View
- From: "David Topham" <david.topham@xxxxxxxxxxxxx>
- Date: Wed, 25 May 2005 16:00:17 +0100
Joe
GetParentFrame returns a poitner to a CFrameWnd, which is the parent class
of your main frame class. To access the function on your derived class, you
will need to cast the pointer to a pointer to your CMainFrame class.
eg:
CMainFrame* pMainFrame = (CMainFrame*)GetParentFrame();
pMainFrame->MyFunction();
Note this is is generally regarded as 'bad' C++, because you are assuming
that you know the derived type of the class pointed to by the CFrameWnd
pointer returned by GetFrameWnd. You may be confident that this will always
be the case in your MFC app. However, it's generally a bad aproach - what
happens if you reuse your view class as part of an MDI app, where the parent
frame will be a ChildFrame? (I'll tell you - your app will crash). A better
way would be:
CMainFrame* pMainFrame = dynamic_cast<CMainFrame*>(GetParentFrame());
if (pMainFrame != NULL)
pMainFrame->MyFunction();
This way you can be sure that you have a pointer to the correct class.
However, it's still not structurally that sound, and is usually (but not
always) an indication your app should be structured differently.
Hope this helps
David
"Joe" <noaddress@xxxxxxxxx> wrote in message
news:oX%ke.501$f4.390@xxxxxxxxxxxxxxxxxxxxxxx
>I manually added a public function to the MainFrame of my SDI. In my View I
> called GetParentFrame() to get a pointer to the Frame. When I tried to
> call
> the function in the Frame from the View, I got compile error C2039:
> 'MyFunctionInFrameClass' : is not a member of 'CFrameWnd'.
>
> What am I doing wrong?
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: How to do that I draw a rectangle with cursor and don't erase the primary word and picture?
- Next by Date: CStringArray pointer problem
- Previous by thread: unable to call public function in SDI MainFrame from View
- Next by thread: Re: unable to call public function in SDI MainFrame from View
- Index(es):
Relevant Pages
|