Font trouble with VS VC++ 6.0 continued - TechRepublic
General discussion
April 24, 2001 at 07:19 AM
ulrika.cooper

Font trouble with VS VC++ 6.0 continued

by ulrika.cooper . Updated 25 years, 2 months ago

//Call FitFont() once for each of the 100 boxes.

void CParmBox::FitFont()
{
m_data_font = new CFont;

int fontwidth = (long)((m_rectLP.right – m_rectLP.left) / (m_numdigits * 1.5));
int fontheight = (long)(m_rectLP.bottom – m_rectLP.top);
m_data_font->CreateFont(fontheight, fontwidth, 0, 0, 1000, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH|FF_SWISS, “Arial”);

m_name_font = new CFont;

fontwidth = (long)((m_rectLP.right – m_rectLP.left) / 16);
fontheight = (long)(fontheight * .40);

m_name_font->CreateFont(fontheight, fontwidth, 0, 0, 1000, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH|FF_SWISS, “Roman”);
}

//Call ShowData() 4 times a second for each of the 100 boxes .

void CParmBox::ShowData(CDC* pDC, double v)
{
CString temp;
CString fmt;

COLORREF bkColor;
CBrush bkBrush;

//Set the Alarm color
bkColor = AlarmStatus(v);
bkBrush.CreateSolidBrush(bkColor);

//Fill the box and format the value
pDC->FillRect(&m_rectLP, &bkBrush);
pDC->SetBkColor(bkColor);
pDC->SetTextColor(RGB(0, 0, 0));

//Build a user defined format specifier
fmt.Format(“%%8.%df”, m_numdecimals);
temp.Format(fmt, (float)v);

//Draw to the box
CFont* pOldFont = pDC->SelectObject(m_data_font);
pDC->SetTextAlign(TA_TOP|TA_CENTER);
pDC->DrawText(temp, 8, m_rectLP, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SelectObject(pOldFont);
}

//Call ShowName() if user selects to do so

void CParmBox::ShowName(CDC* pDC)
{
CFont* pOldFont = pDC->SelectObject(m_name_font);
pDC->SetBkColor(RGB(0, 0, 255));
pDC->SetTextColor(RGB(255, 255, 0));
pDC->SetTextAlign(TA_BOTTOM|TA_CENTER);
pDC->TextOut(m_rectLP.left + ((m_rectLP.right – m_rectLP.left) / 2), m_rectLP.top, m_Name);
pDC->SelectObject(pOldFont);
}

This discussion is locked

All Comments