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));