假设背景位图的ID为IDB_BITMAPBACKGROUND
void CDemoDialog::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
/*++++++++++++++++++++++++++++++++++++++++++++*/
/**** 以下为添加的内容 ******/
/*++++++++++++++++++++++++++++++++++++++++++++*/
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);//得到窗体的大小
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAPBACKGROUND);//加载背景图片
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);//把图贴上去,可以伸缩
// dc.BitBlt(0, 0, bitMap.bmWidth, bitMap.bmHeight, &dcMem, 0, 0, SRCCOPY);
// 不可以伸缩
/*++++++++++++++++++++++++++++++++++++++++++++*/
/**** 添加内容结束 ******/
/*++++++++++++++++++++++++++++++++++++++++++++*/
//CDialog::OnPaint();//这一句不要
}
}
阅读(888) | 评论(0) | 转发(0) |