有没有方法改变对话框背景图案,不是背景颜色呀!请指教!

hayeswu 2003-03-12 05:32:45
谢谢!
...全文
18 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
isCrazy 2003-03-13
  • 打赏
  • 举报
回复
最好响应:WM_ERASEBKGND消息。比WM_PATIENT消息要好。
BOOL CMainWnd::OnEraseBkgnd(CDC* pDC)
{
//请在此加入背景绘图代码:

return CWnd::OnEraseBkgnd(pDC);
}
guoxiny 2003-03-12
  • 打赏
  • 举报
回复
可以添加WM_DRAWITEM消息对CDialog进行重画。挺费劲的,以下是将一个应用程序的图标画到一个CButton上的代码,对CDialog应该也是这样的,虽然我没试过。

void CBigIcon::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
ASSERT(NULL != pDC);

CRect rc;
GetClientRect(&rc);
int cxClient = rc.Width();
int cyClient = rc.Height();

//Get system Icon
HICON hicon = ::AfxGetApp()->LoadIcon(IDR_MAINFRAME);
if(NULL == hicon)
return;

//get system icon size
int cxIcon = ::GetSystemMetrics(SM_CXICON);
int cyIcon = ::GetSystemMetrics(SM_CYICON);

//create a bitmap with pDC compatiblete
CBitmap bitmap;
if(!bitmap.CreateCompatibleBitmap(pDC,cxIcon,cyIcon))
return;

//Creates a memory device context that is compatible with
//the device specified by pDC
CDC dcmen;
if(!dcmen.CreateCompatibleDC(pDC))
return;

CBitmap* pOldBitmap = dcmen.SelectObject(&bitmap);
if(NULL == pOldBitmap)
return;

//draw background
dcmen.StretchBlt(0,0,cxIcon,cyIcon,pDC,2,2,
cxClient-8,cyClient-8,SRCCOPY);

//draw icon on the background
dcmen.DrawIcon(0,0,hicon);

//draw border
CPen pen;
pen.CreateStockObject(BLACK_PEN);
CPen* pOldPen = pDC->SelectObject(&pen);
pDC->Rectangle(0,0,cxClient-4,cyClient-4);
if(pOldPen)
pDC->SelectObject(pOldPen);

//draw shadow
CBrush brh;
brh.CreateStockObject(DKGRAY_BRUSH);
rc.SetRect(cxClient-4,4,cxClient,cyClient);
pDC->FillRect(&rc,&brh);
rc.SetRect(4,cyClient-4,cxClient,cyClient);
pDC->FillRect(&rc,&brh);

//draw icon content
pDC->StretchBlt(2,2,cxClient-8,cyClient-8,&dcmen,0,0,
cxIcon,cyIcon,SRCCOPY);
}

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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