I am converting a program written using Borland Turbo C to M$ Visual C++ 2010.
I have created a Win32 application, and have now managed to write to a window. But the font that has come out is a proportional one, and I need a fixed font for everything to line up.
I have used the code that the Borland application used to change the font but I am getting an error that I cannot figure out.

void MakeFont(HDC ADC)
    cursfont.lfHeight         =  FONTSIZE;
    cursfont.lfWidth          =  FONTSIZE;

    cursfont.lfEscapement     =  0;
    cursfont.lfOrientation    =  0;
    cursfont.lfWeight         =  FW_NORMAL;
    cursfont.lfItalic         =  FALSE;
    cursfont.lfUnderline      =  FALSE;
    cursfont.lfStrikeOut      =  FALSE;
    cursfont.lfCharSet        =  ANSI_CHARSET;
    cursfont.lfOutPrecision   =  OUT_DEFAULT_PRECIS;
    cursfont.lfClipPrecision  =  CLIP_DEFAULT_PRECIS;
    cursfont.lfQuality        =  DEFAULT_QUALITY;
    cursfont.lfPitchAndFamily =  FIXED_PITCH | FF_DONTCARE;
    strcpy_s((char *)cursfont.lfFaceName, 12, "Courier New");

    hnewsfont = CreateFontIndirect(&cursfont);

    holdsfont = (HFONT)(SelectObject(ADC, (HGDIOBJ)hnewsfont));          // latest attempt
//  holdsfont = SelectObject(ADC, (HGDIOBJ)hnewsfont);                   // attempt 1
//	holdsfont = (HFONT)SelectObject(ADC, (HGDIOBJ)(HFONT)hnewsfont); // original
    Font = TRUE;
    fprintf(fp1, "Font height and width = %d %d\n",
        cursfont.lfHeight, cursfont.lfWidth);

    FontX = cursfont.lfHeight;
    FontY = cursfont.lfWidth;

void Delete_Font(HBRUSH ADC)
    if (Font == TRUE)
        SelectObject(ADC, holdsfont);
    Font = FALSE;

The error I am getting is:

1>c:\users\norman\documents\visual studio 2010\projects\test5\test5\test5.cpp(815): error C2664: 'SelectObject' : cannot convert parameter 1 from 'HBRUSH' to 'HDC'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I have tried various options as shown but they all come up with the same error.
What am I doing wrong?

5 Years
Discussion Span
Last Post by amyuni

The error is in function Delete_Font where ADC is an argument of type HBRUSH instead of HDC.


cursfont.lfWidth = FONTSIZE;
should also be changed to
cursfont.lfWidth = 0;

Your font will look either condensed or stretched if the value you set in lfWidth does not match the average character width of that font.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.