InThere are various GUI objects in Windows (do not confuse them with C ++ objects). You need to use these objects when drawing. Various objects have various attributes. The following describes various GUI objects and attributes respectively.
Font objectCFont selects fonts of different styles and sizes for text output. Optional styles include: whether it is italic, bold, font name, and underline. The color and background color do not belong to the font attributes. This section describes how to create and use a font to output text in the 2.2 window.
BrushThe CBrush object determines the color or template used when filling the area. For a fixed-color brush, its attribute is color, and whether the grid and grid types are used, such as horizontal, vertical, and cross. You can also use an 8*8 bitmap to create a custom template brush. The system will gradually fill the area with the bitmap when using this brush. For details about how to create and use a brush, refer to 2.3.
Paint BrushCPen objects are useful for drawing points and lines. Its attributes include color, width, and line style, such as dotted line, solid line, and dotted line. This section describes how to create and use a paint brush in 2.3.
BitmapA CBitmap object can contain an image and can be stored in a resource. This section describes how to use a bitmap to draw a device-related bitmap, icon, and device-independent bitmap in the 2.4 window.
There is also a specialThe GUI object is a polygon. Using polygon, you can well restrict the plotting area or change the window shape. This section describes how to create and use polygon in the 2.6 polygon and clipboard areas.
InIn Windows, GUI objects must follow certain rules. First, you must create a legal object. Different object creation methods are different. Then you need to select the GUI object into the DC and save the original GUI object in the DC. If an invalid object is selected, an exception occurs. It is particularly important to restore the original object after use. If a temporary object is saved in DC, an exception may occur after the temporary object is destroyed. Note that each object must be destroyed before being re-created. The following Code demonstrates this safe method of use:
OnDraw (CDC * pDC)
{
CPen pen1, pen2;
Pen1.CreatePen (PS_SOLID, 2, RGB (128,128,128); // create an object
Pen2.CreatePen (PS_SOLID, 2, RGB (128,128, 0); // create an object
CPen * pPenOld = (CPen *) pDC-> SelectObject (& pen1); // select an object to enter the DC
DrawWithPen1...
(CPen *) pDC-> SelectObject (& pen2); // select an object to enter the DC
DrawWithPen2...
Pen1.DeleteObject (); // destroyed before re-creation
Pen1.CreatePen (PS_SOLID, 2, RGB (0, 0); // create an object again
(CPen *) pDC-> SelectObject (& pen1); // select an object to enter the DC
DrawWithPen1...
PDC-> SelectObject (pOldPen); // restore
}
In addition, the system also has some inventoryGUI objects. You can use the CDC: SelectStockObject (int nIndex) to select these objects, including some fixed-color brushes, brushes, and some basic fonts.
- BLACK_BRUSHBlack brush.
- DKGRAY_BRUSHDark gray brush.