PAINTSTUCT结构体浅析

关于PAINTSTRUCT结构体的大部分内容来自tang3x(http://blog.csdn.net/tang3x/article/details/6279867)的专栏,我只是在后面加了一些在《Windows程序设计》的内容。

The PAINTSTRUCT structure contains information for an application. This information can be used to paint the client area of a window owned by that application.

 

【PAINTSTRUCT结构包含应用程序的某些信息,这些信息可被应用程序所包含的窗口用来绘制客户区。】

 

typedef struct tagPAINTSTRUCT { 

  HDC  hdc; 

  BOOL fErase; 

  RECT rcPaint; 

  BOOL fRestore; 

  BOOL fIncUpdate; 

  BYTE rgbReserved[32]; 

} PAINTSTRUCT, *PPAINTSTRUCT;

 

Windows fills in the fields of this structure when your program calls BeginPaint. Your program can use only the first three fields. The others are used internally by Windows. The hdc field is the handle to the device context. In a redundancy typical of Windows, the value returned from BeginPaint is also this device context handle. In most cases, fErase will be flagged FALSE (0), meaning that Windows has already erased the background of the invalid rectangle. This happens earlier in the BeginPaint function. (If you want to do some customized background erasing in your window procedure, you can process the WM_ERASEBKGND message.) Windows erases the background using the brush specified in the hbrBackground field of the WNDCLASS structure that you use when registering the window class during WinMain initialization. Many Windows programs specify a white brush for the window background. This is indicated when the program sets up the fields of the window class structure with a statement like this: 

 

【当程序调用BeginPaint时,Windows会为PAINTSTRUCT结构字段进行初始化值。但程序只能使用前3个字段,其他字段由Windows内部使用。hdc字段是设备上下文句柄。在旧版本的Windows中,BeginPaint的返回值同样是这个设备关联句柄。大多数情况下,fErase字段会标志为FALSE(0),意味着Windows已经擦除了无效矩形的背景。这最早在BeginPaint函数中发生。(如果你想在窗口过程中自定义背景擦除动作,可以处理WM_ERASEBKGND消息。)Windows用一个画笔来擦除背景。这个画笔是在WinMain初始化期间,注册窗口类时在WNDCLASS结构的hbrBackground字段指定的。许多程序为窗口背景指定一个白色的笔刷,由以下语句为程序设置窗口类的hbrBackground字段。】

 

wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

 

However, if your program invalidates a rectangle of the client area by calling InvalidateRect, the last argument of the function specifies whether you want the background erased. If this argument is FALSE (that is, 0), Windows will not erase the background and the fErase field of the PAINTSTRUCT structure will be TRUE (nonzero) after you call BeginPaint. 

 

【不过,如果程序调用InvalidateRect函数在客户区中定义一个无效矩形时,函数的最后一个参数可指定是否擦除背景。如果这个参数是FALSE(0),调用BeginPaint函数之后,Windows将不会擦除背景并且PAINTSTRUCT结构的fErase字段会设置为TRUE(nonZero)。】

PAINTSTRUCT结构的rcPaint栏目是RECT型态的结构。RECT结构定义了一个矩形,其四个栏目为left,top,right,bottom.PAINTSTRUCT结构的rcPaint栏目定义了无效矩形的边界,这些值均以像素为单位,并相对于显示区域的左上角,无效矩形是应该重画的区域。

PAINTSTRUCT中的rcPaint矩形不仅是无效矩形,它还是一个【剪取】矩形。这意味着Windows将绘图操作限制在剪取矩形内(更确切地说,如果无效矩形区域不为矩形,则Windows将绘图操作限制在这个区域内)。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值