UTTON4, TBSTYLE_BUTTON, 4);
str.LoadString(IDS_ BUTTON4);
m_wndToolBar.SetButtonText(4, str);
m_wndToolBar.SetButtonInfo(5, ID_BUTTON5, TBSTYLE_BUTTON, 5);
str.LoadString(IDS_ BUTTON5);
m_wndToolBar.SetButtonText(5, str);
m_wndToolBar.SetButtonInfo(6, ID_BUTTON6, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN, 6);
str.LoadString(IDS_ BUTTON6);
m_wndToolBar.SetButtonText(6, str);
m_wndToolBar.SetButtonInfo(7, ID_BUTTON7, TBSTYLE_BUTTON, 7);
str.LoadString(IDS_ BUTTON7);
m_wndToolBar.SetButtonText(7, str);
m_wndToolBar.SetButtonInfo(8,ID_BUTTON8, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN, 8);
str.LoadString(IDS_ BUTTON8);
m_wndToolBar.SetButtonText(8, str);
file://重新调整按钮的尺寸
CRect rectToolBar;
m_wndToolBar.GetItemRect(0, &rectToolBar);//得到工具条第一个按钮的尺寸
m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(30,20));
file://第一个参数为按钮尺寸,第二个参数为图像尺寸
file://创建一个组合框作为地址栏
if (!m_wndAddress.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 120), this, AFX_IDW_TOOLBAR + 1))
{
TRACE0("Failed to create combobox\n");
return -1; // fail to create
}
file://加入工具栏、地址栏
m_wndReBar.AddBar(&m_wndToolBar);
str.LoadString(IDS_ADDRESS);
m_wndReBar.AddBar(&m_wndAddress, str, NULL, RBBS_FIXEDBMP | RBBS_BREAK);
file://定义REBARBANDINFO对象,对工具条和地址栏设置理想尺寸
REBARBANDINFO rbbi;
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE;
rbbi.cxMinChild = rectToolBar.Width();
rbbi.cyMinChild = rectToolBar.Height();
rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 9;
m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);//设置工具栏尺寸
rbbi.cxMinChild = 0;
CRect rectAddress;
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE;
m_wndAddress.GetEditCtrl()->GetWindowRect(&rectAddress);
rbbi.cyMinChild = rectAddress.Height() + 10;
rbbi.cxIdeal = 200;
m_wndReBar.GetReBarCtrl().SetBandInfo(2, &rbbi);//设置地址栏尺寸
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
return 0;
}
以上代码在Windows2000和Visual C++环境下编译通过,
程序运行正常,有兴趣的朋友可以动手亲自实验一下。