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)
原文:http://www.cnblogs.com/ahcc08/p/6253819.html