首页 > 编程语言 > 详细

MFC 滑动条的重绘

时间:2017-01-05 21:41:42      阅读:407      评论:0      收藏:0      [点我收藏+]

MFC自带的滑动条的样子是这样的。

技术分享

比较难看,所以需要重绘下,重绘后的样子是这样的。

技术分享

代码如下:

CustomSliderCtr.h

#pragma once


// CCustomSliderCtr

class CCustomSliderCtr : public CSliderCtrl
{
    DECLARE_DYNAMIC(CCustomSliderCtr)

public:
    CCustomSliderCtr();
    virtual ~CCustomSliderCtr();

protected:
    afx_msg void OnPaint();
    void CustDraw(CDC *pDc);
    DECLARE_MESSAGE_MAP()
};

CustomSliderCtr.cpp

// CustomSliderCtr.cpp : 实现文件
//

#include "stdafx.h"
#include "CustomSliderCtr.h"


// CCustomSliderCtr

IMPLEMENT_DYNAMIC(CCustomSliderCtr, CSliderCtrl)

CCustomSliderCtr::CCustomSliderCtr()
{

}

CCustomSliderCtr::~CCustomSliderCtr()
{
}


BEGIN_MESSAGE_MAP(CCustomSliderCtr, CSliderCtrl)
    ON_WM_PAINT()
END_MESSAGE_MAP()



// CCustomSliderCtr 消息处理程序

void CCustomSliderCtr::OnPaint()
{
    CPaintDC dc(this);
    CustDraw(&dc);
    CSliderCtrl::OnPaint();
}

void CCustomSliderCtr::CustDraw(CDC *pDc)
{

    COLORREF colorLeft(SLIDER_LEFT_COLOR);

    COLORREF colorChannel(SlIDER_BK_COLOR);
    CPen penChannel(PS_DASHDOTDOT, 2, colorChannel);
    CBrush brushChannel;
    brushChannel.CreateSolidBrush(colorChannel);

    COLORREF colorThumb(SLIDER_THUMB_COLOR);
    CPen penThumb(PS_DASHDOTDOT, 2, colorThumb);
    CBrush brushThumb;
    brushThumb.CreateSolidBrush(colorThumb);


    CRect clientRect;
    GetClientRect(clientRect);

    //clientRect.bottom /= 2; 

    pDc->SetBkMode(TRANSPARENT);

    pDc->FillSolidRect(clientRect, colorChannel);

    pDc->Draw3dRect(clientRect, colorChannel,colorChannel);

    CRect thumbRect;
    GetThumbRect(thumbRect);
    
    thumbRect.bottom *= 2;

    CRect leftRect;
    leftRect.left = clientRect.left;
    leftRect.top = clientRect.top;
    leftRect.bottom = clientRect.bottom;
    leftRect.right = thumbRect.left;

    
    pDc->SelectObject(&brushThumb);
    pDc->SelectObject(&penThumb);

    pDc->FillSolidRect(leftRect, colorLeft);

    pDc->Draw3dRect(leftRect, colorLeft, colorLeft);

    pDc->Ellipse(thumbRect);
}

 其中颜色定义

#define SlIDER_BK_COLOR RGB(192, 192, 192)
#define SLIDER_LEFT_COLOR RGB(148, 40, 255)
#define SLIDER_THUMB_COLOR RGB(240, 240, 240)

 

MFC 滑动条的重绘

原文:http://www.cnblogs.com/ahcc08/p/6253819.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!