自绘进度条采用线程循环失败用自带的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

图片说明

自绘代码
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);

}

1.尝试消息机制也不行
void CLoop::Run(void *ptr)
{
HWND hWnd = (HWND)ptr;
while (true)
{
for ( int i = 0; i<101; ++i)
{
PostMessage(hWnd, WM_USER_MSG, WPARAM(i), LPARAM(0));
Sleep(100);
}
}
}

/////////////////////主程////////////////////////////////////////
void CCProgressDomoDlg::OnBnClickedButton1()
{
_beginthread(&CLoop::Run, 0, this->GetSafeHwnd());
}

LRESULT CCProgressDomoDlg::OnMsg(WPARAM wp, LPARAM lp)
{
CProgress *prog = (CProgress *)GetDlgItem(IDC_PROGRESS1);
prog->SetPos((int)wp);
return 1L;
}

2.直接在主程循环也不行
void CCProgressDomoDlg::OnBnClickedButton1()
{

while (1)
{ for (int n = 0; n<100; n++)
{
n++;
m_Progress.SetPos(n);
Sleep(100);
} }

}
3. 自带的CprogressCtrl进度条就可以无限循环。

我发现不屏蔽背景brush就可以循环,但是我必须让进度条背景透明啊