void CMyDialog::OnPaint()
{
 CWnd *pWnd=GetDlgItem(IDC_STATIC1);
 CDC  *pControlDC=GetDC(pWnd);
 pWnd->Invalidate();
 pWnd->UpdateWindow();
 pControlDC->SelectStockObject(BLACK_BRUSH);
 pControlDC->Rectangle(0,0,10,10);
 pWnd->ReleaseDC(pControlDC);
}
说明:
既要在控件窗口内绘图,又要防止windows
对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。
问:对于Invalidate函数
Windows sends a WM_PAINT message whenever the CWnd update region is not empty 
and there are no other messages in the application queue for that window.
而UpdateWindow函数
The UpdateWindow member function sends a WM_PAINT message directly, bypassing 
the application queue. 
是不是总共发送了两个WM_PAINT,还有是不是Invalidate/UpdateWindow调用后,当调用
pControlDC->SelectStockObject(BLACK_BRUSH);
 pControlDC->Rectangle(0,0,10,10);
 pWnd->ReleaseDC(pControlDC);IDC_STATIC1控件窗口虽然发生变化,也不发送WM_PAINT

解决方案 »

  1.   

    大概paint是绘制了窗口,而update才刷新
    原来的sdk编程,createwindow后updatewindow窗口才显示出来
      

  2.   

    楼上的,updatewindow后面还有画图呢?]
      

  3.   

    You problem was once part of my problem. As you know, Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.But the UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. It means that the client area is redrawn by OnDraw() right after the UpdateWindow() is called, otherwise, Invalidate() do not sent WM_PAINT, but set invalidate area. Then the system will know you want to redraw your window. But it have to wait till all the other things which came before your redraw command have been done. Than it will redraw the window for you. In another word, if you are hungry, UpdateWindow() directly give you a helping of bread, but Invalidate() tell you where is the bakery. In this way, you may have been starved to death before you get there.
      

  4.   

    1、InvalidateRect只标记无效矩形,不发送WM_PAINT消息。(Invalidate将整个客户区标记为无效)
    2、UpdateWindow/RedrawWindow负责发送WM_PAINT消息。UpdateWindow在无效矩形为空时不发送WM_PAINT消息。
    3、在窗口内绘图只需获得其窗口的设备环境(DC),通过它来向窗口客户区绘图。from msdn:
    The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function. CWnd::Invalidate
    Invalidates the entire client area of CWnd.UpdateWindow
    The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent。因此,
     CWnd *pWnd=GetDlgItem(IDC_STATIC1);
     CDC  *pControlDC=GetDC(pWnd);
     pWnd->Invalidate();             // 标记控件窗口无效矩形
     pWnd->UpdateWindow();           // 发送WM_PAINT消息
     pControlDC->SelectStockObject(BLACK_BRUSH);
     pControlDC->Rectangle(0,0,10,10);
     pWnd->ReleaseDC(pControlDC);
      

  5.   

    同意楼上的
    RedrawWindow 
    = Invalidate + 
    UpdateWindow
      

  6.   

    看看原代码就清楚了。实际上Invalidate()函数中就包含了UpdateWindow
    的调用。而UpdateWindow才是发出WM_PAINT的函数
      

  7.   

    谢谢!下面这句话我不太了解,还有他们在上面的程序的作用?
    既要在控件窗口内绘图,又要防止windows
    对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。
      

  8.   

    repeat:
    谢谢!下面这句话我不太了解,还有他们在上面的程序的作用?
    既要在控件窗口内绘图,又要防止windows
    对它进行重复绘制。可利用Invalidate/UpdateWindow调用来实现。