CreateFontIndirect,函式名。該函式創建一種在指定結構定義其特性的邏輯字型。這種字型可在後面的套用中被任何設備環境選作字型。
基本介紹
- 中文名:CreateFontIndirect
- Windows NT:3.1及以上版本
- Windows:95及以上版本
- Windows CE:1.0及以上版本
基本信息
程式示例
#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);}