Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - how to get the CWnd pointer in a tab control
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

how to get the CWnd pointer in a tab control

 Post Reply Post Reply
Author
Message
rienzi View Drop Down
Groupie
Groupie


Joined: 20 August 2009
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote rienzi Quote  Post ReplyReply Direct Link To This Post Topic: how to get the CWnd pointer in a tab control
    Posted: 28 August 2009 at 5:12am
I'm wondering how to get the CWnd pointer which has been added in a CXTPTabControl object.
I add a CView object to CXTPTabControl as showed in the following codes:


BOOL CProductSysView::AddView(CRuntimeClass* pViewClass, LPCTSTR lpszTitle, int nIcon)
{
     CCreateContext contextT;
     contextT.m_pCurrentDoc     = GetDocument();
     contextT.m_pNewViewClass   = pViewClass;
     contextT.m_pNewDocTemplate = GetDocument()->GetDocTemplate();

     CWnd* pWnd;
     TRY
     {
          pWnd = (CWnd*)pViewClass->CreateObject();
          if (pWnd == NULL)
          {
               AfxThrowMemoryException();
          }
     }
     CATCH_ALL(e)
     {
          TRACE0( "Memory Overflow\n" );
          // Note: DELETE_EXCEPTION(e) not required
          return FALSE;
     }
     END_CATCH_ALL

     DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
     dwStyle &= ~WS_BORDER;

     int nTab = m_wndTabControl.GetItemCount();

     // Create with the right size (wrong position)
     CRect rect(0,0,0,0);
     if (!pWnd->Create(NULL, NULL, dwStyle,
          rect, &m_wndTabControl, (AFX_IDW_PANE_FIRST + nTab), &contextT))
     {
          TRACE0( "warning: Can not create\n" );
          // pWnd will be cleaned up by PostNcDestroy
          return NULL;
     }
     m_wndTabControl.InsertItem(nTab, lpszTitle, pWnd->GetSafeHwnd(), -1/*nIcon*/);    

     pWnd->SetOwner(this);

     return TRUE;

}


m_wndTabControl is a CXTPTabControl type of member variable.
Now the pWnd pointer is a local variable. I want to know how to get its pointer in other functions.


many thanks
Back to Top
rienzi View Drop Down
Groupie
Groupie


Joined: 20 August 2009
Status: Offline
Points: 38
Post Options Post Options   Thanks (0) Thanks(0)   Quote rienzi Quote  Post ReplyReply Direct Link To This Post Posted: 31 August 2009 at 2:11am
OK, I got it from the samples

the following code:

CView* pView = DYNAMIC_DOWNCAST(CView, CWnd::FromHandle(m_wndTabControl.GetSelectedItem()->GetHandle()));
ASSERT_KINDOF(CView, pView);


can get the right CView object pointer

then this post can be terminated
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.137 seconds.