我在OnPaint()中有画线程序。要在其它的函数要调用WM_PAINT消息来更新实现变动线,但不用Invalidate()来更新。我用过直接调用函数OnPaint()但没有效果画的线不更新显示,我又用了SendMessage(WM_PAINT,0,0)来发送消息但还是没法完成画线。
请问怎么做到更新显示画线。(我在OnPaint()中用MessageBox()来确定该函数是否被调用
,结果每次发送消息时都调用OnPaint()函数。但我的画线程序并不显示这是为什么??)

解决方案 »

  1.   

    OnDraw ()
    {
    CClientDC dc(this);
    ...
    }然后在该dc上画就可以了。
      

  2.   

    试试UpdateWindow或者RedrawWindow这两个函数。
    另外在OnPaint中不能加入MessageBox(),否则将是一个死循环...
      

  3.   

    “要在其它的函数要调用WM_PAINT消息来更新实现变动线,但不用Invalidate()来更新。”
    不能这样做,因为OnPaint在创建DC时,把窗口的无效区域作为DC的剪切区域(在调用BeginPaint中完成),如果在无效区域外作图,输出将被DC剪切掉。在EndPaint中,所有的窗口无效区域都被清除。你应该先调用InvalidateRect增加无效区域,在调用UpdateWindow更新窗口,
    尽管UpdateWindow也是直接调用OnPaint,但是自己调用OnPaint是不推崇的。
      

  4.   

    It is an application’s responsibility to check for any necessary internal repainting or updating by looking at its internal data structures for each WM_PAINT message because a WM_PAINT message may have been caused by both an invalid area and a call to the RedrawWindow member function with the RDW_INTERNALPAINT flag set. An internal WM_PAINT message is sent only once by Windows. After an internal WM_PAINT message is sent to a window by the UpdateWindow member function, no further WM_PAINT messages will be sent or posted until the window is invalidated or until the RedrawWindow member function is called again with the RDW_INTERNALPAINT flag set.
      

  5.   

    能不能问问你为什么不用Invalidate()来更新?