-
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); }
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:10次歷史版本
- 最近更新: 晓晓娟娟888