CToolBar m_ToolBar;
if(!m_ToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC))
{
return false;
}
CImageList imageList;
imageList.Create(32,32,ILC_COLOR24|ILC_MASK,2,2);
imageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1);
m_ToolBar.GetToolBarCtrl().SetIamgeList(&imageList);
imageList.Detach();
m_ToolBar.SetButtons(NULL,1);
m_ToolBar.SetButtonInfo(0,ID_BUTTON1,TBSTYLE_BUTTON,0);
m_ToolBar.SetButtonText("button",0);
m_ToolBar.SetSizes(CSize(60,60),CSize(32,32));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
其中,SetButtons设置button的数目,button的ID可以在Resource.h中添加,具体的消息处理需要手动添加消息响应。
(vc++)自定义的ToolBar
最新推荐文章于 2024-01-10 19:47:08 发布