Re: unable to call public function in SDI MainFrame from View
- From: "Joe" <noaddress@xxxxxxxxx>
- Date: Wed, 25 May 2005 19:05:34 GMT
Yes thanks, it was exactly what I needed to know.
The Internet brings out the best and the worst in people, & guys like you,
who take the trouble to help other with no thought of reward, are the best.
"David Topham" <david.topham@xxxxxxxxxxxxx> wrote in message
news:unNf6pTYFHA.2348@xxxxxxxxxxxxxxxxxxxxxxx
> 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?
> >
>
>
.
- References:
- unable to call public function in SDI MainFrame from View
- From: Joe
- Re: unable to call public function in SDI MainFrame from View
- From: David Topham
- unable to call public function in SDI MainFrame from View
- Prev by Date: Re: ascii files + unicode application
- Next by Date: Re: Urgent : Weird PostThreadMessage problem
- Previous by thread: Re: 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
|