Windows API-GDI basics & invalid rectangle & getdc and beginpaint

Source: Internet
Author: User
Website:
Http://www.pconline.com.cn/pcedu/empolder/gj/c/0506/651420.html

In Windows, A paintstruct structure is reserved for each window, which contains the coordinates of the smallest rectangle surrounding the invalid area and some other information, note that when the window message processing function displays another invalid region before processing the wm_paint message, Windows calculates a new invalid region that contains two invalid regions, save the changes in the paintstruct structure. Windows does not store multiple wm_paint messages in the message queue at the same time.

The window message processing function calls the invalidaterect function to make the rectangle in the window display area invalid. If a wm_paint message already exists in the message queue, Windows calculates a new invalid rectangle, when a wm_paint message is received, the window message processing function obtains the coordinates of invalid rectangles. By calling getupdaterect, the coordinates can be obtained at any time.

Difference between getdc and beginpaint in obtaining HDC:

1. Use the beginpaint and endpaint Functions

Usually in applicationsProgramWhen you receive the wm_paint message, that is, you need to call the beginpaint function to obtain the handle of the device description table when updating the display area of the window. After using the function, call the endpaint function to release the handle of the device description table.

Their function prototype is:

HDC beginpaint (
HwndHwnd,, // Handle to window
LppaintstructPpaint // Paint Information
);
Bool endpaint (
HwndHwnd, // Handle to window
Const paintstruct *Ppaint // Paint data
);

2. Use the getdc and releasedc Functions

In many cases, we may need to obtain the device description table handle when receiving a non-wm_paint message. by calling the getdc function, we can obtain the device description table handle, because the program author may want to use the device description table handle to complete other work, such as obtaining the properties of the device description table or modifying the properties of the device description table, in the end, we need to release the handle like the first method and call the releasedc function to complete the work.

Their function prototype is:

HDC getdc (
HwndHwnd // Handle to window
);
Int releasedc (
HwndHwnd, // Handle to window
HDCHDC // Handle to DC
);

Differences between the two methods:

<1> the operation area obtained by using the beginpaint function is the invalid rectangular area in the display area. Next, the drawing operation can only be performed within the invalid area of the window, areas other than the invalid area are ignored and cannot be operated. The operation area obtained by the getdc function is the display area of the entire window. Subsequent operations can be performed in any part, it is not limited to invalid regions.

<2> the beginpaint function automatically changes the invalid region to a valid region, while the getdc function does not make any invalid region valid. The validaterect function must be forcibly called, set the second parameter to null.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.