我在工程里添加了一个类,CMyEdit继承了CEdit。我重载了CtlColor方法想改变文本框的字体,可是不起作用为什么呢?是不是我哪里缺少代码?
代码:
MyEdit.h
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);MyEdit.cpp
HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0xff,0xff,0xff));
return m_brHollow;
}调用代码:
void CSDIView4::AddMsgToEdit(CString str)
{
//追加字符串
int nLength = my_showMsg.SendMessage(WM_GETTEXTLENGTH);
my_showMsg.SetSel(nLength, nLength);
my_showMsg.ReplaceSel(str);
}
代码:
MyEdit.h
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);MyEdit.cpp
HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0xff,0xff,0xff));
return m_brHollow;
}调用代码:
void CSDIView4::AddMsgToEdit(CString str)
{
//追加字符串
int nLength = my_showMsg.SendMessage(WM_GETTEXTLENGTH);
my_showMsg.SetSel(nLength, nLength);
my_showMsg.ReplaceSel(str);
}
可是不行!
建议用数据流把lf存进去,用的时候再读出来
CFont font1;在你的对话框中BOOL CMyTestDlg::OnInitDialog()
font1.CreatePointFont(330,"Comic Sans MS"); //你喜欢的字体
m_edtUserID.SetFont(&font1,true);就可以了!