网站首页  词典首页

请输入您要查询的函数:

 

术语 createfont
释义 CreateFont
语法:
HFONT CreateFont(
__in int nHeight,
__in int nWidth,
__in int nEscapement,
__in int nOrientation,
__in int fnWeight,
__in DWORD fdwItalic,
__in DWORD fdwUnderline,
__in DWORD fdwStrikeOut,
__in DWORD fdwCharSet,
__in DWORD fdwOutputPrecision,
__in DWORD fdwClipPrecision,
__in DWORD fdwQuality,
__in DWORD fdwPitchAndFamily,
__in LPCTSTR lpszFace
);
CreateFont函数
在CreateFont函数创建一个具有指定特色的逻辑字体。逻辑字体可以随后选定为任何设备字体。
参数
nHeight [in]
的高度,以逻辑单位,字体的字符的单元格或字符。字符高度值(也称为时间高度)是字符单元格减去内部领先的价值高的价值。字体映射器在nHeight解释规定的下列方式的价值。
ValueMeaning
“0The字体映射器转换这个值到设备的单位和比赛对手的可用字体单元格高度了。
0The字体映射器使用默认高度值为1时,匹配的搜索。
“0The字体映射器转换这个值到设备的单位和符合其反对可用字体的字符高度的绝对值。
对于所有比较高,字体映射器寻找最大的字体不超过要求的大小。
此映射当字体是首次使用。
对于MM_TEXT映射模式,可以使用下面的公式来指定一个特定点大小字体的高度:
nHeight = - MulDiv(PointSize,GetDeviceCaps(探知,LOGPIXELSY),72);
nWidth [in]
平均宽度,以逻辑单位,所要求的字符的字体。如果此值为零,字体映射器选择一个最匹配的值。最接近的匹配值取决于通过比较当前设备之间的纵横比和数字化的可用字体的宽高比差异的绝对值。
nEscapement [in]
的角度,在十分之一度之间,纵向量和X轴的设备。纵向量平行的文本行的底线。
当图形模式设置为GM_ADVANCED,您可以指定字符串的擒纵系统的角度独立的字符串的字符方向角。
当图形模式设置为的GM_COMPATIBLE,nEscapement都指定擒纵和方向。您应该设定nEscapement和nOrientation为相同的值。
nOrientation [in]
的角度,在度0.2秒,每个字符之间的底线和X轴的设备。
fnWeight [in]
通过1000的重量范围在0字体。例如,400是正常的,700是大胆的。如果此值是零,一个默认的重量使用。
下面的值被定义为方便。
WeightValue
FW_DONTCARE0
FW_THIN100
FW_EXTRALIGHT200
FW_ULTRALIGHT200
FW_LIGHT300
FW_NORMAL400
FW_REGULAR400
FW_MEDIUM500
FW_SEMIBOLD600
FW_DEMIBOLD600
FW_BOLD700
FW_EXTRABOLD800
FW_ULTRABOLD800
FW_HEAVY900
FW_BLACK900
fdwItalic [in]
指定一个斜体如果设置为TRUE。
fdwUnderline [in]
指定一个下划线字体,如果设置为TRUE。
fdwStrikeOut [in]
阿三振字体,如果设置为TRUE。
fdwCharSet [in]
该字符集。下面的值是预定义的:
ANSI_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUL_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET
韩国语的Windows版本:
JOHAB_CHARSET
中东的Windows语言版本:
ARABIC_CHARSET
HEBREW_CHARSET
泰国的Windows语言版本:
THAI_CHARSET
OEM_CHARSET值指定的设置是操作系统依赖一个字符。
DEFAULT_CHARSET设置为当前系统区域为基础的价值。例如,当系统区域设置是英语(美国),它被ANSI_CHARSET集。
与其他字符集字体可能存在于操作系统。如果应用程序使用同一个未知的字符集的字体,它不应该试图解释的翻译或与该字体呈现字符串。
为了确保当创建一个字体一致的结果,不指定OEM_CHARSET或DEFAULT_CHARSET。如果您指定的lpszFace参数字体名称,确保fdwCharSet值匹配的lpszFace指定的字体的字符集。
fdwOutputPrecision [in]
输出精度。输出精度定义如何密切合作,输出必须符合要求的字体的高度,宽度,性格取向,擒,间距和字体类型。它可以是下列值之一。
ValueMeaning
OUT_CHARACTER_PRECISNot使用。
OUT_DEFAULT_PRECISThe默认字体映射器的行为。
OUT_DEVICE_PRECISInstructs是字体映射器选择设备字体当系统包含多个同名的字体。
OUT_OUTLINE_PRECISThis值指示字体映射器选择TrueType和其他轮廓的字体。
OUT_PS_ONLY_PRECISInstructs字体映射器选择只从PostScript字体。如果在系统中安装没有PostScript字体,字体映射器返回到默认行为。
OUT_RASTER_PRECISInstructs字体映射器选择光栅字体当系统包含多个同名的字体。
OUT_STRING_PRECISThis价值不使用的字体映射器,但它是光栅字体时返回枚举。
OUT_STROKE_PRECISThis价值不使用的字体映射器,但它是TrueType字体时返回,其他大纲为基础的字体和矢量字体枚举。
OUT_TT_ONLY_PRECISInstructs字体映射器选择只有TrueType字体。如果在系统中安装任何TrueType字体,字体映射器返回到默认行为。
OUT_TT_PRECISInstructs字体映射器选择TrueType字体当系统包含多个同名的字体。
应用程序可以使用OUT_DEVICE_PRECIS,OUT_RASTER_PRECIS,OUT_TT_PRECIS,并OUT_PS_ONLY_PRECIS值来控制字体映射器如何选择一种字体,当操作系统包含一个指定名称的多个字体。例如,如果一个操作系统包含在光栅和TrueType字体命名为标志的形式,明确OUT_TT_PRECIS部队字体映射器选择TrueType字体的版本。指定OUT_TT_ONLY_PRECIS部队字体映射器选择TrueType字体,即使必须替换另一名TrueType字体。
fdwClipPrecision [in]
剪辑精度。剪辑精确定义了如何剪辑的字符剪辑区域以外的部分。它可以是一个或多个下列值。
ValueMeaning
CLIP_CHARACTER_PRECISNot使用。
CLIP_DEFAULT_PRECISSpecifies默认剪切行为。
CLIP_DFA_DISABLEWindows XP SP1中:关闭字体关联的字体。请注意,此标志不具有任何保证在任何平台上的影响在Windows Server 2003。
CLIP_EMBEDDEDYou必须指定该标志使用嵌入式只读字体。
CLIP_LH_ANGLESWhen此值时,所有字体的旋转取决于是否坐标系统的方向是左手或右手。
如果不使用,设备字体总是逆时针方向旋转,但其他字体的旋转对坐标系统的方向而定。
如需有关方向的坐标系统的信息,见nOrientation参数的说明
CLIP_MASKNot使用。
CLIP_DFA_OVERRIDETurns起飞的字体字型关联。这是相同的CLIP_DFA_DISABLE,但它可以在某些情况下的问题;建议的标志使用CLIP_DFA_DISABLE。
CLIP_STROKE_PRECISNot使用的字体映射器,但返回时,光栅,矢量,或TrueType字体枚举。
兼容性,此值时总是返回枚举字体。
CLIP_TT_ALWAYSNot使用。
fdwQuality [in]
输出质量。输出质量定义了如何小心GDI的必须努力符合逻辑的字体属性,以一个实际的物理字体的。它可以是下列值之一。
ValueMeaning
ANTIALIASED_QUALITYFont是抗锯齿,或平滑,如果字体支持它和字体的大小也不算小或过大。
CLEARTYPE_QUALITYIf设置,文本呈现(如果可能)使用ClearType反锯齿方法。更多信息见备注。
字体的DEFAULT_QUALITYAppearance无关紧要。
字体的DRAFT_QUALITYAppearance是那么重要,当PROOF_QUALITY值。对于GDI的光栅字体,缩放为启用,这意味着更多的字体大小可用,但质量可能会降低。粗体,斜体,下划线和删除线字体合成,如有必要。
NONANTIALIASED_QUALITYFont从未反锯齿,即字体平滑没有这样做。
PROOF_QUALITYCharacter字体的质量更为重要的逻辑字体属性完全匹配。对于GDI的光栅字体,缩放,是残疾人和字体的大小最接近的选择。虽然选择的字体大小可能无法映射什么时候PROOF_QUALITY使用,字体的质量高,没有出现失真。粗体,斜体,下划线和删除线字体合成,如有必要。
如果输出质量DEFAULT_QUALITY,DRAFT_QUALITY,或PROOF_QUALITY,则该字体抗锯齿如果SPI_GETFONTSMOOTHING系统参数为TRUE。用户可以控制这种从控制面板的系统参数。 (即在控制面板设置的确切措词取决于Windows版本,但会以“屏幕字体的边缘平滑的影响”字样。)
fdwPitchAndFamily [in]
球场和字体的家庭。两个低序位指定字体间距可以是下列值之一:
DEFAULT_PITCH
FIXED_PITCH
VARIABLE_PITCH
四个高序位设置字体,可以是下列值之一。
ValueMeaning
FF_DECORATIVENovelty字体。古英语是一个例子。
FF_DONTCAREUse默认字体。
与不断笔画宽度FF_MODERNFonts,带或不带衬线。喜鹊,精英,和Courier New就是例子。
FF_ROMANFonts变笔画宽度和衬线。质谱衬线就是一个例子。
FF_SCRIPTFonts设计看起来像笔迹。脚本和行草就是例子。
FF_SWISSFonts变行程的宽度和无衬线。微软?无衬线就是一个例子。
应用程序可以指定fdwPitchAndFamily参数,通过使用布尔OR运算加入一个家庭音高恒定常数的值。
字体家庭描述一种字体一般性地看。它们用于指定字体的字体时,确切的要求无法使用。
lpszFace [in]
一个指向 null 结尾的字符串指针,指定字体的字体名称。这个字符串的长度不得超过32个字符,包括终止空字符。该EnumFontFamilies函数可以用来枚举所有当前可用字体的字体名称。有关详细信息,请参见备注。
如果lpszFace为NULL或空字符串,使用GDI的第一个字体匹配的其他指定的属性。
返回值
如果函数成功,返回值是一个句柄逻辑字体。
如果函数失败,返回值为NULL。
备注
当您不再需要的字体,调用DeleteObject函数将其删除。
为了帮助保护谁的供应商提供Windows字体的版权,应用程序应始终报告中选定字体的确切名称。由于可用的字体可以变化不同的系统,不要以为所选字体总是被请求字体相同。例如,如果您请求名为帕拉提诺1字体,但没有这样的字体是在系统可用,字体映射器将取代一种字体具有类似的属性,但不同的名称。总是报告所选字体的名称给用户。
要获得对操作系统,请与LOGFONT结构特点EnumFontFamiliesEx所需的字体,然后不同的语言版本合适的字体检索相应的字体名称和创造的字体使用CreateFont或CreateFontIndirect。
对于CreateFont,CreateFontIndirect字体映射器,并CreateFontIndirectEx承认英文和本地化的字体名称,不论语言环境。
在下列情况下不支持ClearType反锯齿:
文本提供的一台打印机。
256种颜色或较少设置的显示。
文本呈现到终端服务器客户端。
字体不是TrueType字体的TrueType或OpenType字体的轮廓。例如,下面不支持ClearType反锯齿:1键入不带的TrueType字体,后记OpenType字体轮廓,位图字体,矢量字体和设备字体。
字体已经调整嵌入式位图,只包含字体大小嵌入式位图。例如,这种情况通常在东亚字体。
实例
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{


case WM_PAINT:
{
RECT rect;
HBRUSH hBrush;
HFONT hFont;
hdc = BeginPaint(hWnd, &ps);

//Logical units are device dependent pixels, so this will create a handle to a logical font that is 48 pixels in height.
//The width, when set to 0, will cause the font mapper to choose the closest matching value.
//The font face name will be Impact.
hFont = CreateFont(48,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Impact"));
SelectObject(hdc, hFont);

//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100,100,700,200);
SetTextColor(hdc, RGB(255,0,0));
DrawText(hdc, TEXT("Drawing Text with Impact"), -1,&rect, DT_NOCLIP);

//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 20, will cause the font mapper to choose a font which, in this case, is stretched.
//The font face name will be Times New Roman. This time nEscapement is at -300 tenths of a degree (-30 degrees)
hFont = CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Times New Roman"));
SelectObject(hdc,hFont);

//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100, 200, 900, 800);
SetTextColor(hdc, RGB(0,128,0));
DrawText(hdc, TEXT("Drawing Text with Times New Roman"), -1,&rect, DT_NOCLIP);


//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 10, will cause the font mapper to choose a font which, in this case, is compressed.
//The font face name will be Arial. This time nEscapement is at 250 tenths of a degree (25 degrees)
hFont = CreateFont(36,10,250,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, VARIABLE_PITCH,TEXT("Arial"));
SelectObject(hdc,hFont);
//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 500, 200, 1400, 600);
SetTextColor(hdc, RGB(0,0,255));
DrawText(hdc, TEXT("Drawing Text with Arial"), -1,&rect, DT_NOCLIP);
DeleteObject(hFont);

EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
又例如,请参阅“使用菜单设置字体的菜单项文本字符串”。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWingdi.h(头文件:winuser.h)
LibraryGdi32.lib
DLLGdi32.dll
Unicode和ANSI namesCreateFontW(Unicode)和CreateFontA(ANSI)的
参见
字体和文字概述
字体和文本函数
CreateFontIndirect
CreateFontIndirectEx
DeleteObject
EnumFonts
EnumFontFamilies
EnumFontFamiliesEx
SelectObject
EnumFontFamilies
逻辑字体
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月11日
==英文原文==CreateFont Function
The CreateFont function creates a logical font with the specified characteristics. The logical font can subsequently be selected as the font for any device.
Syntax
HFONT CreateFont(
__in int nHeight,
__in int nWidth,
__in int nEscapement,
__in int nOrientation,
__in int fnWeight,
__in DWORD fdwItalic,
__in DWORD fdwUnderline,
__in DWORD fdwStrikeOut,
__in DWORD fdwCharSet,
__in DWORD fdwOutputPrecision,
__in DWORD fdwClipPrecision,
__in DWORD fdwQuality,
__in DWORD fdwPitchAndFamily,
__in LPCTSTR lpszFace
);
Parameters
nHeight [in]
The height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in nHeight in the following manner.
ValueMeaning
> 0The font mapper transforms this value into device units and matches it against the cell height of the available fonts.
0The font mapper uses a default height value when it searches for a match.
< 0The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts.

For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.
This mapping occurs when the font is used for the first time.
For the MM_TEXT mapping mode, you can use the following formula to specify a height for a font with a specified point size:

nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
nWidth [in]
The average width, in logical units, of characters in the requested font. If this value is zero, the font mapper chooses a closest match value. The closest match value is determined by comparing the absolute values of the difference between the current device's aspect ratio and the digitized aspect ratio of available fonts.
nEscapement [in]
The angle, in tenths of degrees, between the escapement vector and the x-axis of the device. The escapement vector is parallel to the base line of a row of text.
When the graphics mode is set to GM_ADVANCED, you can specify the escapement angle of the string independently of the orientation angle of the string's characters.
When the graphics mode is set to GM_COMPATIBLE, nEscapement specifies both the escapement and orientation. You should set nEscapement and nOrientation to the same value.
nOrientation [in]
The angle, in tenths of degrees, between each character's base line and the x-axis of the device.
fnWeight [in]
The weight of the font in the range 0 through 1000. For example, 400 is normal and 700 is bold. If this value is zero, a default weight is used.
The following values are defined for convenience.
WeightValue
FW_DONTCARE0
FW_THIN100
FW_EXTRALIGHT200
FW_ULTRALIGHT200
FW_LIGHT300
FW_NORMAL400
FW_REGULAR400
FW_MEDIUM500
FW_SEMIBOLD600
FW_DEMIBOLD600
FW_BOLD700
FW_EXTRABOLD800
FW_ULTRABOLD800
FW_HEAVY900
FW_BLACK900

fdwItalic [in]
Specifies an italic font if set to TRUE.
fdwUnderline [in]
Specifies an underlined font if set to TRUE.
fdwStrikeOut [in]
A strikeout font if set to TRUE.
fdwCharSet [in]
The character set. The following values are predefined:
ANSI_CHARSET
BALTIC_CHARSET
CHINESEBIG5_CHARSET
DEFAULT_CHARSET
EASTEUROPE_CHARSET
GB2312_CHARSET
GREEK_CHARSET
HANGUL_CHARSET
MAC_CHARSET
OEM_CHARSET
RUSSIAN_CHARSET
SHIFTJIS_CHARSET
SYMBOL_CHARSET
TURKISH_CHARSET
VIETNAMESE_CHARSET
Korean language edition of Windows:
JOHAB_CHARSET
Middle East language edition of Windows:
ARABIC_CHARSET
HEBREW_CHARSET
Thai language edition of Windows:
THAI_CHARSET
The OEM_CHARSET value specifies a character set that is operating-system dependent.
DEFAULT_CHARSET is set to a value based on the current system locale. For example, when the system locale is English (United States), it is set as ANSI_CHARSET.
Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font.
To ensure consistent results when creating a font, do not specify OEM_CHARSET or DEFAULT_CHARSET. If you specify a typeface name in the lpszFace parameter, make sure that the fdwCharSet value matches the character set of the typeface specified in lpszFace.
fdwOutputPrecision [in]
The output precision. The output precision defines how closely the output must match the requested font's height, width, character orientation, escapement, pitch, and font type. It can be one of the following values.
ValueMeaning
OUT_CHARACTER_PRECISNot used.
OUT_DEFAULT_PRECISThe default font mapper behavior.
OUT_DEVICE_PRECISInstructs the font mapper to choose a Device font when the system contains multiple fonts with the same name.
OUT_OUTLINE_PRECISThis value instructs the font mapper to choose from TrueType and other outline-based fonts.
OUT_PS_ONLY_PRECISInstructs the font mapper to choose from only PostScript fonts. If there are no PostScript fonts installed in the system, the font mapper returns to default behavior.
OUT_RASTER_PRECISInstructs the font mapper to choose a raster font when the system contains multiple fonts with the same name.
OUT_STRING_PRECISThis value is not used by the font mapper, but it is returned when raster fonts are enumerated.
OUT_STROKE_PRECISThis value is not used by the font mapper, but it is returned when TrueType, other outline-based fonts, and vector fonts are enumerated.
OUT_TT_ONLY_PRECISInstructs the font mapper to choose from only TrueType fonts. If there are no TrueType fonts installed in the system, the font mapper returns to default behavior.
OUT_TT_PRECISInstructs the font mapper to choose a TrueType font when the system contains multiple fonts with the same name.

Applications can use the OUT_DEVICE_PRECIS, OUT_RASTER_PRECIS, OUT_TT_PRECIS, and OUT_PS_ONLY_PRECIS values to control how the font mapper chooses a font when the operating system contains more than one font with a specified name. For example, if an operating system contains a font named Symbol in raster and TrueType form, specifying OUT_TT_PRECIS forces the font mapper to choose the TrueType version. Specifying OUT_TT_ONLY_PRECIS forces the font mapper to choose a TrueType font, even if it must substitute a TrueType font of another name.
fdwClipPrecision [in]
The clipping precision. The clipping precision defines how to clip characters that are partially outside the clipping region. It can be one or more of the following values.
ValueMeaning
CLIP_CHARACTER_PRECISNot used.
CLIP_DEFAULT_PRECISSpecifies default clipping behavior.
CLIP_DFA_DISABLEWindows XP SP1: Turns off font association for the font. Note that this flag is not guaranteed to have any effect on any platform after Windows Server 2003.
CLIP_EMBEDDEDYou must specify this flag to use an embedded read-only font.
CLIP_LH_ANGLESWhen this value is used, the rotation for all fonts depends on whether the orientation of the coordinate system is left-handed or right-handed.
If not used, device fonts always rotate counterclockwise, but the rotation of other fonts is dependent on the orientation of the coordinate system.
For more information about the orientation of coordinate systems, see the description of the nOrientation parameter
CLIP_MASKNot used.
CLIP_DFA_OVERRIDETurns off font association for the font. This is identical to CLIP_DFA_DISABLE, but it can have problems in some situations; the recommended flag to use is CLIP_DFA_DISABLE.
CLIP_STROKE_PRECISNot used by the font mapper, but is returned when raster, vector, or TrueType fonts are enumerated.
For compatibility, this value is always returned when enumerating fonts.
CLIP_TT_ALWAYSNot used.

fdwQuality [in]
The output quality. The output quality defines how carefully GDI must attempt to match the logical-font attributes to those of an actual physical font. It can be one of the following values.
ValueMeaning
ANTIALIASED_QUALITYFont is antialiased, or smoothed, if the font supports it and the size of the font is not too small or too large.
CLEARTYPE_QUALITYIf set, text is rendered (when possible) using ClearType antialiasing method. See Remarks for more information.
DEFAULT_QUALITYAppearance of the font does not matter.
DRAFT_QUALITYAppearance of the font is less important than when the PROOF_QUALITY value is used. For GDI raster fonts, scaling is enabled, which means that more font sizes are available, but the quality may be lower. Bold, italic, underline, and strikeout fonts are synthesized, if necessary.
NONANTIALIASED_QUALITYFont is never antialiased, that is, font smoothing is not done.
PROOF_QUALITYCharacter quality of the font is more important than exact matching of the logical-font attributes. For GDI raster fonts, scaling is disabled and the font closest in size is chosen. Although the chosen font size may not be mapped exactly when PROOF_QUALITY is used, the quality of the font is high and there is no distortion of appearance. Bold, italic, underline, and strikeout fonts are synthesized, if necessary.

If the output quality is DEFAULT_QUALITY, DRAFT_QUALITY, or PROOF_QUALITY, then the font is antialiased if the SPI_GETFONTSMOOTHING system parameter is TRUE. Users can control this system parameter from the Control Panel. (The precise wording of the setting in the Control panel depends on the version of Windows, but it will be words to the effect of "Smooth edges of screen fonts".)
fdwPitchAndFamily [in]
The pitch and family of the font. The two low-order bits specify the pitch of the font and can be one of the following values:
DEFAULT_PITCH
FIXED_PITCH
VARIABLE_PITCH
The four high-order bits specify the font family and can be one of the following values.
ValueMeaning
FF_DECORATIVENovelty fonts. Old English is an example.
FF_DONTCAREUse default font.
FF_MODERNFonts with constant stroke width, with or without serifs. Pica, Elite, and Courier New are examples.
FF_ROMANFonts with variable stroke width and with serifs. MS Serif is an example.
FF_SCRIPTFonts designed to look like handwriting. Script and Cursive are examples.
FF_SWISSFonts with variable stroke width and without serifs. MS?Sans Serif is an example.

An application can specify a value for the fdwPitchAndFamily parameter by using the Boolean OR operator to join a pitch constant with a family constant.
Font families describe the look of a font in a general way. They are intended for specifying fonts when the exact typeface requested is not available.
lpszFace [in]
A pointer to a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the terminating null character. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts. For more information, see the Remarks.
If lpszFace is NULL or empty string, GDI uses the first font that matches the other specified attributes.
Return Value
If the function succeeds, the return value is a handle to a logical font.
If the function fails, the return value is NULL.
Remarks
When you no longer need the font, call the DeleteObject function to delete it.
To help protect the copyrights of vendors who provide fonts for Windows, applications should always report the exact name of a selected font. Because available fonts can vary from system to system, do not assume that the selected font is always the same as the requested font. For example, if you request a font named Palatino, but no such font is available on the system, the font mapper will substitute a font that has similar attributes but a different name. Always report the name of the selected font to the user.
To get the appropriate font on different language versions of the OS, call EnumFontFamiliesEx with the desired font characteristics in the LOGFONT structure, then retrieve the appropriate typeface name and create the font using CreateFont or CreateFontIndirect .
The font mapper for CreateFont, CreateFontIndirect , and CreateFontIndirectEx recognizes both the English and the localized typeface name, regardless of locale.
The following situations do not support ClearType antialiasing:
Text rendered on a printer.
A display set for 256 colors or less.
Text rendered to a terminal server client.
The font is not a TrueType font or an OpenType font with TrueType outlines. For example, the following do not support ClearType antialiasing: Type 1 fonts, Postscript OpenType fonts without TrueType outlines, bitmap fonts, vector fonts, and device fonts.
The font has tuned embedded bitmaps, only for the font sizes that contain the embedded bitmaps. For example, this occurs commonly in East Asian fonts.
Examples
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{


case WM_PAINT:
{
RECT rect;
HBRUSH hBrush;
HFONT hFont;
hdc = BeginPaint(hWnd, &ps);

//Logical units are device dependent pixels, so this will create a handle to a logical font that is 48 pixels in height.
//The width, when set to 0, will cause the font mapper to choose the closest matching value.
//The font face name will be Impact.
hFont = CreateFont(48,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Impact"));
SelectObject(hdc, hFont);

//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100,100,700,200);
SetTextColor(hdc, RGB(255,0,0));
DrawText(hdc, TEXT("Drawing Text with Impact"), -1,&rect, DT_NOCLIP);

//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 20, will cause the font mapper to choose a font which, in this case, is stretched.
//The font face name will be Times New Roman. This time nEscapement is at -300 tenths of a degree (-30 degrees)
hFont = CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY, VARIABLE_PITCH,TEXT("Times New Roman"));
SelectObject(hdc,hFont);

//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 100, 200, 900, 800);
SetTextColor(hdc, RGB(0,128,0));
DrawText(hdc, TEXT("Drawing Text with Times New Roman"), -1,&rect, DT_NOCLIP);


//Logical units are device dependent pixels, so this will create a handle to a logical font that is 36 pixels in height.
//The width, when set to 10, will cause the font mapper to choose a font which, in this case, is compressed.
//The font face name will be Arial. This time nEscapement is at 250 tenths of a degree (25 degrees)
hFont = CreateFont(36,10,250,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, VARIABLE_PITCH,TEXT("Arial"));
SelectObject(hdc,hFont);
//Sets the coordinates for the rectangle in which the text is to be formatted.
SetRect(&rect, 500, 200, 1400, 600);
SetTextColor(hdc, RGB(0,0,255));
DrawText(hdc, TEXT("Drawing Text with Arial"), -1,&rect, DT_NOCLIP);
DeleteObject(hFont);

EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
For another example, see "Setting Fonts for Menu-Item Text Strings" in Using Menus .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWingdi.h (include Windows.h)
LibraryGdi32.lib
DLLGdi32.dll
Unicode and ANSI namesCreateFontW (Unicode) and CreateFontA (ANSI)
See Also
Fonts and Text Overview
Font and Text Functions
CreateFontIndirect
CreateFontIndirectEx
DeleteObject
EnumFonts
EnumFontFamilies
EnumFontFamiliesEx
SelectObject
EnumFontFamilies
LOGFONT
Send comments about this topic to Microsoft
Build date: 7/11/2009
==原始网址==http://msdn.microsoft.com/en-us/library/dd183499(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:24:17