BeginPaint和EndPaint处理WM_PAINT

来源:互联网 发布:火箭回收知乎 编辑:程序博客网 时间:2024/05/29 03:17

The HDC data type is defined as a 32-bit unsigned integer. The program may then use GDI functions, such as TextOut, that require the handle to the device context. A call to EndPaint releases the device context handle.

 

【HDC被定义为一个32位无符号整数。程序可能会使用GDI函数,例如TextOut,需要一个设备上下文(注:此前翻译为设备内容,发现欠妥,在此纠正)句柄。调用EndPaint函数可释放HDC。】

 

Typically, processing of the WM_PAINT message looks like this:

 

【通常,可以像这样处理WM_PAINT消息:】

 

case WM_PAINT:

hdc = BeginPaint (hwnd, &ps) ;

[use GDI functions]

EndPaint (hwnd, &ps) ;

return 0 ;

 

@译:BeginPaint和EndPaint的参数是一样的,都需要窗口句柄以及一个绘图结构。

 

 

The window procedure must call BeginPaint and EndPaint as a pair while processing the WM_PAINT message. If a window procedure does not process WM_PAINT messages, it must pass the WM_PAINT message to DefWindowProc, which is the default window procedure located in Windows. DefWindowProc processes WM_PAINT messages with the following code: 

 

 

【窗口过程在处理WM_PAINT消息的时候必须成对调用BeginPaint和EndPaint。如果窗口过程不处理WM_PAINT消息,它必须将WM_PAINT消息传给DefWindowProc去处理,DefWindowProc是内置于Windows中的默认窗口过程,它用以下代码处理WM_PAINT消息:】

 

case WM_PAINT:

BeginPaint (hwnd, &ps) ;

EndPaint (hwnd, &ps) ;

return 0 ;

 

The sequence of BeginPaint and EndPaint calls with nothing in between validates the previously invalid region. But don't do this:

 

case WM_PAINT:

return 0 ; // WRONG !!!

 

【依次调用BeginPaint和EndPaint而不做任何别的事,可使得先前的无效区域有效。但是不能像下面这样使用:】

 

Windows places a WM_PAINT message in the message queue because part of the client area is invalid. Unless you call BeginPaint and EndPaint (or ValidateRect), Windows will not validate that area. Instead, Windows will send you another WM_PAINT message, and another, and another, and another….  

 

客户区的部分区域变为无效将导致Windows在消息队列中放置一个WM_PAINT消息。除非你调用BeginPaint和EndPaint(或者ValidateRect),否则Windows将不会使那些无效区域变为有效,相反,Windows将会向窗口发送另一个WM_PAINT消息,一个接着一个。