由ClassWiazrd创建的缺省的工具条是在MainFrame中声明并初始化的。
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
如果需要自己来创建自己定义的工具条,可以这样做:
首先,在资源文件中创建工具条资源,并给其命名一个ID号,这里命名为IDR_COLOR_BAR
然后在MainFrame中声明一个CToolBar类型的变量
CToolBar m_wndColorBar;
接下来在MainFrame中定义它
//创建工具条对象并加载工具条资源
if(!m_wndColorBar.Create(this) || !m_wndColorBar.LoadToolBar(IDR_COLOR_BAR))
{
TRACE("Failed to create toolbar\n");
return -1;
}
//设置工具条样式
m_wndColorBar.SetBarStyle(m_wndColorBar.GetBarStyle() | CBRS_TOOLTIPS
| CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
//使能工具条的Dock特性
m_wndColorBar.EnableDocking(CBRS_ALIGN_ANY);
//Dock工具条
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndColorBar);