MFC动态生成工具栏

MFC动态生成工具栏


//头文件定义,状态栏等其他窗口略
CToolBar    m_wndToolBar;

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
   | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
{
   TRACE0("Failed to create toolbar\n");
   return -1;      // fail to create
}


//创建状态栏
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
}

//
//动态生成工具栏按钮
CToolBarCtrl &toolBarCtrl=m_wndToolBar.GetToolBarCtrl();
CBitmap bitMap[6];
TBBUTTON tbButton[6] = {0};
m_ImageList.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 0);

bitMap[0].LoadBitmap(IDB_BITMAP1);
m_ImageList.Add(&bitMap[0],&bitMap[0]);
bitMap[1].LoadBitmap(IDB_BITMAP2);
m_ImageList.Add(&bitMap[1],&bitMap[1]);
bitMap[2].LoadBitmap(IDB_BITMAP3);
m_ImageList.Add(&bitMap[2],&bitMap[2]);
bitMap[3].LoadBitmap(IDB_BITMAP4);
m_ImageList.Add(&bitMap[3],RGB(0,0,255));
bitMap[4].LoadBitmap(IDB_BITMAP5);
m_ImageList.Add(&bitMap[4],RGB(0,0,255));
bitMap[5].LoadBitmap(IDB_BITMAP6);
m_ImageList.Add(&bitMap[5],RGB(0,0,255));
toolBarCtrl.SetImageList(&m_ImageList);
for(int i=0; i< 6; i++)
{
   tbButton[i].dwData   = NULL;
   tbButton[i].fsState   = TBSTATE_ENABLED;
   tbButton[i].fsStyle   = (BYTE)TBSTYLE_FLAT;
   tbButton[i].iBitmap   = i;
 
}
tbButton[0].idCommand = ID_EDIT_FIND;
tbButton[1].idCommand = ID_EDIT_FIND;
tbButton[2].idCommand = ID_EDIT_FIND;
tbButton[3].idCommand = ID_EDIT_FIND;
tbButton[4].idCommand = ID_EDIT_FIND;
//tbButton[5].idCommand = ID_APP_ABOUT;
toolBarCtrl.AddButtons(6, tbButton);
toolBarCtrl.AutoSize();
toolBarCtrl.SetStyle(TBSTYLE_FLAT | CCS_TOP);

//
//我的控制窗口
if (!m_wndMyBar1.Create(_T("我的控制条"),this,123))
{
   TRACE0("Failed to create mybar\n"); return -1;
}
if (!m_wndMyBar2.Create(_T("我的控制条2"),this,CSize(100,100),TRUE,124))
{
   TRACE0("Failed to create mybar\n"); return -1;
}
if (!m_wndMyBar3.Create(_T("我的控制条3"),this,CSize(100,100),TRUE,124))
{
   TRACE0("Failed to create mybar\n"); return -1;
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable

//
//停靠控制//
m_wndMyBar1.SetBarStyle(m_wndMyBar1.GetBarStyle() |
   CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndMyBar2.SetBarStyle(m_wndMyBar2.GetBarStyle() |
   CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndMyBar3.SetBarStyle(m_wndMyBar2.GetBarStyle() |
   CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndToolBar.EnableDocking(0);
m_wndMyBar1.EnableDocking(CBRS_ALIGN_ANY);
m_wndMyBar2.EnableDocking(0);
m_wndMyBar3.EnableDocking(0);
EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);
DockControlBar(&m_wndMyBar1, AFX_IDW_DOCKBAR_LEFT);

CRect nRect;
GetWindowRect(&nRect);
CPoint point(nRect.right,nRect.top);
point.y+=80;
point.x-=200;

//使工具栏窗口浮动
FloatControlBar(&m_wndMyBar2,point);
point.y+=200;
FloatControlBar(&m_wndMyBar3,point);
//m_wndMyBar2.MoveWindow(0,0,400,TRUE);
point.x-=500;
FloatControlBar(&m_wndToolBar,point);
m_wndToolBar.MoveWindow(0,0,400,TRUE);   //解决添加工具栏按钮事件可能无法显示工具按钮

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值