-
February 25th, 2014, 09:37 AM
#1
CTabView - CView's HWND is NULL
I'm using the Feature Pack CTabView, and I noticed that when the view is added using AddView with the following code CView's HWND is NULL when I try and access each of the CView1,CView2, etc.
Code:
int CMyTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabView::OnCreate(lpCreateStruct) == -1)
return -1;
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100);
AddView (RUNTIME_CLASS (CView2), _T("Pair"), 101);
AddView (RUNTIME_CLASS (CView3), _T("Data"), 102);
return 0;
}
I think the user has to click the view's tab before the CTabView assigns an HWND. Is there a way to force CTabview to give each CView an HWND when the view is added?
-
February 25th, 2014, 11:09 AM
#2
Re: CTabView - CView's HWND is NULL
I guess the behavior of CTabView::AddView is the same as the one of CPropertySheet::AddPage.
So there is no need to create a window being later shown (after a user selects it or you call CTabView::SetActiveView) before it will be needed to be shown.
Why do you need to have each CView already created when the view is added?
Victor Nijegorodov
-
February 25th, 2014, 12:06 PM
#3
Re: CTabView - CView's HWND is NULL
Originally Posted by VictorN
I guess the behavior of CTabView::AddView is the same as the one of CPropertySheet::AddPage.
So there is no need to create a window being later shown (after a user selects it or you call CTabView::SetActiveView) before it will be needed to be shown.
Why do you need to have each CView already created when the view is added?
I have a clistctrl on the view that I want to update from a database. The database updated the view before it is displayed. So I want the view to have an HWND so I can access its functions.
-
February 25th, 2014, 12:17 PM
#4
Re: CTabView - CView's HWND is NULL
Why not update "a clistctrl n the view" in the CView::OnInitialUpdate override? It is called before the view is displayed.
Victor Nijegorodov
-
February 26th, 2014, 04:43 AM
#5
Re: CTabView - CView's HWND is NULL
According to the code below all views are created immediately inside AddView and later can be accessible via document object:
Code:
int CTabView::AddView(CRuntimeClass* pViewClass, const CString& strViewLabel, int iIndex /*= -1*/, CCreateContext* pContext/* = NULL*/)
{
ASSERT_VALID(this);
ENSURE(pViewClass != NULL);
ENSURE(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CView)));
CView* pView = DYNAMIC_DOWNCAST(CView, pViewClass->CreateObject());
ASSERT_VALID(pView);
if (!pView->Create(NULL, _T(""), WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), &m_wndTabs, (UINT) -1, pContext))
{
TRACE1("CTabView:Failed to create view '%s'\n", pViewClass->m_lpszClassName);
return -1;
}
CDocument* pDoc = GetDocument();
if (pDoc != NULL)
{
ASSERT_VALID(pDoc);
BOOL bFound = FALSE;
for (POSITION pos = pDoc->GetFirstViewPosition(); !bFound && pos != NULL;)
{
if (pDoc->GetNextView(pos) == pView)
{
bFound = TRUE;
}
}
if (!bFound)
{
pDoc->AddView(pView);
}
}
m_wndTabs.InsertTab(pView, strViewLabel, iIndex);
int nTabs = m_wndTabs.GetTabsNum();
return nTabs - 1;
}
Best regards,
Igor
-
February 26th, 2014, 09:05 AM
#6
Re: CTabView - CView's HWND is NULL
Thanks Igor, that makes sense. Where does that code come from?
-
February 26th, 2014, 09:10 AM
#7
Re: CTabView - CView's HWND is NULL
From <your VS folder>\VC\atlmfc\src\mfc\afxtabview.cpp
Victor Nijegorodov
-
February 26th, 2014, 09:17 AM
#8
Re: CTabView - CView's HWND is NULL
Got it, I added the function to my CMyTabView class and now I have the HWND.
Thanks
-
February 26th, 2014, 09:25 AM
#9
Re: CTabView - CView's HWND is NULL
Originally Posted by cbpetro
Got it, I added the function to my CMyTabView class and now I have the HWND.
But which AddView did you call in the CMyTabView::OnCreate() handler?
Victor Nijegorodov
-
February 26th, 2014, 09:45 AM
#10
Re: CTabView - CView's HWND is NULL
Originally Posted by VictorN
But which AddView did you call in the CMyTabView::OnCreate() handler?
The AddView code that Igor provided, I had to change my AddView call from...
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100);
to...
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100 , NULL);
-
February 26th, 2014, 09:55 AM
#11
Re: CTabView - CView's HWND is NULL
Do you have your own AddView method in CMyTabView class?
Otherwise there would be no difference in these two calls
Code:
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100);
and
Code:
AddView (RUNTIME_CLASS (CView1), _T("Simple"), 100 , NULL);
because the forth parameter of CTabView::AddView has default value NULL:
CTabView::AddView
Adds a view to the tab control.
Code:
int AddView(
CRuntimeClass* pViewClass,
const CString& strViewLabel,
int iIndex=-1,
CCreateContext* pContext=NULL
);
Victor Nijegorodov
-
February 26th, 2014, 10:06 AM
#12
Re: CTabView - CView's HWND is NULL
Originally Posted by VictorN
Do you have your own AddView method in CMyTabView class?
Otherwise there would be no difference in these two callsbecause the forth parameter of CTabView::AddView has default value NULL:
Correct, but when I use the default AddView I never have the HWND of each CView, unless I call OnActivateView or something as I am not use the doc/view architecture. If I use the custom AddView, I see the CView being created and I can customize the AddView further by adding each CView to a CSimpleArray in my CMyTabView class.
Now I have access to each CView in CMyTabView from anywhere in my program.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|