最佳答案:
CreateFontIndirect,函数名。该函数创建一种在指定结构定义其特性的逻辑字体。这种字体可在后面的应用中被任何设备环境选作字体。
详情介绍
CreateFontIndirect,函数名。该函数创建一种在指定结构定义其特性的逻辑字体。这种字体可在后面的应用中被任何设备环境选作字体。

- 中文名
- CreateFontIndirect
- Windows NT
- 3.1及以上版本
- Windows
- 95及以上版本
- Windows CE
- 1.0及以上版本
CreateFontIndirect基本信息
函数原型:HFONT CreateFontIndirect(ConST LOGFONT *lplf);
参数:

lplf:指向定义此逻辑字体特性的LOGFONT结构的指针。
返回值:如果函数调用成功,返回值是逻辑字体的句柄;如果函数调用失败,返回值是NULL。
Windows NT:若想获得更多的错误信息,请调用GetLastError函数。

备注:函数CreateFontIndirect创建一种在结构LOGFONT中定义特性的逻辑字体。当这种字体被函数选择时,GDI的字体映射器会努力将此逻辑字体与现有物理字体相匹配,如果不能找到精确匹配,将会提供另一种选择,其特性与所要求的特性尽可能地匹配。
当一种字体不再需要使用时,可调用DeleteObject删除它。
Windows CE:1.0版本只支持光栅字体。Windows CE版本2.0支持使用TrueType字体和光栅字体其中之一的系统。字体类型(光栅或TrueType)是在系统设计时就已选择,不能被应用程序改变。
速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;头文件:wingdi.h;库文件:gdi32.lib;Unicode:在Windows NT环境下以Unicode和ANSI两种方式实现。
CreateFontIndirect程序示例
#include <windows.h>#include <tchar.h>int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hInstPrev,#ifdef UNDER_CE LPWSTR pszCmdLine,#else LPSTR pszCmdLine,#endif int nCmdShow){// This retrieves the device context (DC) for the primary display driver. This is not associated with a window.// This is only used for simplicity of the example. HDC hdc = GetDC(NULL); int nSmooth, nOldSmooth;// A rectangle to hold the text. RECT rc = { 10, 10, 100, 100}; LOGFONT lf; HFONT hFontNew, hFontOld; int nTextHeight;// Clear out the lf structure to use when creating the font. memset(&lf, 0, sizeof(LOGFONT));// Retrieve the old Cleartype gamma. SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &nOldSmooth, FALSE);// Draw text with the default system font. First calculate the size of the rectangle to use. DrawText(hdc, TEXT("This is the default system font."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP); DrawText(hdc, TEXT("This is the default system font."), -1, &rc, DT_LEFT | DT_TOP);// Draw a Cleartype font with a font smoothing of 1000. nSmooth = 1000; SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, &nSmooth, FALSE); nTextHeight = rc.bottom - rc.top; top += nTextHeight; bottom += nTextHeight; lfQuality = CLEARTYPE_QUALITY; hFontNew = CreateFontIndirect(&lf); hFontOld = (HFONT) SelectObject(hdc, hFontNew); DrawText(hdc, TEXT("This is a ClearType font w/ 1000 font smoothing."), -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP); DrawText(hdc, TEXT("This is a ClearType font w/ 1000 font smoothing."), -1, &rc, DT_LEFT | DT_TOP); SelectObject(hdc, hFontOld); DeleteObject(hFontNew);// Sleep 20 seconds to let the user see the text. Sleep(20000); SystemParametersInfo(SPI_SETFONTSMOOTHINGCONTRAST, 0, &nOldSmooth, FALSE); DeleteDC(hdc);}

