给窗体绘制背景图片 vc

来源:百度文库 编辑:神马文学网 时间:2024/10/03 03:33:58
zyyoung @ 2007-05-30 12:21 | C++
给窗体绘制背景图片view plaincopy to clipboardprint?
//给窗体绘制背景图片(1)图片控件(2)GDI绘制
//方法(2)
void C*Dlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// load IDB_BITMAP1 from our resources
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
// Select the bitmap into the in-memory DC
CBitmap *pOldBmp=dcMemory.SelectObject(&bmp);
if(!m_bStretch.GetCheck())
{
// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting
dc.BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY);
}
else
{
//Get Client area
CRect wndRt;
this->GetClientRect(&wndRt);
// Stretch and copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting
dc.StretchBlt(0, 0, wndRt.Width(), wndRt.Height   (),
&dcMemory, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, SRCCOPY);
}
dcMemory.SelectObject(pOldBmp);
}