• 修改菜单Menu、工具栏ToolBar、状态栏StatusBar的背景色


     

    修改菜单Menu的背景色
    1. 在头文件中声明:HBRUSH m_hMenuBrush;
    2. CMainFrame::OnCreate中添加:

    m_hMenuBrush = CreateSolidBrush(#c8c8c8); // 菜单颜色

    ::MENUINFO lpcmi;

    memset(&lpcmi, 0, sizeof(::LPCMENUINFO));

    lpcmi.cbSize = sizeof(MENUINFO);

    lpcmi.fMask = MIM_APPLYTOSUBMENUS | MIM_BACKGROUND;

    lpcmi.hbrBack = m_hMenuBrush;

    ::SetMenuInfo(GetMenu()->m_hMenu, &lpcmi);

    最后:if (m_hMenuBrush) { DeleteObject(m_hMenuBrush); m_hMenuBrush = NULL; }

     

    修改工具栏Toolbar的背景色:
    1. 取消stdafx.h中的visual style的效果,否则看不到效果
    2. 继承CToolBar,并响应WM_ERASEBKGND,添加以下代码

    // 改变背景色

    CRect ClientRect;

    GetClientRect(ClientRect);

    pDC->FillSolidRect(ClientRect, #6575a9); // #6575a9:修改后的颜色

    return TRUE;

    最后,修改MainFrm.h中的m_wndToolBar为继承后的类对象

    网上关于ReBar的介绍:

    http://blog.csdn.net/yue7603835/article/details/6667581

    http://bbs.csdn.net/topics/340135204

    http://blog.csdn.net/bwmwm/article/details/4734923

    ReBar在2010中未试验成功,在vc6中可以看到效果。

     

    另外,以下两句会使程序中所有Toolbar的背景色都改变:

    HBRUSH newBr = CreateSolidBrush(#6575a9);

    DWORD dwRet = SetClassLongW(m_wndToolBar1.m_hWnd, GCL_HBRBACKGROUND, (long)newBr);

     

    修改状态栏StatusBar的背景色
    1. 取消stdafx.h中的visual style的效果,否则看不到效果
    2. 修改背景色:m_wndStatusBar.GetStatusBarCtrl().SetBkColor(#00005a);
    3. 修改状态栏提示Text的颜色:

    继承CStatusBar类为CColorStatusBar,重载DrawItem

     

    void CColorStatusBar::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct/**/)

    {

        // TODO: Add your code to draw the specified item

     

        // Attach to a CDC object

        CDC dc;

        dc.Attach(lpDrawItemStruct->hDC);

     

        dc.SetBkMode(TRANSPARENT);

     

        // Get the pane rectangle and calculate text coordinates

        CRect rect(&lpDrawItemStruct->rcItem);

     

        if (lpDrawItemStruct->itemID < m_nColumnNum)

        {

            dc.SetTextColor(m_pColor[lpDrawItemStruct->itemID]);

            dc.TextOut(rect.left+2, rect.top, m_pcstrText[lpDrawItemStruct->itemID]);

        }

     

        // Detach from the CDC object, otherwise the hDC will be

        // destroyed when the CDC object goes out of scope

        dc.Detach();

    }

    其中:m_pColorCOLORREF的指针,CColorStatusBar的成员变量,存储状态栏各列的颜色

         m_pcstrTextCString的指针,CColorStatusBar的成员变量,存储状态栏各列的字符

     

    使用CColorStatusBar时,要改变状态栏的提示内容时,需调用m_wndColorStatusBar.GetStatusBarCtrl().SetText(L"", nID, SBT_OWNERDRAW);触发DrawItem函数被调用。

    可参考:http://www.codeproject.com/Articles/2324/Display-colored-text-on-Status-Bar#_rating

      

        4. 修改状态栏右边的缩放区域的背景色,响应WM_PAINT消息

    void CColorStatusBar::OnPaint()

    {

        //CPaintDC dc(this); // device context for painting

        // TODO: Add your message handler code here

        // Do not call CStatusBar::OnPaint() for painting messages

     

        CStatusBar::OnPaint();

     

        CClientDC dc(this); // class CClientDC : public CDC

        if (!GetParent()->IsZoomed()) DrawSizing(&dc);

    }

    void CColorStatusBar::DrawSizing(CDC *pDC)

    {

        CRect rect;

        GetWindowRect(&rect);

        rect.OffsetRect(-rect.left, -rect.top);

     

        if (m_hSizingBkBrush)

        {

            pDC->SelectObject(m_hSizingBkBrush);

            pDC->Rectangle(rect.right-18, rect.bottom-18, rect.right, rect.bottom);

        }

        if (m_hSizingPen)

        {

            pDC->SelectObject(m_hSizingPen);

            pDC->MoveTo(rect.right - 5, rect.bottom);

            pDC->LineTo(rect.right,        rect.bottom - 5);

            pDC->MoveTo(rect.right - 9, rect.bottom);

            pDC->LineTo(rect.right,        rect.bottom - 9);

            pDC->MoveTo(rect.right - 13, rect.bottom);

            pDC->LineTo(rect.right,        rect.bottom - 13);

        }

    }

    其中m_hSizingBkBrushm_hSizingPen均为CcolorStatusBar的成员变量。

     

    可参考:Extended statusbar with bitmap, progress bar and mouse action

              http://www.codeguru.com/cpp/controls/statusbar/article.php/c2969/Extended-statusbar-with-bitmap-progress-bar-and-mouse-action.htm

     

  • 相关阅读:
    idea快捷键
    cas的缺点
    mybatis plus 实现逻辑删除
    mybatis plus的条件查询
    POI写非常大的数据量时
    POI中HSSF和XSSF
    JMM是什么
    Android面试收集录10 LruCache原理解析
    Android面试收集录9 IntentService详解
    Android面试收集录8 HandlerThread详解
  • 原文地址:https://www.cnblogs.com/ant-wjf/p/3416780.html
Copyright © 2020-2023  润新知