如何改变对话框颜色??

eEric 2002-08-10 09:20:12
我是一vc新手,请问如何改变对话框窗体的颜色??为什吗用
::SetClassLong(m_hWnd,GCL_HBRBACKGROUND,COLOR_WINDOWTEXT );不行??
...全文
123 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilovenet 2002-08-10
  • 打赏
  • 举报
回复
SetBkcolor(....)函数可以实现

georgehuang 2002-08-10
  • 打赏
  • 举报
回复
HBRUSH CAllQueryDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
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;
}
return hbr;
}

OnCtlColor 函数可以在ClassWizard中添加
HBRUSH m_hbrush1=CreateSolidBrush(RGB(195,195,146));
HBRUSH m_hbrush2=CreateSolidBrush(RGB(245,245,220));
czn 2002-08-10
  • 打赏
  • 举报
回复
CWnd::OnCtlColor
This method is called by the framework when a child control is about to be drawn. Most controls send this message to their parent, usually a dialog box, to prepare the pDC for drawing the control using the correct colors.

afx_msg HBRUSH OnCtlColor(
CDC* pDC,
CWnd* pWnd,
UINT nCtlColor );
Parameters
pDC
Contains a pointer to the display context for the child window. May be temporary.
pWnd
Contains a pointer to the control asking for the color. May be temporary.
nCtlColor
Contains one of the following values, specifying the type of control:
CTLCOLOR_BTN Button control
CTLCOLOR_DLG Dialog box
CTLCOLOR_EDIT Edit control
CTLCOLOR_LISTBOX List-box control
CTLCOLOR_MSGBOX Message box
CTLCOLOR_SCROLLBAR Scroll-bar control
CTLCOLOR_STATIC Static control
Return Value
OnCtlColor must return a handle to the brush that is to be used for painting the control background.

Remarks
To change the text color, call the SetTextColor method with the desired red, green, and blue (RGB) values.

To change the background color of a single-line edit control, set the brush handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, and call the CDC::SetBkColor method in response to the CTLCOLOR_EDIT code.

OnCtlColor will not be called for the list box of a drop-down combo box because the drop-down list box is actually a child of the combo box and not a child of the window. To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor method must be used to set the background color for the text.

This method is called by the framework to allow your application to handle a Windows CE message. The parameters passed to your method reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this method, that implementation will use the parameters originally passed with the message and not the parameters you supply to the method.

Example

// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.

HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// Call the base class implementation first! Otherwise, it may
// undo what we are trying to accomplish here.
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Are we painting the IDC_MYSTATIC control? We can use
// CWnd::GetDlgCtrlID() to perform the most efficient test.
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
// Set the text color to red.
pDC->SetTextColor(RGB(255, 0, 0));

// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);

// Return handle to our CBrush object.
hbr = m_brush;
tyro_zhang 2002-08-10
  • 打赏
  • 举报
回复
在CWinApp的继承中调用SetDialogBkColor

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧