MFC

修改静态文本框字体颜色

c++

Posted by YiMiTuMi on December 30, 2022

修改静态文本框字体颜色

xxx.h

afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

xxx.cpp

//添加事件
ON_WM_CTLCOLOR()

//实现函数
HBRUSH xxx::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性
	if (nCtlColor == CTLCOLOR_STATIC)
	{
		switch (pWnd->GetDlgCtrlID())
		{
		case IDC_STATIC_xxx_HINT: //文本框ID
		{
			pDC->SetBkMode(TRANSPARENT);
			//pDC->SetTextColor(RGB(0,191,243));
			pDC->SetTextColor(RGB(55, 101, 189)); //设置颜色
		}
		break;
		}
	}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}