Print Page | Close Window

how to get the CWnd pointer in a tab control

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=15065
Printed Date: 28 September 2024 at 4:16am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: how to get the CWnd pointer in a tab control
Posted By: rienzi
Subject: how to get the CWnd pointer in a tab control
Date 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



Replies:
Posted By: rienzi
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net