Differences between CDC and HDC in VC and their 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 zone. paintdc is only used in the onpaint () function.

HDC is a data type in 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. Conversion from CDC to HDC: Method 1: This method does not destroy the original resources (namely, 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 (HDC, hbitmap) at the end of the device) cdc dc; DC. attach (HDC); cbitmap bit; bit. attach (hbitmap); add DC at the end. detach () will not destroy the original resource HDC; CDC to hdchdc = CDC. getsafehdc (); HDC. attach (HDC); reply to 17:46:03 score 20 HDC; CDC to hdchdc = CDC. Getsafehdc (); HDC. attach (HDC) returns to 17:49:14 score 15 CDC is the class in MFC, while HDC is handle uses HDC getdc () to return to 17:51:49 score 0 CDC; HDC = CDC. m_hdc replied to 17:54:20, scoring 20 cdc dc; HDC = dc. m_hdcdc.fromhandle (HDC); returns to 18:01:51 score 10 CDC to HDC use member variable m_hdchdc to CDC use fromhandle to return to 18:02:47 score 10 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 life of the DC ends normally. It is true that the score is more than 5 at 18:05:21. Search for replacement. Replace all (HDC, with PDC-> (of course. Just declare a PDC.

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.