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)
{
Delete_Font(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);
fflush(fp1);
FontX = cursfont.lfHeight;
FontY = cursfont.lfWidth;
}
void Delete_Font(HBRUSH ADC)
{
if (Font == TRUE)
{
SelectObject(ADC, holdsfont);
DeleteObject(hnewsfont);
}
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?