Re: unable to call public function in SDI MainFrame from View

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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?
> >
>
>

.



Relevant Pages

  • Re: IOCP critical sections and mutexes
    ... mismatch and invalid 'this' pointer). ... instance) and I get pretty much the same crash. ... I mush have done something stupid in my main thread app. ... If I use a mutex instead it works fine. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Trouble with malloc().
    ... >> I am having trouble with malloc() again for a PC app I am developing. ... This is the only warning or error I get. ... not-necessarily-compatible pointer type. ...
    (comp.lang.c)
  • Re: unable to call public function in SDI MainFrame from View
    ... To access the function on your derived class, ... will need to cast the pointer to a pointer to your CMainFrame class. ... be the case in your MFC app. ... frame will be a ChildFrame? ...
    (microsoft.public.vc.mfc)
  • Re: Pointer to Document in MDI application - Problem
    ... Even if you have kept a copy of the pointer to the document in m_pDoc, ... The secret lies in the CDocument member, ... > In my MDI application, a default document is created when the app. ... If I open then close a saved document, ...
    (microsoft.public.vc.mfc)
  • Re: Send key stroke command from one pc to another on the network
    ... someone out there can suggest a pointer for me. ... to get to the PC and either click the mouse or hit the space bar. ... First of all, I think there is an app running on PC 'A', right? ... Application on PC 'B' will now be changed to have a TCP client. ...
    (microsoft.public.dotnet.languages.vb)