zoukankan      html  css  js  c++  java
  • 工具栏改变背景色

    新建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);
     
     
    运行程序即可.
  • 相关阅读:
    C# 上传图片前判断上传图片的宽和高
    PHP调用WebService
    js判断输入字符串长度(汉字算两个字符,字母数字算一个)
    js 验证电话号 座机及手机号
    C# 微信扫码支付 回调页面
    复制文件夹及文件
    html失去获得焦点
    SQL 大数据查询如何进行优化?
    sql表内存占用情况,并进行缩放
    查询被锁的表
  • 原文地址:https://www.cnblogs.com/frkang/p/3088056.html
Copyright © 2011-2022 走看看