Share via


Création d’une police logique

Vous pouvez utiliser la boîte de dialogue Police commune pour afficher les polices disponibles. La boîte de dialogue ChooseFont s’affiche après qu’une application initialise les membres d’une structure CHOOSEFONT et appelle la fonction CHOOSEFONT . Une fois que l’utilisateur a sélectionné l’une des polices disponibles et appuyé sur le bouton OK , la fonction ChooseFont initialise une structure LOGFONT avec les données pertinentes. Votre application peut ensuite appeler la fonction CreateFontIndirect et créer une police logique basée sur la demande de l’utilisateur. L’exemple suivant montre comment procéder.

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); 
}