The brush Origin

zhaozj2021-02-17  35

The brush Origin

One attribute of a device context that you should be aware of when using dithered brush colors or hatch brushes is the brush origin. When Windows fills an area with a hatched or dithered brush pattern, it tiles an 8-pixel by 8-pixel pattern horizontally and vertically within the affected area. By default, the origin for this pattern, better known as the brush origin, is the device point (0,0) -the screen pixel in the upper left corner of the window. This means that a pattern drawn in a rectangle that begins 100 pixels to the right of and below the origin will be aligned somewhat differently with respect to the rectangle's border than a pattern drawn in a rectangle positioned a few pixels to the left or right, as shown in Figure 2- .

Figure 2-8. Brush alignment.

Suppose you're using a hatch brush to fill a rectangle and you're animating the motion of that rectangle by repeatedly erasing it and redrawing it 1 pixel to the right or the left. If you do not reset the brush origin to a point ........................

The solution? Before selecting the brush into the device context and drawing the rectangle, call CGdiObject :: UnrealizeObject on the brush object to permit the brush origin to be moved. Then call CDC :: SetBrushOrg to align the brush origin with the rectangle's upper left Corner, AS Shown Here:

CPoint Point (x1, y1);

Dc.lptodp (& point);

POINT.X% = 8;

Point.y% = 8;

Brush.unRealizeObject (); dc.setbrushorg (point);

Dc.selectObject (& brush);

Dc.Rectangle (X1, Y1, X2, Y2);

In this example, point is a CPoint object that holds the logical coordinates of the rectangle's upper left corner. LPtoDP is called to convert logical coordinates into device coordinates (brush origins are always specified in device coordinates), and a modulo-8 operation is performed On The Resulting Values ​​Because Coordinates Passed to setbrushorg Should Fall Withnin The Range 0 THROUGH 7. NOW The Hatch Pattern Will Be Aligned Consistently No Matter Where In The Window The Rectangle IS Drawn.

Drawing text

You've already seen one way to output text to a window. The CDC :: DrawText function writes a string of text to a display surface. You tell DrawText where to draw its output by specifying both a formatting rectangle and a series of option flags Indicating how the text is to be positioned with the rectangle. in Chapter 1's Hello Program, The Statement

Dc.drawtext (_T ("Hello, MFC"), -1, & review,

DT_SINGLINE | DT_CENTER | DT_VCENTER);

drew "Hello, MFC" so that it was centered in the window. rect was a rectangle object initialized with the coordinates of the window's client area, and the DT_CENTER and DT_VCENTER flags told DrawText to center its output in the rectangle both horizontally and vertically.

DrawText is one of several text-related functions that are members of MFC's CDC class. Some of the others are listed in the table below. One of the most useful is TextOut, which outputs text like DrawText but accepts an xy coordinate pair that specifies where The Text Will Be Output and Also Uses The Current Position If It is asked to. The Statement

dc.TextOut (0, 0, CString (_T ( "Hello, MFC")));. writes "Hello, MFC" to the upper left of the display surface represented by dc A related function named TabbedTextOut works just like TextOut except that it expands tab characters into white space. (If a string passed to TextOut contains tabs, the characters show up as rectangles in most fonts.) Tab positions are specified in the call to TabbedTextOut. A related function named ExtTextOut gives you the added option of Filling a Rectangle Surrounding The Output Text With An Opaque Background Color. It Also Gives The Programmer PRecise Control over intercharacter spacing.

By default, the coordinates passed to TextOut, TabbedTextOut, and ExtTextOut specify the location of the upper left corner of the text's leftmost character cell. However, the relationship between the coordinates passed to TextOut and the characters in the output string, a property known as The text alignment, is an attribute of the device context. You can change it with cdc :: setTextalign. for example, after a

Dc.SetTextAlign (TA_RIGHT);

Statement is Executed, The x Coordinate Passed to Textout Specifies The Rightmost Position In The Character Cell-Perfect for Drawing Right-Aligned Text.

You can also call SetTextAlign with a TA_UPDATECP flag to instruct TextOut to ignore the x and y arguments passed to it and use the device context's current position instead. When the text alignment includes TA_UPDATECP, TextOut updates the x component of the current position each time a String is output. One use for this feature is to achieve prosker spacing between two or more character strings two or more.

CDC Text functions

FunctionDescriptionDrawText Draws text in a formatting rectangleTextOut Outputs a line of text at the current or specified positionTabbedTextOut Outputs a line of text that includes tabsExtTextOut Outputs a line of text and optionally fills a rectangle with a background color or varies the intercharacter spacingGetTextExtent Computes the width of a string in the current fontGetTabbedTextExtentComputes the width of a string with tabs in the current fontGetTextMetrics Returns font metrics (character height, average character width, and so on) for the current fontSetTextAlign Sets alignment parameters for TextOut and other output functionsSetTextJustificationSpecifies the added width that is needed to justify a string of textSetTextColorSets the device context's text output colorSetBkColorSets the device context's background color, which determines the fill color used behind characters that are output to a display surfaceTwo functions-GetTextMetrics and GetTextExtent-let you retrieve info rmation about the font that is currently selected into the device context. GetTextMetrics fills a TEXTMETRIC structure with information on the characters that make up the font. GetTextExtent returns the width of a given string, in logical units, rendered in that font. (Use GetTabbedTextExtent if the string contains tab characters.) One use for GetTextExtent is to gauge the width of a string prior to outputting it in order to compute how much space is needed between words to fully justify the text. If nWidth is the distance between left and right Margins, The Following Code Outputs The Text "Now is the Time" and justifies the output to Both margins:

CString String = _t ("now is the time");

CSIZE SIZE = dc.gettextextent (string); DC.SettextJustification (nwidth - size.cx, 3);

Dc.TextOut (0, y, string);

The second parameter passed to SetTextJustification specifies the number of break characters in the string. The default break character is the space character. After SetTextJustification is called, subsequent calls to TextOut and related text output functions distribute the space specified in the SetTextJustification's first parameter evenly between All the break characters.

GDI FONTS AND THE CFONT CLASS

All CDC text functions use the font that is currently selected into the device context. A font is a group of characters of a particular size (height) and typeface that share common attributes such as character weight-for example, normal or boldface. In classical typography, font sizes are measured in units called points. One point equals about 1/72 inch. Each character in a 12-point font is nominally 1/6 inch tall, but in Windows, the actual height can vary somewhat depending on the physical Characteristics of the output device. The Term Typeface Describes A Font's Basic Style. Times New Roman is One Example of A Typeface; Courier New Is Another.

A font is a GDI object, just as a pen or a brush is. In MFC, fonts are represented by objects of the CFont class. Once a CFont object is constructed, you create the underlying GDI font by calling the CFont object's CreateFont, CreateFontIndirect , CreatePointFont, or CreatePointFontIndirect function. use CreateFont or CreateFontIndirect if you want to specify the font size in pixels, and use CreatePointFont and CreatePointFontIndirect to specify the font size in points. Creating a 12-point Times New Roman screen font with CreatePointFont requires just two LINES OF CODE: CFONT FONT;

Font.createPointFont (120, "Times New Roman"));

Doing the Same with createfont required for the logical number of pixels per in the value of pixels:

CClientDC DC (this);

INT NHEIGHT = - ((Dc.getDeviceCaps (Logpixelsy) * 12) / 72);

CFONT font;

Font.createfont (NHEIGHT, 0, 0, 0, FW_NORMAL, 0, 0, 0,

Default_charset, OUT_CHARACTER_PRECIS, Clip_Character_Precis,

Default_quality, default_pitch | ff_dontcare,

_T ("Times New Roman"));

Incidentally, the numeric value passed to CreatePointFont is the desired point size times 10. This allows you to control the font size down to 1/10 point-plenty accurate enough for most applications, considering the relatively low resolution of most screens and other commonly used Output Devices.

The many parameters passed to CreateFont specify, among other things, the font weight and whether characters in the font are italicized. You can not create a bold, italic font with CreatePointFont, but you can with CreatePointFontIndirect. The following code creates a 12- Point Bold, Italic Times New Roman Font Using CreatePointFontIndInderct.logfont LF;

:: ZeromeMory (& lf, SizeOf (LF));

Lf.lfheight = 120;

Lf.lfweight = fw_bold;

Lf.lfitalic = TRUE;

:: LSTRCPY (LF.Lffacename, _T ("Times New Roman"));

CFONT font;

Font.createPointFontIndirect (& lf);

LOGFONT is a structure whose fields define all the characteristics of a font. :: ZeroMemory is an API function that zeroes a block of memory, and :: lstrcpy is an API function that copies a text string from one memory location to another. You can use the C run time's memset and strcpy functions instead (actually, you should use _tcscpy in lieu of strcpy so the call will work with ANSI or Unicode characters), but using Windows API functions frequently makes an executable smaller by reducing the amount of statically linked Code.

After creating a font, you can select it into a device context and draw with it using DrawText, TextOut, and other CDC text functions. The following OnPaint handler draws "Hello, MFC" in the center of a window. But this time the text IS DRAWN USING A 72-POINT Arial Typeface, Complete with Drop Shadows (See Figure 2-9.)

Void cmainwindow :: onpaint ()

{

CRECT RECT;

GetClientRect (& RECT);

CFONT font;

Font.createPointFont (720, _t ("arial"));

CPAINTDC DC (this);

Dc.selectObject (& font);

Dc.setbkmode (transparent);

CString String = _t ("Hello, MFC");

Rect.offsetRect (16, 16);

Dc.SettextColor (RGB (192, 192, 192)); dc.drawtext (String, & Rect, DT_SINGLINE |

DT_Center | DT_VCENTER);

Rect.offsetRect (-16, -16);

Dc.SetTextColor (RGB (0, 0, 0));

Dc.drawtext (String, & Rect, Dt_SingLine |

DT_Center | DT_VCENTER);

}

Figure 2-9. "Hello, MFC" RENDERED IN 72-Point Arial with Drop Shadows.

The shadow effect is achieved by drawing the text string twice-once a few pixels to the right of and below the center of the window, and once in the center. MFC's CRect :: OffsetRect function makes it a snap to "move" rectangles by Offsetting the x and y DIRECTIONS.

What happens if you try to create, say, a Times New Roman font on a system that does not have Times New Roman installed? Rather than fail the call, the GDI will pick a similar typeface that is installed. An internal font-mapping algorithm is called to pick the best match, and the results are not always what one might expect. But at least your application will not output text just fine on one system and mysteriously output nothing on another.

Raster Fonts vs. TrueType Fonts

Most GDI fonts fall into one of two categories:. Raster fonts and TrueType fonts Raster fonts are stored as bitmaps and look best when they're displayed in their native sizes One of the most useful raster fonts provided with Windows is MS Sans Serif,. which is commonly used (in its 8-point size) on push buttons, radio buttons, and other dialog box controls. Windows can scale raster fonts by duplicating rows and columns of pixels, but the results are rarely pleasing to the eye due to stair -Stepping Effects.

The best fonts are TrueType fonts because they scale well to virtually any size. Like PostScript fonts, TrueType fonts store character outlines as mathematical formulas. They also include "hint" information that's used by the GDI's TrueType font rasterizer to enhance scalability. You can pretty Much Bank On The Fact That Any System Your Application Runs ON Will Have The Following TrueType Fonts Installed, Because All Four Province: Times New Roman Arial Courier New Symbol

In Chapter 7, you'll learn how to query the system for font information and how to enumerate the fonts that are installed. Such information can be useful if your application requires precise character output or if you want to present a list of installed fonts to The user.

Rotated Text

One question that's frequently asked about GDI text output is "How do I display rotated text?" There are two ways to do it, one of which works only in Microsoft Windows NT and Windows 2000. The other method is compatible with all 32-bit Versions of Windows, SO It's The One I'll Describe Here.

The secret is to create a font with CFont :: CreateFontIndirect or CFont :: CreatePointFontIndirect and to specify the desired rotation angle (in degrees) times 10 in the LOGFONT structure's lfEscapement and lfOrientation fields. Then you output the text in the normal manner-for . example, using CDC :: TextOut Conventional text has an escapement and orientation of 0; that is, it has no slant and is drawn on a horizontal Setting these values ​​to 450 rotates the text counterclockwise 45 degrees The following OnPaint handler increments lfEscapement.. And Lirtiantation in Units of 15 Degrees and uses the resulting fonts to draw the radial text array shown in Figure 2-10: Void cmainwindow :: onpaint ()

{

CRECT RECT;

GetClientRect (& RECT);

CPAINTDC DC (this);

Dc.SetViewportorg (Rect.width () / 2, Rect.Height () / 2);

Dc.setbkmode (transparent);

For (int i = 0; i <3600; i = 150) {

Logfont LF;

:: ZeromeMory (& lf, SizeOf (LF));

Lf.lfheight = 160;

Lf.lfweight = fw_bold;

Lf.LFEScapement = i;

Lf.LForientation = i;

:: lstrcpy (lf.lffacename, _t ("arial"));

CFONT font;

Font.createPointFontIndirect (& lf);

CFont * PoldFont = DC.SelectObject (& font);

Dc.Textout (0, 0, CString (_T ("Hello, MFC")))))))

Dc.selectObject (PoldFont);

}

}

This Technique Works Great With TrueType Fonts, But it Doesn't Work At All With Raster Fonts.

Figure 2-10. Rotated text.

Stock Objects

Windows predefines a handful of pens, brushes, fonts, and other GDI objects that can be used without being explicitly created. Called stock objects, these GDI objects can be selected into a device context with the CDC :: SelectStockObject function or assigned to an existing CPen, CBrush, or other object with CGdiObject :: CreateStockObject. CGdiObject is the base class for CPen, CBrush, CFont, and other MFC classes that represent GDI objects.The following table shows a partial list of the available stock objects. Stock pens go by the names WHITE_PEN, BLACK_PEN, and NULL_PEN. WHITE_PEN and BLACK_PEN draw solid lines that are 1 pixel wide. NULL_PEN draws nothing. The stock brushes include one white brush, one black brush, and three shades of gray. HOLLOW_BRUSH and NULL_BRUSH are two different ...

Commonly Used Stock Objects

ObjectDescriptionNULL_PENPen that draws nothingBLACK_PENBlack pen that draws solid lines 1 pixel wideWHITE_PENWhite pen that draws solid lines 1 pixel wideNULL_BRUSHBrush that draws nothingHOLLOW_BRUSHBrush that draws nothing (same as NULL_BRUSH) BLACK_BRUSHBlack brushDKGRAY_BRUSHDark gray brushGRAY_BRUSHMedium gray brushLTGRAY_BRUSH Light gray brushWHITE_BRUSH White brushANSI_FIXED_FONT Fixed-pitch ANSI fontANSI_VAR_FONTVariable-pitch ANSI FONTSYSTEM_FONTVARIABLE-PITCH System Fontsystem_fixed_FontFixed-Pitch System Font

Suppose You Want to Draw A Light Gray Circle with no border. How do you do it? Here's one Way:

CPEN PEN (PS_NULL, 0, (RGB (0, 0, 0)))));

Dc.selectObject (& Pen);

Cbrush Brush (RGB (192, 192, 192);

Dc.selectObject (& brush);

Dc.ellipse (0, 0, 100, 100); But Since Null Pens and Light Gray Brushes Are Stock Objects, Here's A Better Way:

Dc.selectStockObject (null_pen);

Dc.selectStockObject (LTGRAY_BRUSH);

Dc.ellipse (0, 0, 100, 100);

The Following Code Demonstrates A Third Way To Draw The Circle. This Time The Stock Objects Are Assigned To a CPEN AND A CBRUSH Rather Than Selected INTO The Device Context Directly:

CPEN Pen;

Pen.createstockObject (NULL_PEN);

Dc.selectObject (& Pen);

CBRUSH brush;

Brush.createstockOckObject (LTGRAY_BRUSH);

Dc.selectObject (& brush);

Dc.ellipse (0, 0, 100, 100);

Which of the three methods you use is up to you. The Second Method is The Shortest, And It's The Only One That's Guaranteed Not to THROW An Exception Since It Doesn't Create Any GDI Objects.

Deleting GDI Objects

Pens, brushes, and other objects created from CGdiObject-derived classes are resources that consume space in memory, so it's important to delete them when you no longer need them. If you create a CPen, CBrush, CFont, or other CGdiObject on the stack , the associated GDI object is automatically deleted when CGdiObject goes out of scope. If you create a CGdiObject on the heap with new, be sure to delete it at some point so that its destructor will be called. The GDI object associated with a CGdiObject can BE EXPLICITLY DELETED by CALLING CGDIOBJECT :: DeleteObject. You Never Need To Delete Stock Objects, Even if the is "created" with createstockObject.

In 16-bit Windows, GDI objects frequently contributed to the problem of resource leakage, in which the Free System Resources figure reported by Program Manager gradually decreased as applications were started and terminated because some programs failed to delete the GDI objects they created. All 32 -bit versions of Windows track the resources a program allocates and deletes them when the program ends. However, it's still important to delete GDI objects when they're no longer needed so that the GDI does not run out of memory while a program is running. Imagine an OnPaint handler that creates 10 pens and brushes every time it's called but neglects to delete them. Over time, OnPaint might create thousands of GDI objects that occupy space in system memory owned by the Windows GDI. Pretty soon, calls to create Pens and Brushes Will Fail, And The Application's Onpaint Handler Will MySTERIOSLY Stop Working.in Visual C , There's An Easy Way To Tell WHether You're Failing To Delete Pens, Brushe s, and other resources:.. Simply run a debug build of your application in debugging mode When the application terminates, resources that were not freed will be listed in the debugging window MFC tracks memory allocations for CPen, CBrush, and other CObject- Derived classes SO That It can notify you at ketage from the debug messages which Objects get't deleted, add the statement

#define new debug_new

to your application's source code files after the statement that includes Afxwin.h. (In AppWizard-generated applications, this statement is included automatically.) Debug messages for unfreed objects will then include line numbers and file names to help you pinpoint leaks.Deselecting GDI Objects

It's important to delete the GDI objects you create, but it's equally important to never delete a GDI object while it's selected into a device context. Code that attempts to paint with a deleted object is buggy code. The only reason it does not crash is That The Windows GDI IS Sprinkled with error-checking code to prevent such crashes from occurring.

Abiding by this rule isn't As Easy As It Sounds. The Following Onpaint Handler Allows A Brush To Be Dleted WHILE'S SELECTED INTO A DEVICE CONTEXT. CAN you figure out why?

Void cmainwindow :: onpaint ()

{

CPAINTDC DC (this);

CBRUSH Brush (RGB (255, 0, 0));

Dc.selectObject (& brush);

Dc.ellipse (0, 0, 200, 100);

}

Here's the problem. A CPaintDC object and a CBrush object are created on the stack. Since the CBrush is created second, its destructor gets called first. Consequently, the associated GDI brush is deleted before dc goes out of scope. You could fix this by Creating The Brush First and The DC Second, But Code Whose Robustness Relies On Stack Variables Being Created In a Particular Order IS Bad Code Indeed. AS Far As Maintainability Goes, It's A Nightmare.

The solution is to select the CBrush out of the device context before the CPaintDC object goes out of scope. There is no UnselectObject function, but you can select an object out of a device context by selecting in another object. Most Windows programmers make it a practice to save the pointer returned by the first call to SelectObject for each object type and then use that pointer to reselect the default object. An equally viable approach is to select stock objects into the device context to replace the objects that are currently selected in. The first of these two methods is illustrate by the following code: CPEN PEN (PS_SOLID, 1, RGB (255, 0, 0));

CPEN * POLDPEN = DC.SelectObject (& Pen);

CBRUSH Brush (RGB (0, 0, 255);

CBRUSH * POLDBRUSH = DC.SelectObject (& brush);

Dc.selectObject (Poldpen);

Dc.selectObject (Poldbrush);

The Second Method Works Like this:

CPEN PEN (PS_SOLID, 1, RGB (255, 0, 0));

Dc.selectObject (& Pen);

CBRUSH Brush (RGB (0, 0, 255);

Dc.selectObject (& brush);

Dc.selectStockObject (Black_pen);

Dc.selectStockObject (White_brush);

The big question is why this is necessary. The simple truth is that it's not. In modern versions of Windows, there's no harm in allowing a GDI object to be deleted a split second before a device context is released, especially if you're absolutely sure that no drawing will be done in the interim. Still, cleaning up a device context by deselecting the GDI objects you selected in is a common practice in Windows programming. It's also considered good form, so it's something I'll do throughout this book .

Incidentally, GDI Objects Are Occasionally Created on The Heap, Like this:

CPEN * PPEN = New CPEN (PS_SOLID, 1, RGB (255, 0, 0)); CPEN * POLDPEN = DC.SelectObject (PPEN);

At Some Point, The Pen Must Be Slected Out of The Device Context and deleted. The code to do it might l l THIS:

Dc.selectObject (Poldpen);

Delete ppen;

Since The SelectObject Function Returns A Pointer To The Object Selected Out of The Device Context

Delete dc.selectObject (PoldPen);

But do not do this. It works fine with pens, but it might not work with brushes. Why? Because if you create two identical CBrushes, 32-bit Windows conserves memory by creating just one GDI brush and you'll wind up with two CBrush pointers that reference the same HBRUSH. (An HBRUSH is a handle that uniquely identifies a GDI brush, just as an HWND identifies a window and an HDC identifies a device context. A CBrush wraps an HBRUSH and stores the HBRUSH handle in its m_hObject data member.) Because CDC :: SelectObject uses an internal table maintained by MFC to convert the HBRUSH handle returned by SelectObject to a CBrush pointer and because that table assumes a one-to-one mapping between HBRUSHes and CBrushes, the CBrush pointer you get Back might not match the cbrush pointer returned by new. Be Sure You Pass Delete the Pointer Returned by New. Then Both The GDI Object and The C Object Will Be Properly Destroyed.

The Ruler Application

The best way to get acquainted with the GDI and the MFC classes that encapsulate it is to write code. Let's start with a very simple application. Figure 2-12 contains the source code for Ruler, a program that draws a 12-inch ruler on The Screen. Ruler's Output is Shown in Figure 2-11.

Figure 2-11. The ruler window.figure 2-12. The ruler application.

Ruler.hclass CMYAPP: Public CWINAPP

{

PUBLIC:

Virtual Bool InitInstance ();

}

Class CMainWindow: Public CFrameWnd

{

PUBLIC:

CMAINWINDOW ();

protected:

AFX_MSG void onpaint ();

Declare_message_map ()

}

Ruler.cpp # include

#include "ruler.h"

CMYAPP myApp;

/

// CMYAPP Member Functions

Bool CmyApp :: InitInstance ()

{

m_pmainwnd = new cmainwindow;

m_pmainwnd-> showwindow (m_ncmdshow);

m_pmainwnd-> UpdateWindow ();

Return True;

}

/

// CMainWindow Message Map and Member Functions

Begin_MESSAGE_MAP (CMainWindow, CFrameWnd)

ON_WM_PAINT ()

END_MESSAGE_MAP ()

CMAINWINDOW :: CMAINWINDOW ()

{

Create (NULL, _T ("Ruler");

}

Void cmainwindow :: onpaint ()

{

CPAINTDC DC (this);

//

// Initialize The Device Context.

//

DC.SETMAPMODE (mm_loenglish);

Dc.SetTextAlign (Ta_Center | TA_BOTTOM);

Dc.setbkmode (transparent);

//

// Draw the body of the ruler.

//

CBRUSH Brush (RGB (255, 255, 0));

CBRUSH * POLDBRUSH = DC.SelectObject (& brush);

Dc.Rectangle (100, -100, 1300, -200);

Dc.selectObject (Poldbrush);

//

// Draw the Tick Marks and labels.

//

For (int i = 125; i <1300; i = 25) {

DC.Moveto (i, -192);

DC.LineTo (i, -200);

}

FOR (i = 150; i <1300; i = 50) {

Dc.moveto (i, -184);

DC.LineTo (i, -200);

}

For (i = 200; i <1300; i = 100) {

Dc.moveto (i, -175);

DC.LineTo (i, -200);

CString string;

String.format (_T ("% d"), (I / 100) - 1);

Dc.Textout (i, -175, string);

}

}

The structure of Ruler is similar to that of the Hello application presented in Chapter 1. The CMyApp class represents the application itself. CMyApp :: InitInstance creates a frame window by constructing a CMainWindow object, and CMainWindow's constructor calls Create to create the window you see on the screen. CMainWindow :: OnPaint handles all the drawing. The body of the ruler is drawn with CDC :: Rectangle, and the hash marks are drawn with CDC :: LineTo and CDC :: MoveTo. Before the rectangle is drawn, a yellow brush is selected into the device context so that the body of the ruler will be painted yellow. Numeric labels are drawn with CDC :: TextOut and positioned over the tick marks by calling SetTextAlign with TA_CENTER and TA_BOTTOM flags and passing TextOut the coordinates of the top of each tick mark. Before TextOut is called for the first time, the device context's background mode is set to TRANSPARENT. Otherwise, the numbers on the face of the ruler would be drawn with white backgroun ds.Rather than hardcode the strings passed to TextOut, Ruler uses CString :: Format to generate text on the fly. CString is the MFC class that represents text strings. CString :: Format works like C's printf function, converting numeric values ​​to text and substituting them for placeholders in a formatting string. Windows programmers who work in C frequently use the :: wsprintf API function for text formatting. Format does the same thing for CString objects without requiring an external function call. And unlike :: wsprintf, Format supports .

转载请注明原文地址:https://www.9cbs.com/read-30683.html

New Post(0)