CEdit自绘点

就几个点:

背景色,字体颜色,字体大小,

注意的是字体大小最好用WM_SETFONT来处理,我也是在挂钩时打印消息发现了它,直接看MSDN就知道怎么发送了。

代码:

HBRUSH CSkinEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
     m_Brush.DeleteObject();
	 m_Brush.CreateSolidBrush(m_BkClr);
	 pDC->SetBkColor(m_BkClr);
	 pDC->SetTextColor(m_TextClr);

	return (HBRUSH)m_Brush;
}

必须return 一个HBRUSH对象,表示你设置了,不然设置无效

void CSkinEdit::SetTextFont(LONG FontHeight, CString szFontName, int FontType)
{
	BOOL bRedraw = FALSE;
	if ((FontHeight != m_FontHeight)&&FontHeight)
	{
		m_FontHeight = FontHeight;
		bRedraw = TRUE;
	}
	if (!szFontName.IsEmpty()&&(m_szFontName != szFontName))
	{
		m_szFontName = szFontName;
		bRedraw = TRUE;
	}
	if(FontType != m_FontType)
	{
		m_FontType = FontType;
		bRedraw = TRUE;
	}

	if (bRedraw)
	{
		LOGFONT lf;
		m_Font.GetLogFont(&lf);

		lf.lfHeight = m_FontHeight;   
		lf.lfWeight = m_FontType;  

		memcpy(lf.lfFaceName, m_szFontName.GetBuffer(LF_FACESIZE), LF_FACESIZE);
		m_szFontName.ReleaseBuffer(LF_FACESIZE);

		m_Font.DeleteObject();
		m_Font.CreateFontIndirect(&lf);

		SendMessage(WM_SETFONT, (WPARAM)((HFONT)m_Font), MAKELPARAM(TRUE, 0));
	}
}


szFontName可以是TEXT("Arial"),TEXT("宋体")
原文地址:https://www.cnblogs.com/hgy413/p/3693592.html