一般通过自己派生 CEdit 来实现。 重载 CEdit 的消息 =WM_CTLCOLOR 加上成员变量: CBrush br;修改构造函数为:CMyEdit::CMyEdit() { br.CreateSolidBrush( RGB(192,192,192) ); }重载:HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor) { // TODO: Change any attributes of the DC here pDC->SetBkMode( TRANSPARENT ); pDC->SetTextColor( RGB(255,0,0) );
return br;
// TODO: Return a non-NULL brush if the parent's handler should not be called //return NULL; }对于其他控间,有些相同,如 CStatic, 有些稍有不同,如 CButton 对于对话框添加背景,我所知道的,有两种方式: 1是重写 Dialog 的 WM_PAINT 消息,绘制你自己的图片。 2是为对话框加一个一样大小的 STATIC ,然后设置属性 Bitmap, 选中你自己的图片。
修改字体可以直接通过 SetFont 来实现。
怎样改变编辑框和静态文本控件中的文本颜色
HBRUSH m_hbrush1=CreateSolidBrush(RGB(195,195,146)); HBRUSH m_hbrush2=CreateSolidBrush(RGB(245,245,220)); 重载OnCtlColor,在里面判断nCtlColor的类型,下面有段代码,其中m_hbrush1和m_hbrush2是HBRUSH的成员变量,要在OnInitialDialog之中赋值 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here if(nCtlColor==CTLCOLOR_DLG) return m_hbrush1; if (nCtlColor == CTLCOLOR_STATIC) { pDC->SetTextColor(RGB(10,10,100)); pDC->SetBkColor(RGB(195,195,146)); return m_hbrush1; }if (nCtlColor == CTLCOLOR_EDIT) { pDC->SetBkColor(RGB(245,245,220)); return m_hbrush2; } if (nCtlColor == CTLCOLOR_LISTBOX) { pDC->SetBkColor(RGB(245,245,220)); return m_hbrush2; } // TODO: Return a different brush if the default is not desired return hbr; 至于在控件中放入图片,需重载控件类,在这里说不清楚给你个源码你自己看吧,要吗,给我留言并写下e_mail
CWnd::SetFont()
可以吗?
加图片要在erasebackground里做吧。
然后声明并实现下面的成员函数:
// in CMyEdit.h
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);// in CMyedit.cpp
// 消息处理程序,在每次OnDraw调用之前调用
HBRUSH CMyedit::CtlColor(CDC* pDC, UINT nCtlColor){
// TODO: 在此添加命令处理程序代码或调用父类的处理函数
static CFont m_font;
if (!(HFONT)m_font) {
// 第一次运行,在这里创建你需要的字体
LOGFONT lf;
GetFont()->GetObject(sizeof(lf), &lf);
strcpy(lf.lfFaceName ,"黑体");
m_font.CreateFontIndirect(&lf);
} pDC->SelectObject(&m_font);
pDC->SetTextColor(RGB(0,0,255)); // blue
pDC->SetBkMode(TRANSPARENT); return ((HBRUSH)::GetStockObject(DEFAULT_PALETTE));
}
重载 CEdit 的消息 =WM_CTLCOLOR
加上成员变量:
CBrush br;修改构造函数为:CMyEdit::CMyEdit()
{
br.CreateSolidBrush( RGB(192,192,192) );
}重载:HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
pDC->SetBkMode( TRANSPARENT );
pDC->SetTextColor( RGB(255,0,0) );
return br;
// TODO: Return a non-NULL brush if the parent's handler should not be called
//return NULL;
}对于其他控间,有些相同,如 CStatic, 有些稍有不同,如 CButton
对于对话框添加背景,我所知道的,有两种方式:
1是重写 Dialog 的 WM_PAINT 消息,绘制你自己的图片。
2是为对话框加一个一样大小的 STATIC ,然后设置属性 Bitmap, 选中你自己的图片。
HBRUSH m_hbrush1=CreateSolidBrush(RGB(195,195,146));
HBRUSH m_hbrush2=CreateSolidBrush(RGB(245,245,220));
重载OnCtlColor,在里面判断nCtlColor的类型,下面有段代码,其中m_hbrush1和m_hbrush2是HBRUSH的成员变量,要在OnInitialDialog之中赋值
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_DLG) return m_hbrush1;
if (nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(10,10,100));
pDC->SetBkColor(RGB(195,195,146));
return m_hbrush1;
}if (nCtlColor == CTLCOLOR_EDIT)
{
pDC->SetBkColor(RGB(245,245,220));
return m_hbrush2;
}
if (nCtlColor == CTLCOLOR_LISTBOX)
{
pDC->SetBkColor(RGB(245,245,220));
return m_hbrush2;
}
// TODO: Return a different brush if the default is not desired
return hbr;
至于在控件中放入图片,需重载控件类,在这里说不清楚给你个源码你自己看吧,要吗,给我留言并写下e_mail
由例子么??
谢谢 !?