Share via


建立邏輯字型

您可以使用 [ 型通用] 對話方塊來顯示可用的字型。 在應用程式初始化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); 
}