这个crebar用起来参数真奇怪, 算了, 直接上代码吧:
先弄一个基于cdialog的类CMyDlgBar,将基类改为cdialogbar, 需要注意必须修改 constructor(没有参数), OnInitDialog(里面需要初始化)
class
CMyDlgBar :
public
CDialogBar
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
DECLARE_DYNAMIC(CMyDlgBar)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public:
CMyDlgBar(); // standard constructor
virtual ~CMyDlgBar();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// Dialog Data
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
enum
{ IDD = IDD_DIALOG1 };
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
DECLARE_MESSAGE_MAP()
public:
virtual BOOL Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID);
int m_nData;
afx_msg void OnBnClickedOk();
// afx_msg void OnBnClickedButton1();
afx_msg void OnBnClickedButton1();
afx_msg LRESULT OnInitDialog(UINT wParam,LONG lParam);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
afx_msg void OnEnChangeEdit1();
}
;
//
CMyDlgBar dialog
IMPLEMENT_DYNAMIC(CMyDlgBar, CDialogBar)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
CMyDlgBar::CMyDlgBar()
: CDialogBar()
, m_nData(
0
)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
CMyDlgBar::
~
CMyDlgBar()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void
CMyDlgBar::DoDataExchange(CDataExchange
*
pDX)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
CDialogBar::DoDataExchange(pDX);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar)
ON_BN_CLICKED(IDOK,
&
CMyDlgBar::OnBnClickedOk)
//
ON_BN_CLICKED(IDC_BUTTON1, &CMyDlgBar::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON1,
&
CMyDlgBar::OnBnClickedButton1)
ON_EN_CHANGE(IDC_EDIT1,
&
CMyDlgBar::OnEnChangeEdit1)
ON_MESSAGE(WM_INITDIALOG,OnInitDialog)
END_MESSAGE_MAP()
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
LRESULT CMyDlgBar::OnInitDialog(UINT wParam,LONG lParam)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// TODO: Add extra initialization here
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
BOOL bRet = HandleInitDialog(wParam,lParam);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (!UpdateData(FALSE))
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
TRACE("InitCDataStatus Failed!");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return TRUE; // return TRUE unless you set the focus to a control
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// EXCEPTION: OCX Property Pages should return FALSE
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//
CMyDlgBar message handlers
BOOL CMyDlgBar::Create(CWnd
*
pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// TODO: Add your specialized code here and/or call the base class
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
CDialogBar::Create(pParentWnd, nIDTemplate, nStyle, nID);
UpdateData(FALSE);
return TRUE;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void
CMyDlgBar::OnBnClickedOk()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// TODO: Add your control notification handler code here
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//
void CMyDlgBar::OnBnClickedButton1()
//
{
//
//
TODO: Add your control notification handler code here
//
}
void
CMyDlgBar::OnBnClickedButton1()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// TODO: Add your control notification handler code here
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
void
CMyDlgBar::OnEnChangeEdit1()
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialogBar::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
MessageBox(L"Changed");
// TODO: Add your control notification handler code here
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
在cmainframe里面定义两个变量
CMyDlgBar m_barAttrib;
CReBar m_wndReBar;
必须实现oncreate和oncmdmsg
int
CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// TODO: Delete these three lines if you don't want the toolbar to be dockable
if (!m_barAttrib.Create(this,m_barAttrib.IDD, CBRS_ALIGN_RIGHT|CBRS_GRIPPER, m_barAttrib.IDD))
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
TRACE0("Failed to create dialogbar\n");
return -1;
}
m_barAttrib.SetWindowText(L"部件属性");
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*XXX是一个资源id手工直接在资源的.h文件中添加一条,不会,这里就不教了。
工具条的显示和隐藏代码如下,自己慢慢理解吧:*/
// ShowControlBar(&m_barAttrib, (m_barAttrib.GetStyle() & WS_VISIBLE) == 0, FALSE);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//m_wndReBar.Create(this);
m_wndReBar.Create(this, RBS_AUTOSIZE | RBS_BANDBORDERS,
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | */ CBRS_RIGHT) ;
m_wndReBar.AddBar(&m_barAttrib,NULL,NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
//m_wndReBar.AddBar(&m_wndToolBar,NULL,NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
m_barAttrib.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_barAttrib);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::OnCmdMsg(UINT nID,
int
nCode,
void
*
pExtra, AFX_CMDHANDLERINFO
*
pHandlerInfo)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
// TODO: Add your specialized code here and/or call the base class
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if(m_barAttrib.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}