-
Changing Font
I subclassed a CListCntrl so I could control the color of text in each cell. Now I want to change the font for the entire control. Do I do this in my control or the app where I'm formating the data.
int i;
CString CSTemp;
CRect CRectText;
CString szBuffer;
int nPointSize;
CString CStrFaceName;
CFont fntArial;
// Create font
nPointSize = -12;
CStrFaceName = "Arial";
// Create a memory DC.
CDC dcMem;
CDC *pDC = GetDC();
dcMem.CreateCompatibleDC(pDC);
GetClientRect(CRectText);
pDC->DPtoLP(CRectText);
fntArial.CreateFont(nPointSize,0,0,0,FW_REGULAR,0,0,0,
0,0,0,0,0, CStrFaceName);
CFont* pOldFont = pDC->SelectObject(&fntArial);
// Create the rows of the list control
for(i=0; i<10; i++)
{
CSTemp.Format("%d", i);
m_List.InsertItem(i,CSTemp);
}
// Write Data
for(i=0; i<10; i+=2)
{
CSTemp.Format("%s", "PASS");
m_List.m_CellColor[i][1] = RGB(0,168,0);
m_List.SetItemText(i,1,CSTemp);
}
// Write Data
for(i=1; i<10; i+=4)
{
CSTemp.Format("%s", "FAIL");
m_List.m_CellColor[i][1] = RGB(255,0,0);
m_List.SetItemText(i,1,CSTemp);
}
// Write Data
for(i=3; i<10; i+=4)
{
CSTemp.Format("%s", "Degraded");
m_List.m_CellColor[i][1] = RGB(226,232,21);
m_List.SetItemText(i,1,CSTemp);
}
The data appears in the control and the right color but the font never changes.