BOOL CBgColorDemoApp::InitInstance() { AfxEnableControlContainer();// Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endifCBgColorDemoDlg dlg; m_pMainWnd = &dlg; //在这里加入背景颜色的设置,就一条语句,多简单, //前一个 RGB设置背景色,第二个RGB设置字体颜色SetDialogBkColor(RGB(000,204,255), RGB(255, 0,0)); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel }// Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
在对应的BOOL CXXXView::OnEraseBkgnd(CDC* pDC)里这样写:
BOOL CAaView::OnEraseBkgnd(CDC* pDC)
{ CBrush Brush (RGB (128 , 0 , 128) );//你的颜色 CBrush* pOldBrush = pDC->SelectObject(&Brush); CRect rcClip;
pDC->GetClipBox(&rcClip); pDC-> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height( ) , PATCOPY ); pDC->SelectObject (pOldBrush ); return TRUE;
}OK了.....
{
AfxEnableControlContainer();// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endifCBgColorDemoDlg dlg;
m_pMainWnd = &dlg;
//在这里加入背景颜色的设置,就一条语句,多简单,
//前一个 RGB设置背景色,第二个RGB设置字体颜色SetDialogBkColor(RGB(000,204,255), RGB(255, 0,0));
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
SetColor( BACKGROUND, **** )函 数 可 以 改 变 窗 口 背 景 色 , 在 适 当 的 位 置 加 上 它 即 可 , 其 中 第 二 个 变 量 可 以 为 以 下 值 :
BK_BLUE BK_MAGENTA BK_PINK BK_YELLOW
BK_GREEN BK_ORANGE BK_RED
以 上 几 种 为 渐 变 色
BK_SOLIDBLACK BK_SOLIDMAGENTA BK_SOLIDRED
BK_SOLIDBLUE BK_SOLIDORANGE BK_SOLIDWHITE
BK_SOLIDGREEN BK_SOLIDPINK BK_SOLIDYELLOW
同 时 第 二 个 参 数 也 可 以 用 RGB来 描 述 , 如 SetColor( BACKGROUND, RGB(0,0,255) )
只有时间控件等有用
BOOL Csdi1View::OnEraseBkgnd(CDC* pDC)
{
CView::OnEraseBkgnd(pDC);
CRect rect;
GetClientRect(rect);
pDC->FillSolidRect(&rect, RGB(0,255,0)); return TRUE;}
{
CRect rect;
GetClientRect(&rect);
pDC->FillRect(&rect, RGB(0,255,0));
return TRUE;}