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)。】
【译注:Invalidate函数可为窗口指定一个需要更新的区域,即无效矩形。Windows发现有客户区有无效区域的时,它会在应用程序的消息队列中发送一个WM_PAINT消息,窗口过程可以利用这个消息来更新客户区。】