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