MFC设置对话框背景[bmp位图当背景]
步骤一:导入bmp文件:
第二步:设置为背景:
① 添加OnCtlColor消息响应函数:
② 添加响应代码:
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
static CBrush gBr;
static bool isInited = false;
if(!isInited)
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
gBr.CreatePatternBrush(&bitmap);
COLORREF clearColor = -1;
bitmap.DeleteObject();
isInited = true;
}
if(pWnd==this)
{
pDC->SetBkMode(TRANSPARENT);
return gBr; //主窗口背景使用这个背景刷
}
else
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(NULL_BRUSH); //其他控件使用透明背景
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
③效果图:
静态文本框、单行多行输入文本框、列表框、ListCtrl等都可以共享主窗口的背景,但是按钮需要另外设置才可以。
还没有评论,来说两句吧...