반응형
작성중
1.
먼저 이벤트를 만들기 전에 Button의 속성중에서 "Style - Owner Draw(동작 - 소유자 그리기)"를 true로 해주어야합니다.
2. ~.h 에 추가 할거
public:
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
3.~.pp 에 추가 할거
BEGIN_MESSAGE_MAP(CDLG_Task, CDialog)
// 생략
// ON_WM_CTLCOLOR()
ON_WM_DRAWITEM() // OnDrawItem() 에 필요
// 생략
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////
// Button Color
void CDlg_Set::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) {
int m;
switch (nIDCtl) {
case IDC_task_BUT_Out1:
m = (m_pDlg -> m_useOut & 1) != (m_pDlg -> m_useOut_Old & 1);
break;
case IDC_task_BUT_Out2:
m = (m_pDlg -> m_useOut & 2) != (m_pDlg -> m_useOut_Old & 2);
break;
case IDC_task_BUT_Out3:
m = (m_pDlg -> m_useOut & 4) != (m_pDlg -> m_useOut_Old & 4);
break;
case IDC_task_BUT_Out4:
m = (m_pDlg -> m_useOut & 8) != (m_pDlg -> m_useOut_Old & 8);
break;
}
switch (nIDCtl) {
case IDC_task_BUT_Out1:
case IDC_task_BUT_Out2:
case IDC_task_BUT_Out3:
case IDC_task_BUT_Out4:
CDC dc;
RECT rect;
dc.Attach(lpDrawItemStruct -> hDC); //Get the Button DC to CDC
rect = lpDrawItemStruct -> rcItem; //Store the Button rect to local rect
if (m) {
dc.Draw3dRect( & rect, RGB(200, 200, 200), RGB(20, 20, 20));
dc.FillSolidRect( & rect, RGB(255, 255, 0)); // 바닥 빛깔
} else {
dc.Draw3dRect( & rect, RGB(200, 200, 200), RGB(20, 20, 20));
dc.FillSolidRect( & rect, RGB(255, 255, 255));
}
//Show the Effect of Click Event
UINT state = lpDrawItemStruct -> itemState;
if ((state & ODS_SELECTED)) {
dc.DrawEdge( & rect, EDGE_SUNKEN, BF_RECT);
} else {
dc.DrawEdge( & rect, EDGE_RAISED, BF_RECT);
}
//Draw Color Text
if (m) {
dc.SetBkMode(TRANSPARENT); // dc.SetBkColor(RGB(255,255,0)); //Setting the Text Background Color
dc.SetTextColor(RGB(255, 0, 0)); //Setting the Text Color, 글자 빛깔
} else {
dc.SetBkMode(TRANSPARENT); // dc.SetBkColor(RGB(255,255,0)); //Setting the Text Background Color
dc.SetTextColor(RGB(0, 0, 0)); //Setting the Text Color
}
TCHAR buffer[MAX_PATH];
ZeroMemory(buffer, MAX_PATH);::GetWindowText(lpDrawItemStruct -> hwndItem, buffer, MAX_PATH);
dc.DrawText(buffer, & rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dc.Detach(); //Detach the Button DC break;
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
반응형
'개발 > mfc' 카테고리의 다른 글
mfc, enter, esc key 처리 (0) | 2024.02.13 |
---|---|
mfc: CString 비교 - 작업중 (0) | 2024.01.18 |
Mfc EditBox 글자 지우며 마지막에 쓰기, sample source (2) | 2023.12.06 |
[mfc] UDP,TCP server, client sample source (0) | 2023.11.27 |
mfc UpdateData (0) | 2023.11.17 |