Differences between CDC and HDC and mutual conversion

Source: Internet
Author: User

CDC is a DC class of MFC. HDC is the DC handle, and a data type similar to pointer in API. the prefix of the MFC class is mostly the handle starting with H starting with C. This is a help note and a good habit of programming to read and write code. the base class of DC of all MFC in CDC. common cclientdc (this) is a subclass of CDC (or a derived class ). devices such as CDC are classified up and down and contain the member variable m_nhdc; that is, the HDC type handle. remember the following sentence to help you understand it. the MFC class is a small program with certain functions developed using the window API statement. (also known as a class ). the default method to use it is to remember its name and parameters (you can use notes instead of brain notes ). if you compare window API to assembly language, then MFC is equivalent to basic language. CDC is the base class of the device description table. clientdc refers to the device description table of the customer area. paintdc is only used in the onpaint () function. HDC is a data type of windows and a device description. Handle. CDC is a class in MFC, which encapsulates almost all HDC operations. It can also be said that the HDC variable points to a piece of memory, which is used to describe the related content of a device, so it can be considered that HDC defines a pointer; the CDC class defines an object, which has a device description table defined by HDC, and also contains functions related to HDC operations. This is the same as the difference between Hpen, cpen, and point and cpoint. Transformation from CDC to HDC: Method 1: This method will not destroy the original resources (I .e., HDC, hbitmap) at the end of the device CDC * PDC = CDC: fromhandle (HDC ); cbitmap * pbitmap = cbitmap: fromhandle (hbitmap); Method 2: This method destroys the original resources (namely, HDC, hbitmap) cdc dc and DC at the end of the device. attach (HDC); cbitmap bit; bit. attach (hbitmap); add DC at the end. detach () will not destroy the original resource HDC; CDC to HDC = CDC. getsafehdc (); HDC to CDC. attach (HDC); tip1: HDC; CDC to HDC = CDC. getsafehdc (); HDC to CDC. attac H (HDC) tip2: CDC is the class in MFC, while HDC is handle. Use HDC getdc () tip3: CDC; HDC = CDC. m_hdc tip4: cdc dc; HDC = dc. m_hdc DC. fromhandle (HDC); tip5: CDC to HDC use member variable m_hdc HDC to CDC use fromhandle tip6: DC. fromhandle (HDC) generates a DC, but it is temporary. MFC does not guarantee when the system will delete the DC. DC. attach (HDC) is permanent until the lifecycle of the DC ends normally. Tip7: Search for replacement. Replace all (HDC, with PDC-> (of course. Just declare a PDC. From: http://blog.sina.com.cn/s/blog_523491650100gwii.html

Differences Between CDC and HDC and mutual conversion

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.