MFC进度条(CProgressCtrl) 重绘


MFC进度条(CProgressCtrl) 重绘

看一张图:

新建一个 继承自 CProgressCtrl 的类,然后添加 OnPaint 消息处理函数,此函数代码如下:

void CNewProgress::OnPaint()
{
    CPaintDC dc(this);
    
    CBrush BackgroundBrush;

    BackgroundBrush.CreateSolidBrush(RGB(255,0,0));    

    CBrush ForeBrush;
    ForeBrush.CreateSolidBrush(RGB(100,255,0));    

    CRect r;
    this->GetClientRect(r);

    double With=r.Width();

    int min,max;
    this->GetRange(min,max);
    
    int pos= this->GetPos();
    double unit=(double)r.Width()/(max-min);

    dc.FillRect(r,&BackgroundBrush);    

    r.right=pos*unit;    

    dc.FillRect(r,&ForeBrush);    
}

 

这样就实现了 CProgressCtrl 重绘。 

如果你想在 进度条中 添加 用鼠标左键单击,然后到指定的位置,这一功能,就要再添加对OnLButtonDown 消息的处理。代码如下:

void CNewProgress::OnLButtonDown(UINT nFlags, CPoint point)
{    
    CRect r;
    this->GetClientRect(r);

    double With=r.Width();

    int min,max;
    this->GetRange(min,max);    
    
    double unit=(double)(max-min)/r.Width(); //

    int pos= point.x*unit;

    this->SetPos(pos);

    CProgressCtrl::OnLButtonDown(nFlags, point);
}

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM