how to change the font for a label
-
Hi, I tried to change the font of a label using SelectObject but it don't work. The SelectObject works if I use TextOut(...). But for label or edit, I use SetDlgItemText(..). So how to change the fonts used for edit/label or is there anything that I did it wrongly. Thanks. code that I use ======================== HDC hDC = GetDC(); hFont = CreateFont(....) HFONT hFontOld = (HFONT)SelectObject( hDC, hFont); TextOut(....) DelectObject(hFont) SelectObject(hDC, hFontOld);
-
Hi, I tried to change the font of a label using SelectObject but it don't work. The SelectObject works if I use TextOut(...). But for label or edit, I use SetDlgItemText(..). So how to change the fonts used for edit/label or is there anything that I did it wrongly. Thanks. code that I use ======================== HDC hDC = GetDC(); hFont = CreateFont(....) HFONT hFontOld = (HFONT)SelectObject( hDC, hFont); TextOut(....) DelectObject(hFont) SelectObject(hDC, hFontOld);
i think this way could work: overwrite or go into InitDialog (WM_INITDIALOG) and set here the font for the label. I hope that is correct, because it's only a part of 16-bit-code-application (MFC). I believe IDC_ErrorA was a Label. //define at the top of your cpp-file CFont m_biggerFont; //must be are here, global in View for Paint() void Cxx_View::OnInitialUpdate() { LOGFONT logfont; CRect rect; // get edit control size GetDlgItem(IDC_ErrorA)->GetWindowRect(&rect); ScreenToClient(&rect); // in parent coordinate memset(&logfont, 0, sizeof(logfont)); logfont.lfHeight = int ((rect.bottom-rect.top)); logfont.lfWeight = FW_BOLD; switch(FontType) { case 0: strcpy(logfont.lfFaceName, "MS Sans Serif");break; default: strcpy(logfont.lfFaceName, "MS Sans Serif"); } VERIFY(m_biggerFont.CreateFontIndirect(&logfont)); GetDlgItem(IDC_BigA)->SetFont(&m_biggerFont,TRUE); GetDlgItem(IDC_BigA)->UpdateWindow(); ... }