工具栏改变背景色

新建dialog对话框程序。在资源视图中添加一个toolbar(代码中为IDR_TOOLBAR_MAIN)),在资源视图中添加一个bmp(代码中为IDB_BITMAP_Toobar_background)图片作为背景.

在.h文件中添加:

private:
    CToolBar    m_toolBar;
    CReBar        m_reBar;

在.cpp文件的OnInitDialog中添加以下代码:

if (m_toolBar.CreateEx(this,TBSTYLE_FLAT | TBSTYLE_TRANSPARENT))
    {
        //m_toolBar.LoadBitmap(m_nIDBitmap);
        //m_toolBar.SetButtons(m_lpaIDToolBar, m_cIDToolBar);
        m_toolBar.LoadToolBar(IDR_TOOLBAR_MAIN);
    }
    m_toolBar.ModifyStyle(0,TBSTYLE_TRANSPARENT);//设置工具栏背景色透明
    m_toolBar.ShowWindow(SW_SHOW);
    m_reBar.Create(this);
    m_reBar.AddBar(&m_toolBar, RGB(255,0,0), RGB(0,255,0),_T(""), RBBS_GRIPPERALWAYS| RBBS_CHILDEDGE);
    m_reBar.RedrawWindow();

    REBARBANDINFO    info;
    CRect            rectToolBar;

    m_toolBar.GetItemRect(0, &rectToolBar);
    ZeroMemory(&info, sizeof(info));
    info.cbSize=sizeof(info);
    info.fMask=RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE|RBBIM_BACKGROUND;
    info.fStyle = RBBS_GRIPPERALWAYS;
    info.cxMinChild = rectToolBar.Width();
    info.cyMinChild = rectToolBar.Height();
    info.cx = info.cxIdeal = rectToolBar.Width() * 10;
    info.hwndChild=(HWND)m_toolBar;
    info.hbmBack = LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP_Toobar_background));//加载位图
    m_reBar.GetReBarCtrl().SetBandInfo(0,&info);

    CRect rcClientStart;
    CRect rcClientNow;

    GetClientRect(rcClientStart);
    //将重绘工具栏和状态栏后剩余的客户区空间放到rcClientNow中
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
        0, reposQuery, rcClientNow);

    // Now move all the controls so they are in the same relative
    // position within the remaining client area as they would be
    // with no control bars.
    CPoint ptOffset(rcClientNow.left - rcClientStart.left,
        rcClientNow.top - rcClientStart.top);

    CRect  rcChild;
    CWnd* pwndChild = GetWindow(GW_CHILD);
    while (pwndChild)
    {
        pwndChild->GetWindowRect(rcChild);
        ScreenToClient(rcChild);
        rcChild.OffsetRect(ptOffset);
        pwndChild->MoveWindow(rcChild, FALSE);
        pwndChild = pwndChild->GetNextWindow();
    }

    // Adjust the dialog window dimensions
    CRect rcWindow;
    GetWindowRect(rcWindow);
    rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
    rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
    MoveWindow(rcWindow, FALSE);

    // And position the control bars
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
 
 
运行程序即可.

转载于:https://www.cnblogs.com/frkang/archive/2013/05/20/3088056.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值