Windows API一日一練(28)CreateFont函數

來源:互聯網
上載者:User
 文字的出現曆史可以追溯到甲骨文的使用,直到今天使用的宋體文字。在軟體開發裡,經常遇到是跨國語言的使用,由於世界在變平,全球在變小,交通運輸非常發達,由我所在的深圳,向東坐飛機12個小時就可以到達倫敦,向西坐飛機12小時就可以到達美國,可算得上朝發夕至。比如像炒外匯的人,一天可以不用睡覺都在工作著,比如早上炒東京的匯市,下午就可以炒倫敦的,晚上就可以炒紐約的了。軟體的開發,也在全球化,比如昨晚在美國開發,早上就可以變成中國開發同樣的軟體了,一天24小時開發,這樣加速軟體的開發。全球的市場已經變得同步化了,開發的軟體可以適應任何有人類的地方。經常開發的軟體,就需要有中英雙語化。這樣就需要使用到不同的字型,才能適應國際化的需要,下面就來學習怎麼樣建立字型,並且使用它。

函數CreateFont聲明如下:
WINGDIAPI HFONT   WINAPI CreateFontA( __in int cHeight, __in int cWidth, __in int cEscapement, __in int cOrientation, __in int cWeight, __in DWORD bItalic,
                             __in DWORD bUnderline, __in DWORD bStrikeOut, __in DWORD iCharSet, __in DWORD iOutPrecision, __in DWORD iClipPrecision,
                             __in DWORD iQuality, __in DWORD iPitchAndFamily, __in_opt LPCSTR pszFaceName);
WINGDIAPI HFONT   WINAPI CreateFontW( __in int cHeight, __in int cWidth, __in int cEscapement, __in int cOrientation, __in int cWeight, __in DWORD bItalic,
                             __in DWORD bUnderline, __in DWORD bStrikeOut, __in DWORD iCharSet, __in DWORD iOutPrecision, __in DWORD iClipPrecision,
                             __in DWORD iQuality, __in DWORD iPitchAndFamily, __in_opt LPCWSTR pszFaceName);
#ifdef UNICODE
#define CreateFont CreateFontW
#else
#define CreateFont CreateFontA
#endif // !UNICODE

cHeight是字型的高度。
cWidth是字型的寬度。
cEscapement是字型的傾斜角。
cOrientation是字型的傾斜角。
cWeight是字型的粗細。
bItalic是字型是否斜體。
bUnderline是字型是否有底線。
bStrikeOut是字型是否有刪除線。
iCharSet是字型使用的字元集。
iOutPrecision是指定如何選擇合適的字型。
iClipPrecision是用來確定裁剪的精度。
iQuality是怎麼樣跟選擇的字型相符合。
iPitchAndFamily是間距標誌和屬性標誌。
pszFaceName是字型的名稱。

調用這個函數的例子如下:
#001 //建立字型.
#002 //
#003 //蔡軍生 2007/09/03 QQ:9073204 深圳
#004 //
#005 HFONT CCaiWinMsg::GetFont(void)
#006 {
#007  LOGFONT lf; //字元的結構

#008
#009  //擷取當前系統的字型.
#010  GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT),
#011         &lf);
#012
#013  //設定字型的屬性.
#014  lf.lfWeight = FW_BOLD;
#015  lf.lfItalic = true;           
#016  lf.lfHeight = 26;
#017
#018  //設定為宋體.
#019  wsprintf(lf.lfFaceName,_T("%s"),_T("宋體"));
#020
#021  //建立字型並返回
#022  return CreateFont(lf.lfHeight, lf.lfWidth,
#023         lf.lfEscapement, lf.lfOrientation, lf.lfWeight,
#024         lf.lfItalic, lf.lfUnderline, lf.lfStrikeOut, lf.lfCharSet,
#025         lf.lfOutPrecision, lf.lfClipPrecision, lf.lfQuality,
#026         lf.lfPitchAndFamily, lf.lfFaceName);
#027
#028 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.