All of the drawing operations include the following: Using the API, with a CClientDC object, with a cclientDC object, with the CClientDC object, with the CPWindowDC object and CPAINTDC; the following description: Using the API to make a drawing operation, first need a device description table (DC) handle HDC, then In order to draw a plot operation, release the DC at the end of the drawing, the basic operation is as follows: HDC HDC = :: getdc (m_hwnd); // getdc () requires a handle of the form as a parameter, that is, which form is obtained DC // Draw a drawing operation, draw a straight line MoveToex (HDC, 0, 0, NULL); LINETO (HDC, 100, 100); // Release DC :: ReleaseDC (M_HWND, HDC); // You need to use global functions Identifier, otherwise compiling will consider the ReleaseDC () member function to call the form object, resulting in an error CDC: is the base class of other device descriptive tables. All operations can be made here. CDC In general, the CWnd :: getDC () function needs to be initialized with the current window, namely: CDC * PDC = getDc (); // can be used in any window class to initialize a CDC class in this class In the middle, you can draw a graphic drawing operation PDC-> MoveTo (CPOINT (0)); // If there is no such sentence, you can still draw a straight line, it will default as a start point PDC by default (0, 0) -> LineTo (CPOINT (100, 100)); // If you want to draw a straight line, the default will stop the point as the starting point PDC-> Lineto (CPOINT (200, 300)); // This operation is also feasible. After this operation is completed, you need to release the DC: ReleaseDC (PDC); cclientdc: As a subclass of the CDC, encapsulate the getDc () function in the constructor, so you only need to pass a window object pointer, namely: CClientDC DC (this); // Gets the DC of the current window to encapsulate the ReleaseDC () function in the destructor of CClientDC, so it is not necessary to release it, the other operation is the same as the CDC, but it is only Valid within the range of the window of the window. CWindowdc: Points the entire window, including the client area and non-client (menu bar, etc.). As a subclass of the CDC, a getDC () function is encapsulated in the constructor. Therefore, simply pass a window object pointer, ie: CWindowDC DC (this); // Get the DC of the current window If you want on the desktop Operation, you can use the pointer to your pointing to get the desktop context description table, namely: CWindowDC DC (GetDeskTopWindow ()); in the destructor of CWindowDC, encapsulate the ReleaseDC () function, so no need to It is released, and other operations are the same as CDC, but it is only valid within the range of the window's client area. CPAINTDC: It is mainly to operate the printout, and then supplement that in addition to the basic operation of the DC, in most cases, we may need to add different properties to the drawing graphics, such as font, color, line style, fillingability Wait. This should be operated by some GDI objects.
The following is a brief description: 1, CPEN class, set the color of the brush, line style, line width, etc. CPEN PEN (PS_SOLID, 1, RGB (255, 0, 0)); // Using CPEN constructor, we can directly initialize one Objects, the first parameter represents line type, the second parameter is line width, the third parameter is color, where the third parameter is a ColorRef type, which can be constructed with macro RGB. RGB (0, 0, 0) is shown as black, and RGB (255, 0, 0) is shown in red, RGB (0, 255, 0) is displayed as green, RGB (0, 0, 255) shows blue, RGB (255, 255, 255) is shown as white. When drawing or painting other geometries, it needs to be selected into the device description table (all GDI objects are also required to perform the same operation), namely: CclientDC DC (this); cpcln * oldpen = dc.selectObject (& pen ); // Return to the original pen type in the device description table, select it back to the device description table after operation ... Dc.selectObject (oldpen); // Restore the original setting 2, CBRUSH, set the painted brush Fill type, color or bitmap. Initializing CBRUSH's objects have multiple methods: (1) If the constructor is not used in the declaration, the following initialization function must be used: BOOL CREATESOLIDBRUSH (ColorRef crcolor); // The function creates a color (herein, full color), if crcolor is RGB (255, 0, 0), create a red full padded brush. Bool CreateHatchBrush (int NINDEX, ColorRef crcolor); // Create a brush of different padding styles, where Nindex specifies the fill of different styles, such as HS_CROSS, cross-shaped fill styles; HS_Diagcross, 45 degree paintings, etc. Bool createbrushindirect (const logbrush * lplogbrush; // Create a brush over indirectly, LPLOGBRUSH points to a logbrush pointer. In this manner, you can specify a fill style, color bool createSysColorbrush (int NINDEX); // Create a brush of a system color, or specify a fill pattern (2), using constructor to initialize a painting, and use Several ways corresponding to the initialization function. CBrush (colorRef crcolor); // is the same as Createsolidbrush (), but also needs to specify a color to fill the brush. Cbrush (int NINDEX, ColorRef crcolor); // is the same as CreateHatchBrush (), which can specify the color and fill styles of the paint brush. CBRUSH (CBitMap * Pbitmap); // Fill the painting brush through a bitmap. However, when filling, you need to load (load) one bitmap to memory.
The operation is as follows: cbitmap bitmap; bitmap.loadBitmap (idb_bit_new); CBRUSH brush (& Bitmap); (3), in addition, we want to fill it when drawing rectangles, circle, etc. The following graphics can still be seen in the case of coverage. Then PDC is selected to be selected, namely: CDC * PDC = getdc (); PDC-> SelectStockObject (null_brush); To select these objects into DC objects, you can use selectObject (). For the object already existing, you must use SelectStockObject () to operate.