본문 바로가기

MFC

CStatic 폰트 크기, 글씨 굵기 등 변경하기.

반응형

폰트를 변경하는 여러 가지 방법보다 가장 중요한 한 가지 먼저!!!

 

폰트 관련 변수인 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

 

반응형

'MFC' 카테고리의 다른 글

CDC로 화면에 출력할 글자 길이 구하기.  (0) 2021.11.25
InstallShield 2013 timestamp error 1027  (0) 2021.07.02