mfc_EditCtrl_Color_2 - 8BitsCoding/RobotMentor GitHub Wiki
ν΄λμ€ λ§λ²μ¬ -> MFC ν΄λμ€ μΆκ° -> CEdit ν΄λμ€ μΆκ°
μλ‘ μΆκ°ν MFC ν΄λμ€μ CTLCOLOR, KillFocus λ©μμ§ μΆκ°
// TW_Edit.h
HBRUSH mh_edit_bk_brush;
HBRUSH TW_Edit::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetTextColor(RGB(255, 0, 0));
HWND cur_focus = ::GetFocus();
if (cur_focus == m_hWnd) {
pDC->SetBkColor(RGB(0, 255, 0));
}
else
{
pDC->SetBkColor(RGB(0, 0, 255));
}
return mh_edit_bk_brush;
}
void TW_Edit::OnEnKillfocus()
{
Invalidate();
}
// Dlg.h
TW_Edit m_my_edit[6];
BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// μ΄ λν μμμ μμ΄μ½μ μ€μ ν©λλ€. μμ© νλ‘κ·Έλ¨μ μ£Ό μ°½μ΄ λν μμκ° μλ κ²½μ°μλ
// νλ μμν¬κ° μ΄ μμ
μ μλμΌλ‘ μνν©λλ€.
SetIcon(m_hIcon, TRUE); // ν° μμ΄μ½μ μ€μ ν©λλ€.
SetIcon(m_hIcon, FALSE); // μμ μμ΄μ½μ μ€μ ν©λλ€.
// TODO: μ¬κΈ°μ μΆκ° μ΄κΈ°ν μμ
μ μΆκ°ν©λλ€.
for (int i = 0; i < 6; i++) {
SetDlgItemText(IDC_EDIT1+i, L"μλ
νμΈμ~");
m_my_edit[i].SubclassDlgItem(IDC_EDIT1 + i, this);
}
return TRUE; // ν¬μ»€μ€λ₯Ό 컨νΈλ‘€μ μ€μ νμ§ μμΌλ©΄ TRUEλ₯Ό λ°νν©λλ€.
}
void TW_Edit::ChangeColor(COLORREF a_active_text_color, COLORREF a_normal_text_color, COLORREF a_bk_color)
{
m_active_text_color = a_active_text_color;
m_normal_text_color = a_normal_text_color;
m_bk_color = a_bk_color;
}
// Dlg.cpp
m_my_eidt[0].ChangeColor(RGB(0,0,0), RGB(128,0,0), RGB(0,0,128));