Here we assume that we have usedApplicationWizard generates the program code of an SDI interface. Next, you only need to add the drawing code to the OnDraw member function of the CView derived class. Here I need to explain the role of the OnDraw function. The OnDraw function will be automatically called when the window needs to be re-painted. The input parameter CDC * pDC corresponds to the DC environment. The advantage of OnDraw is that when you use the printing function, the DC environment that you pass in the OnDraw will be the printer drawing environment, and when you use the print preview, it will be a drawing environment called CPreviewDC, so you only need a piece of code to complete the window/print preview/printer drawing triple function. With the device independence of Windows and the thousands of lines of code written by M $ for print preview, you can easily complete a WYSIWYG software.
Output text is generally usedCDC: BOOL TextOut (int x, int y, const CString & str) and CDC: int DrawText (const CString & str, LPRECT lpRect, UINT nFormat) functions, for TextOut, only single-line text can be output, while DrawText can specify the single-line or multi-line text output in a rectangle, and it can specify the alignment mode and the style used. NFormat can be a combination of the following tags (using bits or operations) to select an output style.
- The bottom of DT_BOTTOM is aligned with Specifies bottom-justified text. This value must be combined with DT_SINGLELINE.
- DT_CALCRECT: Determines the width and height of the rectangle. If there are multiple lines of text, DrawText will use the width of the rectangle pointed toLpRectAnd extend the base of the rectangle to bound the last line of text. if there is only one line of text, DrawText will modify the right side of the rectangle so that it bounds the last character in the line. in either case, DrawText returns the height of the formatted text, but does not draw the text.
- The center of DT_CENTER is aligned with Centers text horizontally.
- Failed or DT_PATH_ELLIPSIS Replaces part of the given string with ellipses, if necessary, so that the result fits in the specified rectangle. The given string is not modified unless the DT_MODIFYSTRING flag is specified.
You can specify DT_END_ELLIPSIS to replace characters at the end of the string, or DT_PATH_ELLIPSIS to replace characters in the middle of the string. if the string contains backslash () characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.
- DT_EXPANDTABS Expands tab characters. The default number of characters per tab is eight.
- DT_EXTERNALLEADING limits des the font limit external leading in the line height. Normally, external leading is not supported ded in the height of a line of text.
- DT_LEFT left Aligns text flush-left.
- DT_MODIFYSTRING Modifies the given string to match the displayed text. This flag has no effect unless the DT_END_ELLIPSIS or DT_PATH_ELLIPSIS flag is specified.
Note SomeUFormatFlag combinations can cause the passed string to be modified. Using DT_MODIFYSTRING with either DT_END_ELLIPSIS or DT_PATH_ELLIPSIS may use the string to be modified, causing an assertion in the CString override.
- DT_NOCLIP Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.
- DT_NOPREFIX disable & prefix Turns off processing of prefix characters. normally, DrawText interprets the ampersand (&) mnemonic-prefix character as a directive to underscore the character that follows, and the two-ampersand (&&) mnemonic-prefix characters as a directive to print a single ampersand. by specifying DT_NOPREFIX, this processing is turned off.
- DT_PATH_ELLIPSIS
- DT_RIGHT right Aligns text flush-right.
- DT_SINGLELINE single row output Specifies single line only. Carriage returns and linefeeds do not break the line.