[英]Docking CDialogBar Horizontally with CToolbar
我需要水平顯示CToolbar(m_wndToolBar)和CDialogBar(m_wndDlgBarSid1)(即彼此相鄰,而不是彼此上方)。 父幀是從CMDIFrameWnd派生的。
我嘗試了各種變體來使其正常工作。 盡管我可以將CDialogBar正確地定位在CToolbar的右側,但是盡管WINDOWPLACEMENT機制運行正常(注冊表是在程序出口寫的),但我無法保持定位。 每當運行程序時,CToolbar都將顯示在停靠的左側,而CDialogBar會在它下方顯示,也停靠的左側。 我正在使用(強制)MFC和Visual C ++ 6.0。 這是代碼,略作編輯以刪除調試打印輸出等:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
{
return -1;
}
if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME) )
{
return -1; // fail to create
}
if (!m_wndDlgBarSid1.Create(this, IDD_DIALOGBAR_SID1, CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
{
return -1; // fail to create
}
WINDOWPLACEMENT wp ;
CString sSection = "DialogBarSettings";
CString sEntry = "Sid1";
if ( ReadWindowPlacement( &wp, sSection, sEntry ))
{
BOOL bSWP = m_wndDlgBarSid1.SetWindowPlacement( &wp );
RecalcLayout();
}
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.GetToolBarCtrl().ModifyStyle( 0, TBSTYLE_FLAT, 0 ) ;
m_wndDlgBarSid1.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY ) ;
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
m_wndDlgBarSid1.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
DockControlBar(&m_wndDlgBarSid1,AFX_IDW_DOCKBAR_TOP);
return 0;
}
有什么想法嗎?
返回零之前,將此代碼粘貼到下面的代碼中。 這將加載先前保存的對接狀態。
CDockState dockState;
dockState.LoadState(L"CTRLBARSDOCKSTATE.INI");
SetDockState(dockState);
RecalcLayout();
要在關閉窗口時保存當前的停靠狀態,請將以下代碼粘貼到CMainFrame :: OnClose()覆蓋中。
CDockState dockState;
GetDockState(dockState);
dockState.SaveState(L"CTRLBARSDOCKSTATE.INI");//File name can be of your choice
使用CReBar結束工作,這非常接近我的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.