Greless 2017-03-02 03:39 采纳率: 33.3%
浏览 1023
已结题

自绘进度条采用线程循环失败用自带的CprogressCtrl进度条就能循环,怎么回事

自绘进度条Cprogress采用线程循环失败(100后又从新开始),用自带的CprogressCtrl进度条就能循环,怎么回事
/////////////// CProgressDomoDlg.h : 头文件/////////
public:

CProgress m_Progress;
//CProgressCtrl m_Progress;
afx_msg void OnBnClickedButton1();
// UINT MyThread(LPVOID pParam);
};
/////////////// CProgressDomoDlg.cpp //////////
UINT MyThread(LPVOID pParam)//这是线程
{
CCProgressDomoDlg pDlg = (CCProgressDomoDlg)pParam;
CProgress *pPro = &pDlg->m_Progress;//CProgress 自绘进度条
//CProgressCtrl *pPro = &pDlg->m_Progress;

while(1)
{ 
    for (int n = 0; n<100; n++)
    {
        n++;
        pPro->SetPos(n);     
        Sleep(100);
    }
}
return 0;

}
void CCProgressDomoDlg::OnBnClickedButton1()
{
AfxBeginThread(MyThread, (LPVOID)this);

}
//源码
http://download.csdn.net/detail/greless/9768091

图片说明

  • 写回答

3条回答 默认 最新

  • Greless 2017-03-02 07:14
    关注

    自绘代码
    void CProgress::OnPaint()
    {

    CPaintDC dc(this); // 用于绘制的设备上下文
    //CBrush BackgroundBrush;
    //BackgroundBrush.CreateSolidBrush(RGB(255, 255, 0));
    
    CBrush ForeBrush;
    ForeBrush.CreateSolidBrush(RGB(0, 142, 185));
    
    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);
    

    }

    评论

报告相同问题?