【文章內容簡介】
sh::CreatePatternBrush(…).. In Windows implemented default GDI objects that can be retrieved and used at any time. These objects include pens, brushes, fonts, etc. We can get any object by calling ::GetStockObject(…) API function. There turned value is a handle that could be attached to a GDI variable (declared by MFC class) of the same type. When a rectangle is not finally fixed, we may want to draw only its border and leave its interior unpainted. To implement this, we can select a NULL (hollow) brush into the device context. A hollow brush can be obtained by calling function ::GetStockObject(…) using HOLLOW_BTRUSH or NULL_BRUSH flag. With the above implementation, the application will be able to let the user draw rectangles. With only minor modifications we can let the application draw ellipses. To draw an ellipse, we need to call function CDC::Ellipse(…)and pass a CRect type value to it. This is exactly the same with calling function CDC::Rectangle(…). So in the previous sample, if we change all the “Rectangle” keywords to “Ellipse”, the application will be implemented to draw ellipses instead of rectangles. Font Font is another very important GDI object, every application deals with font. Usually a systemcontains some default fonts that can be used by all the applications. Besides these default fonts, we can also install fonts provided by the thirty party. For word processing applications, using font is a plex issue. There are many things we need to take care. For example, when creating this type of applications, we need to think about the following issues: how to display a font with different styles。 how to change the text alignment。 how to add special effects to characters. When we implement a font dialog box, all the available fonts contained in the system will be listed in it. We can select font size, font name, special styles, and text other GDI objects such as pen and brush, we need to create font with specific styles and select it into a DC in order to use it for outputting text. In MFC, the class that can be used to implement font is CFont. To create a font, we can call either CFont::CreateFont(…) or CFont::CreateFontIndirect(…), whose formats are listed as follows: BOOL CFont::CreateFont ( int nHeight, int nWidth, int nEscapement, int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename )。 BOOL CFont::CreateFontIndirect(const LOGFONT *lpLogFont)。 The first function has many parameters and the second one needs only a LOGFONT type pointer. The results of the two member functions are exactly the same, every style we need to specify for a font in the first function has a corresponding member in structure LOGFONT: typedef struct tagLOGFONT{ LONG lfHeight。 LONG lfWidth。 LONG lfEscapement。 LONG lfOrientation。 LONG lfWeight。 BYTE lfItalic。 BYTE lfUnderline。 BYTE lfStrikeOut。 BYTE lfCharSet。 BYTE lfOutPrecision。 BYTE lfClipPrecision。 BYTE lfQuality。 BYTE lfPitchAndFamily。 TCHAR lfFaceName[LF_FACESIZE]。 } LOGFONT。 Here, member lfFaceName specifies the font name。 lfHeight