tags:

views:

345

answers:

1

I am trying to access a view inside a splitter from my mainframe. At the moment I have this:

CWnd* pView = m_wndSplitter.GetPane( 0, 0 );

However this gets me a pointer to the CWnd not the CMyViewClass object.

Can anyone explain to me what I need to do in order to access the view object itself so I can access member functions in the form pView->ViewFunction(...);

+3  A: 

Just cast it:

// using MFC's dynamic cast macro
CMyViewClass* pMyView = 
   DYNAMIC_DOWNCAST(CMyViewClass, m_wndSplitter.GetPane(0,0));
if ( NULL != pMyView )
   // whatever you want to do with it...

or:

// standard C++ 
CMyViewClass* pMyView = 
   dynamic_cast<CMyViewClass*>(m_wndSplitter.GetPane(0,0));
if ( NULL != pMyView )
   // whatever you want to do with it...

If you know that the view in pane 0,0 will always be of type CMyViewClass, then you could just use static_cast... but i recommend you don't - no sense risking problems should you ever change your layout.

Shog9