CClientDC dc(this);
for(int i=0;i<255;i+=20){
CBrush brush(RGB(i,i,i));
CRect rect(100,50,300,150);
dc.FillRect(&rect,&brush);
Sleep(100);
}

解决方案 »

  1.   

    呵呵。为什么要Sleep(100)呢?在这么个循环中,那可是要Sleep很长时间啊。点快了,还没执行完呢。
      

  2.   

    我也认为是sleep的问题,楼主去掉试试,我们编程时候leader是不允许我们用这个的
      

  3.   

    Sleep(100);
    100 * 255 = 25.5秒
      

  4.   

    刷新的问题,修改如下:
    CClientDC dc(this);
    CBrush brush, *pOldbrush;
    CRect rc(100,50,300,150);
    for(int i=0; i<=255;i+=51)
    {
    brush.CreateSolidBrush(RGB(0,i,i));
    dc.FillRect(rc, &brush);
    brush.DeleteObject();
    this->InvalidateRect(rc);
    Sleep(500);
    }
      

  5.   

    在你的循環中調用這個函數便可以解決
    void DoEvents()
    {
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return;
    }