Three methods for obtaining DC handles on Windows

Source: Internet
Author: User
There are three main methods to get an HDC handle of the client area on the window.
1. Call the beginpaint () method in the wm_paint message. The beginpaint method returns an HDC handle for the currently invalid region and sets the invalid region as the valid region. The so-called invalid region is the region that requires the application to re-draw, and the opposite is the valid region. When beginpaint is called, a paintstruct structure is returned at the same time. The clip rectangle for this re-painting is provided. All painting operations outside this rectangle are not displayed. It is worth noting that Petzold repeatedly emphasizes in the bricks that the beginpaint method in the wm_paint message processing function needs to be paired with the endpaint method, and the HDC returned in beginpaint cannot be cached for use.
2. Call getdc (hwnd)/releasedc () to obtain the HDC handle for releasing the corresponding client rectangle. This handle has no predefined clip rectangle, and the entire client rectangle can be drawn. However, the handles obtained by getdc () cannot be cached, that is, the getdc and releasedc functions must be paired in a message processing function.
A similar API is getwindowdc (), which is used to obtain the DC of the entire window, (client area + non-client area)
Like getdc, it must be released in a wndproc execution and cannot be cached.

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.