I want to capture workspace in mainframe
The notification message tvn_selchanged for the tree control on the bar class, But it is strange that it cannot work, but it does work in a non-BCG project.
The Code is as follows:
**********************************************************************
// WorkspaceBar.cpp : implementation of the CWorkspaceBar class
//
BEGIN_MESSAGE_MAP(CWorkspaceBar, CBCGSizingControlBar)
//{{AFX_MSG_MAP(CWorkspaceBar)
ON_WM_CREATE()
ON_WM_SIZE()
ON_NOTIFY(TVN_SELCHANGED, 1, OnSelectTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CWorkspaceBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
....
// Create tabs window:
if (!m_wndTabs.Create (CBCGTabWnd::STYLE_3D, rectDummy, this, 1))
{
TRACE0("Failed to create workspace tab window
");
return -1; // fail to create
}
m_wndTabs.SetImageList (IDB_WORKSPACE, 16, RGB (255, 0, 255));
// Create tree windows.
// TODO: create your own tab windows here:
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES
|
TVS_LINESATROOT | TVS_HASBUTTONS;
if (!m_wndTree1.Create (dwViewStyle, rectDummy, &m_wndTabs, 2) ||
!m_wndTree2.Create (dwViewStyle, rectDummy, &m_wndTabs, 3))
{
TRACE0("Failed to create workspace view
");
return -1; // fail to create
}
...
}
void CWorkspaceBar::OnSelectTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
*pResult = 0;
}
**********************************************************************
// WorkspaceBar.h : interface of the CWorkspaceBar class
//
// Generated message map functions
protected:
//{{AFX_MSG(CWorkspaceBar)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnSelectTree(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
On the BCG website, I saw a solution, that is, you inherit a tree control class from ctreectrl and process messages in the new class.
I don't want to do this. So I searched for the root cause of the problem. I found that the cbcgtabwnd class of BCG intercepted the onnotify message, causing mainframe to fail to be captured.
The solution is as follows:
1. inherit a class from cbcgtabwnd.
2. Implement the onnotify virtual function in the class.
BOOL CMyTabCtrl::OnNotify (WPARAM wParam, LPARAM lParam, LRESULT* pResult){
ASSERT_VALID (this);
BOOL bRes = CBCGTabWnd::OnNotify (wParam, lParam, pResult);
NMHDR* pNMHDR = (NMHDR*)lParam; ASSERT (pNMHDR != NULL);
if (pNMHDR->code == TTN_SHOW && !m_bFlat) { m_ToolTip.SetWindowPos (&wndTop,
-1, -1, -1, -1, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSIZE); }
if (pNMHDR->code == HDN_ITEMCHANGED) { SynchronizeScrollBar ();
}
if (wParam > 0) {
CWnd* pChild = GetDlgItem(wParam);
if (pChild)
{
if (IsChild(pChild))
{
GetOwner()->SendMessage(WM_NOTIFY,wParam,lParam);
}
}
}
return bRes;
}
3. In the oncreate method of the cworkspacebar class, make sure that you change the cbcgtabwnd class to your own class.
4. Implement the notification messages you want to capture in the cworkspacebar class.
ON_NOTIFY(NM_DBLCLK,ID_LIST,OnListDblClk)...void
CWorkspaceBar::OnListDblClk(NMHDR* pNMHDR, LRESULT* pResult) { ... *pResult
= 0;}