Introduction
I was trying the variable type: __int64 in a simple dialog application and decided to make it useful
so I had it display the address range of 4 x 1 GB RAM chips.
Background
The framework in a simple dialog app. doesn't display strings very well, the spacing of characters is not good.
Therefore, I tried to change the Font to a True Type font. After a few failed attempts I came up with
a different solution, I'll get the string from the Static Window and reformat it to Courier New
and rewrite the string. GetClientRect($rc) gets the dialog box window not the Static Window.
Fine, let's use that. The code below shows the result.
Using the Code
The framework calls OnEraseBkgnd() before painting so I'll do it there.
BOOL CBigNumberDlg::OnEraseBkgnd(CDC* pDC)
{
CString szStr;
CWnd *pWnd;
CSize m_sizeCharScn;
CRect rct;
GetClientRect(&rct);
pDC->FillSolidRect(rct, RGB(135, 206, 250)); CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 18;
strcpy_s(lf.lfFaceName, sizeof("Courier New"), "Courier New");
lf.lfWeight = FW_BOLD;
font.CreateFontIndirect(&lf);
CFont *pOldFont = (CFont *)pDC->SelectObject(&font);
CBrush brush;
brush.CreateSolidBrush(RGB(135, 206, 250));
CBrush *pOldBrush = pDC->SelectObject(&brush);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
m_sizeCharScn.cy = tm.tmHeight + tm.tmExternalLeading;
m_sizeCharScn.cx = tm.tmAveCharWidth;
rct.left += m_sizeCharScn.cx * 2;
rct.top += m_sizeCharScn.cy * 6;
pDC->SetTextColor(RGB(0,0,96)); for(int index = 0; index < 4; index++)
{
switch(index) {
case 0: pWnd = GetDlgItem(IDC_STATIC_NUM);
break;
case 1: pWnd = GetDlgItem(IDC_STATIC_NUM_ONE);
break;
case 2: pWnd = GetDlgItem(IDC_STATIC_NUM_TWO);
break;
case 3: pWnd = GetDlgItem(IDC_STATIC_NUM_THREE);
break;
}
pWnd->GetWindowText(szStr);
pDC->TextOut(rct.left, rct.top, szStr);
rct.top += m_sizeCharScn.cy;
}
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldFont);
return FALSE;
}
Also, have the program hide the Static Window that code is next:
void CBigNumberDlg::OnBnClickedHide()
{
CWnd *pWnd;
for(int index = 0; index > 4; index++)
{
switch(index) {
case 0: pWnd = GetDlgItem(IDC_STATIC_NUM);
break;
case 1: pWnd = GetDlgItem(IDC_STATIC_NUM_ONE);
break;
case 2: pWnd = GetDlgItem(IDC_STATIC_NUM_TWO);
break;
case 3: pWnd = GetDlgItem(IDC_STATIC_NUM_THREE);
break;
}
Sleep(250); pWnd->ShowWindow(SW_HIDE);
}
}
Points of Interest
CString.Format(...)is a little scrary till you read the Help Library.
szStr.Format(_T("%0.10I64d = 0x0%0.8I64X to (%0.10I64d)-1 = 0x0%0.8I64X"),
m_nLow, m_nLow, m_nHigh, m_nHigh-1);
History
BigNumber Version 1.0 Feb, 28, 2011