建立邏輯字型
您可以使用 字型 通用對話框來顯示可用的字型。 應用程式初始化 CHOOSEFONT結構的成員,並呼叫CHOOSEFONT 函式之後,會顯示 [ChooseFont] 對話框。 用戶選取其中一個可用的字型,然後按 [確定] 按鈕之後,ChooseFont 函式會使用相關數據初始化 LOGFONT 結構。 然後,您的應用程式可以呼叫 CreateFontIndirect 函式,並根據使用者的要求建立邏輯字型。 下列範例示範如何完成此作業。
HFONT FAR PASCAL MyCreateFont( void )
{
CHOOSEFONT cf;
LOGFONT lf;
HFONT hfont;
// Initialize members of the CHOOSEFONT structure.
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = (HWND)NULL;
cf.hDC = (HDC)NULL;
cf.lpLogFont = &lf;
cf.iPointSize = 0;
cf.Flags = CF_SCREENFONTS;
cf.rgbColors = RGB(0,0,0);
cf.lCustData = 0L;
cf.lpfnHook = (LPCFHOOKPROC)NULL;
cf.lpTemplateName = (LPSTR)NULL;
cf.hInstance = (HINSTANCE) NULL;
cf.lpszStyle = (LPSTR)NULL;
cf.nFontType = SCREEN_FONTTYPE;
cf.nSizeMin = 0;
cf.nSizeMax = 0;
// Display the CHOOSEFONT common-dialog box.
ChooseFont(&cf);
// Create a logical font based on the user's
// selection and return a handle identifying
// that font.
hfont = CreateFontIndirect(cf.lpLogFont);
return (hfont);
}