MFC
CStatic 폰트 크기, 글씨 굵기 등 변경하기.
전념하자
2020. 10. 20. 16:43
반응형
폰트를 변경하는 여러 가지 방법보다 가장 중요한 한 가지 먼저!!!
폰트 관련 변수인 newFont를 클래스 멤버 변수로 선언해야 폰트 적용이 잘 됩니다.
newFont를 로컬 변수로 생성했더니, 폰트 변경하는 그 어떤 코드도 적용이 안 되더군요!!!
당연한 건데, 또 나만 몰랐나?? 오랜만에 MFC 했더니, 매우 번거롭습니다. ㅎㅎ
TestDlg.h
class TestDlg : public CDialog{
......
public:
virtual BOOL OnInitDialog();
private:
CFont newFont;
......
}
TestDlg.cpp
......
BOOL TestDlg::OnIOnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CFont *currentFont = this->GetFont();
LOGFONT logFont;
currentFont->GetLogFont(&logFont);
//-----------------------------------------------
// 폰트관련 설정 변경 및 새로운 폰트 생성.
logFont.lfHeight = 15;
logFont.lfWeight = FW_BOLD;
this->newFont.CreateFontIndirectW(&logFont);
//-----------------------------------------------
// 새로운 폰트 적용
this->GetDlgItem(IDC_STATUS_MESSAGE)->SetFont(&this->newFont);
}
......
LOGFONT 속성은 여기에서 확인 가능합니다.
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfonta
LOGFONTA (wingdi.h) - Win32 apps
The LOGFONT structure defines the attributes of a font.
docs.microsoft.com
반응형