一个窗口过程中有如下代码:
     case WM_PAINT :
          hdc = BeginPaint (hwnd, &ps) ;
  
          SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
          SetBkMode (hdc, TRANSPARENT) ;
          
          TextOut (hdc, 24 * cxChar, cyChar, szTop, lstrlen (szTop)) ;
          TextOut (hdc, 24 * cxChar, cyChar, szUnd, lstrlen (szUnd)) ;          EndPaint (hwnd, &ps) ;          return 0 ;
          
     case WM_DRAWITEM :
     case WM_COMMAND :
          ScrollWindow (hwnd, 0, -cyChar, &rect, &rect) ;
          
          hdc = GetDC (hwnd) ;
          SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
          
          TextOut (hdc, 24 * cxChar, cyChar * (rect.bottom / cyChar - 1),
                   szBuffer,
                   wsprintf (szBuffer, szFormat,
                         message == WM_DRAWITEM ? TEXT ("WM_DRAWITEM") : 
                                                  TEXT ("WM_COMMAND"),
                         HIWORD (wParam), LOWORD (wParam),
                         HIWORD (lParam), LOWORD (lParam))) ;
          
          ReleaseDC (hwnd, hdc) ;
          ValidateRect (hwnd, &rect) ;   //此句话的目的是不让触发该窗口的//WM_PAINT消息,可为什么跟踪的结果是"仍然会触发WM_PAINT消息".
          break ;

解决方案 »

  1.   

    ValidateRect (hwnd, &rect)The ValidateRect function validates the client area within a rectangle by removing the rectangle from the update region of the specified window.
      

  2.   

    ValidateRect是要触发WM_PAINT消息,但不会全部重画。
      

  3.   

    再问一个问题。
    BOOL ScrollWindow(
      HWND hWnd,    // handle to window to scroll
      int XAmount,  // amount of horizontal scrolling
      int YAmount,  // amount of vertical scrolling
      CONST RECT *lpRect,
                    // address of structure with scroll rectangle
      CONST RECT *lpClipRect 
                    // address of structure with clip rectangle
    );Res:
    The area uncovered by ScrollWindow is not repainted, but it is combined into the window's update region. 
    The application eventually receives a WM_PAINT message notifying it that the region must be repainted. 
    To repaint the uncovered area at the same time the scrolling is in action, call the UpdateWindow function immediately after calling ScrollWindow. 
    /////////////////////////////The area uncovered by ScrollWindow is not repainted ,but it is combined into the window's update region.The application eventually receives a WM_PAINT message notifying it that the region must be repainted. 
    译:“没有被覆盖的区域”不会被重绘 ,但是它会被算在update区域中  。最终WM_PAINT消息会通知应用程序这块区域必须被重绘。先说“没有被覆盖的区域”不会被重绘,后来又说会在WM_PAINT消息事件中被重绘,到底这块“没被覆盖的区域”会不会被重绘啊?
      

  4.   

    To repaint the uncovered area at the same time the scrolling is in action, call the UpdateWindow function immediately after calling ScrollWindow. 
    _____________________
    这句话有助理解哦。SCROLLING的时候WINDOWS就在不停的画需要滚动的区域,然后滚动结束之后的某个时候,窗口接到一个WM_PAINT消息,这时候就会重新全部重绘。如果你想(上面的英文)
      

  5.   

    就是“没有被覆盖的区域”的区域暂时不重绘,但把他合并在窗口需要重绘的区域中了,如果有WM_PAINT事件这块区域就和窗口需要重绘的区域一起重绘了。
      

  6.   

    好象稍微有点头绪了:)
    再问一下其中的一个参数
    lpClipRect 
    Pointer to the RECT structure containing the coordinates of the clipping rectangle. Only device bits within the clipping rectangle are affected. Bits scrolled from the outside of the rectangle to the inside are painted; bits scrolled from the inside of the rectangle to the outside are not painted. ////
    请问以上所说的clipping rectangle是指哪块?
      

  7.   

    没看见Rigel(猎户座-参宿七) 的回复,修订一下:
    就是“没有被覆盖的区域”的区域暂时不重绘,但把他合并在窗口需要重绘的区域中了,”如果“有WM_PAINT事件这块区域就和窗口需要重绘的区域一起重绘了
    ///////////////////////////////////
    根据msdn不应该是“如果”吧。好象ScrollWindow最宗还是要触发WM_PAINT事件。。
      

  8.   

    根据msdn不应该是“如果”吧。好象ScrollWindow最宗还是要触发WM_PAINT事件。。
    __________
    理解没错。你是南方人。
      

  9.   

    不是丫...
    我是说 everandforever怎么会知道你是南方人的?你真是南方的?哪的?
      

  10.   

    是说 everandforever怎么会知道你是南方人的?
    //////////////////////////////////////
    刀哥:
    这次该论到我来做你老师了..
    仔细看看下面的话就知道了...
    /////////////////////////////////////////////////////////
    根据msdn不应该是“如果”吧。好象ScrollWindow最宗还是要触发WM_PAINT事件。。