改变背景颜色,有两种方法:
1、在app的初始化函数中调用:
void SetDialogBkColor( COLORREF clrCtlBk = RGB(192, 192, 192), COLORREF clrCtlText = RGB(0, 0, 0) );
2、在对话框类的OnCtlColor函数中:
if(nCtlColor == CTLCOLOR_DLG)
{
CBrush *brush;
brush = new CBrush(RGB(221,221,221));
return (HBRUSH)(brush->m_hObject);
}
设置背景位图:
void CTestDlg::OnPaint()
{
CRect r;
GetClientRect(&r);
CPaintDC dc(this);
CRect rect=CRect(0,0,r.Width()/5,r.Height()/3);
//GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP2);
BITMAP bitMap;
bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);
}