Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As I know,everyone can create a font by using the function CreateFont .But the problem is I cannot get a font that I really want.For example ,I create a log font using the LOGFONT and set lfPitchAndFamily field with VARIABLE_PITCH ,so every glyph in the font should be not same width with each other,but the result is when I print character "i" and "m" ,I find that their width is equal. Why this happened?

[Edit by Jochen Arndt: Added code posted as comment]
HFONT 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 = (LPWSTR)NULL;
    cf.hInstance = (HINSTANCE) NULL;
    cf.lpszStyle = (LPWSTR)NULL;
    cf.nFontType = SCREEN_FONTTYPE;
    cf.nSizeMin = 0;
    cf.nSizeMax = 0;
    
    // Display the CHOOSEFONT common-dialog box.
    
    ChooseFont(&cf);//select a font form the list ChooseFontDialog of MS's CommDlg
    
    // Create a logical font based on the user's
    // selection and return a handle identifying
    // that font.
    //cf.lpLogFont->lfOutPrecision=OUT_TT_ONLY_PRECIS;
    int err = GetLastError();
    cf.lpLogFont->lfHeight=15;
    cf.lpLogFont->lfPitchAndFamily=2;//set not seam width
    hfont = CreateFontIndirect(cf.lpLogFont);
    err = GetLastError();
    if(err>0)
    {
        MessageBox(NULL,L"Failed",L"wrong",MB_OK);
    }
    return (hfont);
} 
Posted
Updated 21-Sep-15 0:39am
v2
Comments
Jochen Arndt 21-Sep-15 5:25am    
Show your code. Especially which face you are passing to CreateFont().
codeprojectddx 21-Sep-15 6:32am    
HFONT 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 = (LPWSTR)NULL;
cf.hInstance = (HINSTANCE) NULL;
cf.lpszStyle = (LPWSTR)NULL;
cf.nFontType = SCREEN_FONTTYPE;
cf.nSizeMin = 0;
cf.nSizeMax = 0;

// Display the CHOOSEFONT common-dialog box.

ChooseFont(&cf);//select a font form the list ChooseFontDialog of MS's CommDlg

// Create a logical font based on the user's
// selection and return a handle identifying
// that font.
//cf.lpLogFont->lfOutPrecision=OUT_TT_ONLY_PRECIS;
int err = GetLastError();
cf.lpLogFont->lfHeight=15;
cf.lpLogFont->lfPitchAndFamily=2;//set not seam width
hfont = CreateFontIndirect(cf.lpLogFont);
err = GetLastError();
if(err>0)
{
MessageBox(NULL,L"Failed",L"wrong",MB_OK);
}
return (hfont);
}

What I want, what I really really want...

Your question is not really informative, and we can't know what you want.

Try learning how to use the font creation tools first.
 
Share this answer
 
You are using ChooseFont to select the font. So you will get what you select there. If you select a fixed width font like Courier, setting lfPitchAndFamily afterwards to 2 will have no effect.

If you want only proprtional fonts to be listed, set lf.lfPitchAndFamily to 2 and add CF_INITTOLOGFONTSTRUCT to cf.Flags before calling ChooseFont.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900