⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07.htm

📁 VC 21天 学习VC 的好东西
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<PRE>BOOL 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);
</PRE>
<P>The first of these arguments, nHeight, specifies the height of the font to be
used. This logical value is translated into a physical value. If the value is 0,
a reasonable default value is used. If the value is greater or less than 0, the absolute
height is converted into device units. It is key to understand that height values
of 10 and -10 are basically the same.</P>
<P>The second argument, nWidth, specifies the average width of the characters in
the font. This logical value is translated into a physical value in much the same
way as the height is.</P>
<P>The third argument, nEscapement, determines the angle at which the text will be
printed. This value is specified in 0.1-degree units in a counterclockwise pattern.
If you want to print vertical text that reads from bottom to top, you supply 900
as the value for this argument. For printing normal horizontal text that flows from
left to right, supply 0 as this value.</P>
<P>The fourth argument, nOrientation, determines the angle of each individual character
in the font. This works on the same basis as the previous argument, but it controls
the output on a character basis, not a line-of-text basis. To print upside-down characters,
set this value to 1800. To print characters on their backs, set this value to 900.</P>
<P>The fifth argument, nWeight, specifies the weight, or boldness, of the font. This
can be any value from 0 to 1000, with 1000 being heavily bolded. You can use constants
defined for this argument to control this value with ease and consistency. These
constants are listed in Table 7.1.</P>
<P>
<H4>TABLE 7.1. FONT WEIGHT CONSTANTS.</H4>
<P>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><I>Constant</I></TD>
		<TD ALIGN="LEFT"><I>Value</I></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_DONTCARE		</TD>
		<TD ALIGN="LEFT">0		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_THIN		</TD>
		<TD ALIGN="LEFT">100		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_EXTRALIGHT		</TD>
		<TD ALIGN="LEFT">200		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_ULTRALIGHT		</TD>
		<TD ALIGN="LEFT">200		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_LIGHT		</TD>
		<TD ALIGN="LEFT">300		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_NORMAL		</TD>
		<TD ALIGN="LEFT">400		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_REGULAR		</TD>
		<TD ALIGN="LEFT">400		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_MEDIUM		</TD>
		<TD ALIGN="LEFT">500		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><I>Constant</I></TD>
		<TD ALIGN="LEFT"><I>Value</I></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_SEMIBOLD		</TD>
		<TD ALIGN="LEFT">600		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_DEMIBOLD		</TD>
		<TD ALIGN="LEFT">600		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_BOLD		</TD>
		<TD ALIGN="LEFT">700		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_EXTRABOLD		</TD>
		<TD ALIGN="LEFT">800		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_ULTRABOLD		</TD>
		<TD ALIGN="LEFT">800		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_BLACK		</TD>
		<TD ALIGN="LEFT">900		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">FW_HEAVY		</TD>
		<TD ALIGN="LEFT">900		</TD>
	</TR>
</TABLE>
</P>
<P>The actual interpretation and availability of these weights depend on the font.
Some fonts only have FW_NORMAL, FW_REGULAR, and FW_BOLD weights. If you specify FW_DONTCARE,
a default weight is used, just as with most of the rest of the arguments.</P>
<P>The sixth argument, bItalic, specifies whether the font is to be italicized. This
is a boolean value; 0 indicates that the font is not italicized, and any other value
indicates that the font is italicized.</P>
<P>The seventh argument, bUnderline, specifies whether the font is to be underlined.
This is also a boolean value; 0 indicates that the font is not underlined, and any
other value indicates that the font is underlined.</P>
<P>The eighth argument, cStrikeOut, specifies whether the characters in the font
are displayed with a line through the character. This is another boolean value using
a non-zero value as TRUE and 0 as FALSE.</P>
<P>The ninth argument, nCharSet, specifies the font's character set. The available
constants for this value are listed in Table 7.2.</P>
<P>
<H4>TABLE 7.2. FONT CHARACTER SET CONSTANTS.</H4>
<P>
<TABLE BORDER="1">
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT"><I>Constant</I></TD>
		<TD ALIGN="LEFT"><I>Value</I></TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">ANSI_CHARSET		</TD>
		<TD ALIGN="LEFT">0		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">DEFAULT_CHARSET		</TD>
		<TD ALIGN="LEFT">1		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">SYMBOL_CHARSET		</TD>
		<TD ALIGN="LEFT">2		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">SHIFTJIS_CHARSET		</TD>
		<TD ALIGN="LEFT">128		</TD>
	</TR>
	<TR ALIGN="LEFT" VALIGN="TOP">
		<TD ALIGN="LEFT">OEM_CHARSET		</TD>
		<TD ALIGN="LEFT">255		</TD>
	</TR>
</TABLE>
</P>
<P>The system on which your application is running might have other character sets,
and the OEM character set is system dependent, making it different for systems from
different manufacturers. If you are using one of these character sets, it is risky
to try to manipulate the strings to be output, so it's best to just pass along the
string to be displayed.</P>
<P>The tenth argument, nOutPrecision, specifies how closely the output must match
the requested font's height, width, character orientation, escapement, and pitch.
The available values for this argument are</P>
<P>

<UL>
	<LI>OUT_CHARACTER_PRECIS
	<P>
	<LI>OUT_DEFAULT_PRECIS
	<P>
	<LI>OUT_DEVICE_PRECIS
	<P>
	<LI>OUT_RASTER_PRECIS
	<P>
	<LI>OUT_STRING_PRECIS
	<P>
	<LI>OUT_STROKE_PRECIS
	<P>
	<LI>OUT_TT_PRECIS
</UL>

<P>The OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, and OUT_TT_PRECIS values control which
font is chosen if there are multiple fonts with the same name. For instance, if you
use the OUT_TT_PRECIS value and specify a font with both a TrueType and raster version,
then the TrueType version is used. In fact, the OUT_TT_PRECIS value forces the system
to use a TrueType font, even when the specified font does not have a TrueType version.</P>
<P>The eleventh argument, nClipPrecision, specifies how to clip characters that are
partially outside of the display area. The values for this argument are</P>
<P>

<UL>
	<LI>CLIP_CHARACTER_PRECIS
	<P>
	<LI>CLIP_DEFAULT_PRECIS
	<P>
	<LI>CLIP_ENCAPSULATE
	<P>
	<LI>CLIP_LH_ANGLES
	<P>
	<LI>CLIP_MASK
	<P>
	<LI>CLIP_STROKE_PRECIS
	<P>
	<LI>CLIP_TT_ALWAYS
</UL>

<P>These values can be ORed together to specify a combination of clipping techniques.</P>
<P>The twelfth argument, nQuality, specifies the output quality and how carefully
the GDI (Graphics Device Interface) must attempt to match the logical font attributes
to the physical font output. The available values for this argument are</P>
<P>

<UL>
	<LI>DEFAULT_QUALITY
	<P>
	<LI>DRAFT_QUALITY
	<P>
	<LI>PROOF_QUALITY
</UL>

<P>The thirteenth argument, nPitchAndFamily, specifies the pitch and family of the
font. This value consists of two values that are ORed together to create a combination
value. The first set of available values is</P>
<P>

<UL>
	<LI>DEFAULT_PITCH
	<P>
	<LI>VARIABLE_PITCH
	<P>
	<LI>FIXED_PITCH
</UL>

<P>This value specifies the pitch to be used with the font. The second set of available
values specifies the family of fonts to be used. The available values for this portion
of the argument are</P>
<P>

<UL>
	<LI>FF_DECORATIVE
	<P>
	<LI>FF_DONTCARE
	<P>
	<LI>FF_MODERN
	<P>
	<LI>FF_ROMAN
	<P>
	<LI>FF_SCRIPT
	<P>
	<LI>FF_SWISS
</UL>

<P>The font family describes in a general way the appearance of a font. You can use
the font family value to choose an alternative font when a specific font does not
exist on a system. The final argument, lpszFacename, is a standard C-style string
that contains the name of the font to be used. This font name comes from the font
information received by the EnumFontFamProc callback function.</P>
<P>
<H2><A NAME="Heading4"></A>Using Fonts</H2>
<PRE>Today you will build an application that allows the user to select from a list of available fonts to be displayed. The user will be able to enter some text to be displayed in the selected font, allowing the user to see what the font looks like.
</PRE>
<H3><A NAME="Heading5"></A>Creating the Application Shell</H3>
<P>To begin today's application, follow these steps:</P>
<P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Create a new project workspace using the MFC AppWizard. Name the project
	<B>Day7</B>.
	<P>
	<DT></DT>
	<DD><B>2. </B>Use the same defaults that you used for the previous day's projects,
	giving the application a title of <B>Fonts</B>.
	<P>
	<DT></DT>
	<DD><B>3. </B>Design the main dialog as in Figure 7.1, using the properties in Table
	7.3.
	<P>
</DL>

<P><A HREF="javascript

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -