弱弱的问:怎么设置对话框的背景色?
谢谢!
谢谢!
解决方案 »
- 放置窗口于SetWindowText之后
- 为什么没有填充这个矩形块
- 送100分----大家谈谈VC架构前景,或编程经历体验
- 有一段代码 运行的结果正常,但运行的时间越长,单次运算的过程就越长 每次都多几十毫秒
- 请教UNICODE双字节字符串处理的问题?
- 我在MFC的扩展DLL中如何声明一个MFC子类?而且这个类是作为外部接口的.
- 高分在线求解!!!语音处理问题
- 对windows编程的一些预处理语句的困惑
- 如何解决CChildView的字符串换行问题?
- CRuntimeClass有没有pFirstClass这个成员的
- 我要用GUITHREADINFO和GetGUIThreadInfo,为什么编译是说我没声明啊?我include <winuser.h>还是不行
- 大虾帮忙:如何给一个dialog贴上背景图?
一般在InitInstance中调用.
不过这个功能很弱.
建议你重新写一Dialog类,把它做为对话框的基类.
HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_DLG)
{
// pDC->SetBkColor(RGB(68,192,128));
hbr =CreateSolidBrush(RGB(68,192,128));
return hbr;
} // TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CSampleApp : : InitInstance ( )
{
…
//use blue dialog with yellow text .
SetDialogBkColor (RGB (0, 0, 255 ), RGB ( 255 ,255 , 0 ) )
…
}
需要重画对话(或对话的子控件)时,Windows向对话发送消息WM_CTLCOLOR,通常用户可以让Windows选择绘画背景的刷子,也可重置该消息指定刷子。下例说明了创建一个红色背景对话的步骤。
首先,给对话基类增加一人成员变量
CBursh :class CMyFormView : public CFormView
{
…
private :
CBrush m_ brush // background brush
…
}
其次, 在类的构造函数中将刷子初始化为所需要的背景颜色。
CMyFormView : : CMyFormView ( )
{
// Initialize background brush .
m_brush .CreateSolidBrush (RGB ( 0, 0, 255) )
}
最后,使用ClassWizard处理WM_CTLCOLOR消息并返回一个用来绘画对话背景的刷子句柄。注意:由于当重画对话控件时也要调用该函数,所以要检测nCtlColor参量。
HBRUSH CMyFormView : : OnCtlColor (CDC* pDC , CWnd*pWnd , UINT nCtlColor
)
{
// Determine if drawing a dialog box . If we are, return +handle to
//our own background brush . Otherwise let windows handle it .
if (nCtlColor = = CTLCOLOR _ DLG )
return (HBRUSH) m_brush.GetSafeHandle ( )
return CFormView : : OnCtlColor (pDC, pWnd , nCtlColor
)
}