빛깔 색 변경 관련 글 입니다.
Static Text 글자,바닦에 빛깔 입히기 본글
button 글자,바닦에 빛깔 입히기 색 변경 https://bahk33.tistory.com/87
========================================
Static Text 글자,바닦에 빛깔 입히기
목차
1. 'WM_CTLCOLOR' 추가
2. header 파일 수
3. OnCtlColor 수정 하기
4. 혹시 글자 빛깔이 안바뀌면
-------------------------------------------------
1. '클래스 마법사' 창의 '메시지' 탭에서 'WM_CTLCOLOR' 추가 하기
1) Resource View 에서 다이알 로그 선택 하여 띄운뒤 마우스 오른쪽 버튼을 눌러 "Class Wizard" 를 띄우셔요
아니면, 'CTRL + SHIFT + X'

2) Class Name 을 확인 하시고, Message Tab 을 누른뒤 ' WM_CTLCOLOR ' 를 찾아 추가 하셔요
3) 그럼 MESSAGE_MAP 에 ON_WM_CTLCOLOR() 가 추가 되어 있는 것을 확인 할 수 있읍니다.
BEGIN_MESSAGE_MAP(CDLG_Task, CDialog)
: 생략
ON_WM_CTLCOLOR()
: 생략
END_MESSAGE_MAP()
2. .h 에서 빛깔 변수 만들기
CBrush m_redbrush,m_bluebrush, m_yellowbrush, m_blackBrush;
3. .cpp 파일
1) OnInitDialog() 에서 변수 값 지정 하기
// m_textcolor=RGB(255,255,255); // white text
m_redbrush.CreateSolidBrush ( RGB(255,0,0) ); // red background
m_bluebrush.CreateSolidBrush ( RGB(0,0,255) ); // blue background
m_yellowbrush.CreateSolidBrush( RGB(255,255,0) ); // Yellow background
m_blackBrush.CreateSolidBrush ( RGB(0,0,0) ); // black background
2). 실행 함수( OnCtlColor ) 수정 하기
HBRUSH CDLG_Task::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int m;
m=1;
switch ( pWnd->GetDlgCtrlID() ){
case IDC_STATIC_Test1:
// 일단 기본 빛깔 지정
pDC->SetTextColor(RGB(255, 255, 255)); // change the text color
pDC->SetBkMode(TRANSPARENT); // make background transparent [only affects the TEXT itself]
// 조건에 따라 다른 빛깔 지정
if(m==1) {
// pDC->SetBkColor(m_redcolor); // change the background
hbr = (HBRUSH) m_bluebrush; // apply the blue brush, m_redbrush m_bluebrush
}else if (m==2) {
pDC->SetTextColor(RGB(0, 0, 0)); // change the text color
hbr = (HBRUSH) m_yellowbrush; // apply the blue brush, [this fills the control rectangle]
} else {
// pDC->SetBkColor(m_redcolor); // change the background
hbr = (HBRUSH) m_redbrush; // apply the blue brush, [this fills the control rectangle]
}
break;
}
return hbr;
}
4. 혹시 글자 빛깔이 안바뀌면
원래는 위와 같이 하면 바뀌어 하는데, 안바뀌어서,
혹시나 하고 다시 써 줬더니 바뀌었읍니다.
SetDlgItemText( IDC_STATIC_Test1, _T("123"));
뭔가 트리거를 줘야 하는데, 정상 적인 방법은 뭔지 모르겠네요.
~~~~~~~~~~~~~~~~~~~~~~``
수고 하셨읍니다.
'개발 > mfc' 카테고리의 다른 글
| win32 경과 시간을 계산, GetTickCount, GetSystemTimeAsFileTime 등 (0) | 2025.09.09 |
|---|---|
| visual studio 에서 dos (win32) project 시작 하기 (0) | 2025.09.08 |
| mfc: Rich Edit Control 2 쓰기 (6) | 2025.08.25 |
| mfc, 일반 Class 추가 하기 (0) | 2024.12.16 |
| mfc, Visual Studio project 명, 이름 변경하기 (1) | 2024.11.18 |