初学我windows编程,有一个问题,为什么要在窗口过程中定义PAINTSTRUCT结构体和RECT结构体,定义其中一个不行吗?他们两个有什么区别?谢谢!

解决方案 »

  1.   

    typedef struct tagPAINTSTRUCT {
       HDC hdc;
       BOOL fErase;
       RECT rcPaint;
       BOOL fRestore;
       BOOL fIncUpdate;
       BYTE rgbReserved[16];
    } PAINTSTRUCT;
    PAINTSTRUCT可以获得设备上下文的句柄,以及请求绘图区域和重绘背景。通过BeginPaint(hwnd,&ps)设置其实例
    而RECT仅仅是定义了客户绘图区域而已,通过GetClientRect(hwnd,&rect)设置实例。
      

  2.   

    RECT 与 PAINTSTRUCT中的RECT并不能等同,后者仅指出paint的区域。
      

  3.   

    typedef struct tagPAINTSTRUCT { 
      HDC  hdc; 
      BOOL fErase; 
      RECT rcPaint; 
      BOOL fRestore; 
      BOOL fIncUpdate; 
      BYTE rgbReserved[32]; 
    } PAINTSTRUCT, *PPAINTSTRUCT; 
    rcPaint 的msdn解释:
    Specifies a RECT structure that specifies the upper left and lower right corners of the rectangle in which the painting is requested, in device units relative to the upper-left corner of the client area. 
     大概中文意思:rcPaint为需要重新绘制的客户区矩形。
      

  4.   

    谢谢,那是不是PAINTSTRUCT 与WM_PAINT消息有关?而RECT 结构与WM_PAINT消息无关呢?