HDC is the handle, and CDC is a Windows Device-related class encapsulated by MFC. clientdc is a classification class of CDC, which is generated for objects in the corresponding windows customer zone. PDC is a class pointer, HDC is a Windows handle, HDC = PDC through PDC-> getsafedc (), and PDC, CDC * PDC = new CDC () through HDC (); PDC-> attch (HDC); HDC is a data type in windows and a device description handle. CDC is a class in MFC, which encapsulates almost all HDC operation. You can also say that the HDC variable points to a piece of memory. Memory is used to describe the content of a device. HDC defines a pointer, while the CDC class defines an object, This object has a device description table defined by HDC, and also contains Functions that contain HDC-related operations. This is the same as Hpen, cpen, and point. . Createcompatibledc if you want to perform a lot of GDI function operations on the screen, if each step is to directly operate on the screen DC, most of the possibilities are that the screen is flashing. A good solution is to use the memory DC to operate all these operations on the memory DC first, and then perform operations on the screen in sequence. For example, if you use bitblt to copy an image on the screen, you can directly use the DC of the screen. However, if you need to set the background (fillrect) and then bitblt, this involves two screen DC operations, so that the screen will easily flash. Save the data in the customer zone as a BMP Image 1. first obtain the HDC and hscrdc = getdc () functions in the customer zone. Create a compatible memory device description table for the screen device table. Hmemdc = createcompatibledc (hscrdc ); Note: The memory DC created by createcompatibledc cannot be used immediately. You must use createcompatiblebitmap Creates a memory bitmap, and then transfers its SelectObject to the memory DC. Physical HDC devices have memory resources at the underlying layer, but compatible DC does not provide memory space for image pixels. Therefore, compatible DC is always used with bitmap, compatible with DC, the bitmap image pixel data space is used to provide itself with memory space similar to memory. This has many benefits. Since we can use the various DC drawing functions on the image after loading the image, please refer to the following example: Compatible with DC at the beginning of creation, only 1*1 pixel size, SelectObject select bitmap before drawing. The visible area of the memory DC is a simple area, unlike the visible area of the physical DC, which may be overwritten by other windows to produce a complex visible area. since any drawing of DC needs to be considered drawing within the visible area, it cannot be beyond the visible area range. therefore, each GDI Drawing Output must be tailored to each giant area that constitutes a complex visible area. Therefore, the drawing effect of physical DC is slower than that of compatible DC. this is one of the reasons why we often use compatible DC for dual-Cache output. HDC = getdc (hwnd ); HDC memdc = createcompatibledc (HDC ); Rect RC; Bitmap BMP; Hbitmap holdbmp, hbmp = loadbitmap (hinstdvbres, makeintresource (idb_clock); // load a bitmap from a resource Holdbmp = (hbitmap) SelectObject (memdc, hbmp); // select the hbmp bitmap to be compatible with DC memdc. Then, the compatible DC will have // In the drawing area of the same size as hbmp, note that the output of GDI returned by the bitmap is invalid. GetObject (hbmp, sizeof (Bitmap), & BMP); // The bitmap size information is obtained here. In fact, it is also compatible with the DC Drawing Output Range. Setrect (& rc, 0, 0, BMP. bmwidth, BMP. bmheight ); Drawtext (memdc, "center line text"-1, & rc, dt_vcenter | dt_singleline | dt_center); // outputs a string in the compatible DC Center // In this way, we add a text annotation to the hbmp bitmap. We can save the bitmap with the added text annotation. A simple image processing is basically OK. SelectObject (memdc, holdbmp); // restores DC-compatible data. Deletedc (memdc ); //.......... |