如何将CDockablePane拆分为两部分,就像VS2010 IDE中的“类视图”一样? 提前谢谢!
答案 0 :(得分:2)
扩展CSplitterWndEx如下:
class CPaneSplitter : public CSplitterWndEx
{
public :
BOOL AddWindow(int row, int col, CWnd* pWin,CString clsName,
DWORD dwStyle,DWORD dwStyleEx, SIZE sizeInit);
};
将以下成员添加到MyDockablePaneClass
CTreeCtrl m_wndTree
CListCtrl m_wndList
CPaneSplitter wndSplitter
MyDockablePaneClass的OnCreate看起来像这样:
int MyDockablePaneClass::OnCreate(LPCREATESTRUCT lp)
{
if(CDockablePane::OnCreate(lp)==-1)
return -1;
DWORD dwStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT
| TVS_HASBUTTONS |TVS_EDITLABELS;
DWORD dwStyleEx = 0;
m_wndSplitter.CreateStatic(this,2,1);
if(!m_wndSplitter.AddWindow(0,0,&m_wndTree,WC_TREEVIEW,dwStyle,
dwStyleEx,CSize(100,100)))
return -1;
dwStyle = WS_CHILD | WS_VISIBLE | LVS_ICON | LVS_SHAREIMAGELISTS;
dwStyleEx = 0;
if(!m_wndSplitter.AddWindow(1,0,&m_wndList,WC_LISTVIEW,dwStyle
,dwStyleEx,CSize(100,100)))
return -1;
if(!m_toolbar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_REFTREE))
{
TRACE0("Failed to create RefTreePane Toolbar Control\n");
return -1;
}
m_toolbar.LoadToolBar(IDR_REFTREE, 0, 0, TRUE /* Is locked */);
m_toolbar.SetPaneStyle(m_toolbar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
m_toolbar.SetPaneStyle(m_toolbar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
m_toolbar.SetOwner(this);
// All commands will be routed via this control , not via the parent frame:
m_toolbar.SetRouteCommandsViaFrame(FALSE);
return 0;
}
为OnSize添加hendler,如下所示
void MyDockablePaneClass::OnSize(UINT type,int cx,int cy)
{
CDockablePane::OnSize(type, cx, cy);
int cyTlb = m_toolbar.CalcFixedLayout(FALSE, TRUE).cy;
CRect rectClient;
GetClientRect(rectClient);
m_toolbar.SetWindowPos(NULL, rectClient.left, rectClient.top, rectClient.Width()
, cyTlb,SWP_NOACTIVATE | SWP_NOZORDER);
m_wndSplitter.SetRowInfo(0,(cy-cyTlb)/2,25);
m_wndSplitter.SetRowInfo(1,(cy-cyTlb)/2,25);
m_wndSplitter.SetWindowPos(NULL,rectClient.left
, rectClient.top + cyTlb
, rectClient.Width() , rectClient.Height() - cyTlb , SWP_NOZORDER | SWP_NOACTIVATE);
}
注意我在onSize处理程序中为工具栏定位添加处理程序,以防你没有工具栏删除代码并假设cyTlb = 0
祝你好运答案 1 :(得分:0)
Class View似乎是一个CDockablePane,但是分类Class View上下的东西似乎与CDockablePanes没有任何关系,而是分裂器。 我使用从CSplitterWndEx
派生的非常小的类成功完成了这项工作