Re: handling control notifications in different window than parent
Hello, thanks for reading!
I have a class QElemsView (derived from CFrameWnd) which serves as a
container. In this class I used to create the CTreeCtrl object. QElemsView
contained the business logic and handled notifications from the tree.
Then I had to add a splitter into the QElemsView. I could not add the tree
into it directly (as before). I had to add additional object CHolderView
which serves as an envelope for the tree. I think the code will explain the
situation better than words. The problem is, that the tree must have an ID
(like IDC_LIST_GROUPS):
inside QElemsView::OnCreateClient:
if (!m_wndSplitter.CreateStatic(this, 2, 1))
{
TRACE0("Failed to create splitter window\n");
return FALSE;
}
m_wndSplitter.CreateView(0,0, RUNTIME_CLASS(CHolderView), CSize(100,100),
pContext);
m_wndSplitter.CreateView(1,0, RUNTIME_CLASS(CHolderView), CSize(100,100),
pContext);
//envelope
CHolderView* pView = (CHolderView*)m_wndSplitter.GetPane(0, 0);
pView->setWnd(&m_groupsCtrl);
pView->setOwner(this);
if (!m_groupsCtrl.CreateEx(WS_EX_CLIENTEDGE,
NULL,
NULL,
WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT,
// WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_HASLINES,
CRect(0,0,0,0),
pView,
IDC_LIST_GROUPS,
NULL))
{
TRACE0("Failed to create tree list box 1\n");
return -1;
}
The solution I am playing with is adding a method into CHolderView which
handles the notifications and relays them onto the owner:
BOOL CHolderView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT *Result)
{
*Result = m_owner->SendMessage(WM_NOTIFY, wParam, lParam);//
OnNotify(wParam, lParam, Result);
return TRUE;
}