CDockablePane 使用

这个是转载的

intm_nshowCurrent;

m_nshowCurrent=theApp.GetProfileInt(_T("Workspace\\Pane-377"),_T("IsFloating"),0); //在构造函数中

首先派生两个子类,源码就不用写出来了,占篇幅,在MainFrm里申明如:
CCurrentDockablePane m_wndCurrentDockablePane;
CHistoryDockablePane m_wndHistoryDockablePane;
CDockablePane* m_pTabbedBar;

然后在OnCreate()里面:
CString strHistoryDockablePane;
CString strCurrentView;
strCurrentView.LoadString(IDS_Current_VIEW);
strHistoryDockablePane.LoadString(IDS_History_VIEW);

if (!m_wndHistoryDockablePane.Create(strHistoryDockablePane, this, CRect(0, 0, 200, 200),
TRUE, ID_VIEW_HistoryDockablePane, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Class View window\n");
return FALSE; // failed to create
}

if (!m_wndCurrentDockablePane.Create(strCurrentView, this, CRect(0, 0, 200, 200),
TRUE, ID_VIEW_CurrentView, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT| CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create File View window\n");
return FALSE; // failed to create
}

再给她们添加图标:
HICON hHistoryDockablePaneIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(),
MAKEINTRESOURCE(bHiColorIcons ? IDI_history : IDI_history), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
m_wndHistoryDockablePane.SetIcon(hHistoryDockablePaneIcon, FALSE);
HICON hCurrentViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(),
MAKEINTRESOURCE(bHiColorIcons ? IDI_Currrently : IDI_Currrently), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
m_wndCurrentDockablePane.SetIcon(hCurrentViewIcon, FALSE);

m_wndHistoryDockablePane.EnableDocking(CBRS_ALIGN_ANY);
m_wndCurrentDockablePane.EnableDocking(CBRS_ALIGN_ANY);

DockPane(&m_wndHistoryDockablePane);
DockPane(&m_wndCurrentDockablePane);
m_pTabbedBar = NULL;

m_wndCurrentDockablePane.AttachToTabWnd(&m_wndHistoryDockablePane, DM_SHOW, FALSE, &m_pTabbedBar);

相关显示代码就这样的了.后来老大说关闭需要修改工具栏里的显示状态,即去掉对勾.在工具栏里控制他们的显示和隐藏简单啊,就是用m_wndCurrentDockablePane.ShowPane(TRUE,FALSE,TRUE);可是关闭再去修改工具栏想了半天,以为要重载CDockablePane的Close()消息,又尝试了他的很多消息,都不对.跟踪进去才知道是调用MainFrm来关闭的.里面有pMainfrm.onCloseDockingPane(this);好了,我就重载这个方法.

BOOL CMainFrame::OnCloseDockingPane( CDockablePane* pWnd )
{
CWnd * pfWnd = pWnd->GetFocus();
if (*pfWnd == m_wndCurrentDockablePane)
{
m_nshowCurrent = 0;
}
else if(*pfWnd == m_wndHistoryDockablePane)
{
m_nshowHistory = 0;
}
return TRUE;
}
这样工具栏里面的信息就更新了.呵呵,高兴的太早了,才做了一半,当两个面板拆开,即处于浮动状态时关闭根本就不调用这里.又郁闷了半天,还是老大牛逼,说那种情况是OnCloseMiniFrame,于是有如下重载:

BOOL CMainFrame::OnCloseMiniFrame( CPaneFrameWnd* pWnd )
{
CWnd *ptWnd = pWnd->GetWindow( GW_CHILD );
if (*ptWnd ==m_wndCurrentDockablePane)
{
m_nshowCurrent = 0;
}
else if (*ptWnd == m_wndHistoryDockablePane)
{
m_nshowHistory = 0;
}
return TRUE;
}

//写注册表,在析构函数中

theApp.WriteProfileInt(_T("Workspace\\Pane-377"),_T("IsFloating"),m_nshowCurrent);

你可能感兴趣的:(ANE)