Re: Fonts and Colors for Static Text Controls with MFC

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Use SetBkMode(TRANSPARENT).

Tom wrote:
I try so change font appearance and text colors using eVC++ 4 and MFC. Unfortunately it works not the way I think it should:


BOOL CMtrackerDlg::OnInitDialog() { CDialog::OnInitDialog();

SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow());


CClientDC dc(&m_DataSourceName_Static);
COLORREF cr = dc.GetTextColor();
cr = RGB(255,0,0);
dc.SetTextColor(cr);
m_DataSourceName_Static.SetWindowText(L"Test text ");
/*
CFont* pFont = m_DataSourceName_Static.GetFont();
LOGFONT lf;
pFont->GetLogFont(&lf);
lf.lfWeight = 900;
pFont->CreateFontIndirect(&lf);
m_DataSourceName_Static.SetFont(pFont);
*/
return TRUE;
}


m_DataSourceName_Static is of type CStatic. The text still displays black instead of read.

With the font I am also unlucky:

CFont* pFont = m_DataSourceName_Static.GetFont();

returns a NULL pointer.

What am I doing wrong??

Tom
.