真彩色图像作为对话框的背景图像
void CDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
HBITMAP hbm =(HBITMAP)::LoadImage(AfxGetInstanceHandle(), "TMKPTZ.bmp ",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
m_bmp.Attach(hbm);
CDC mem;
mem.CreateCompatibleDC(&dc);
BITMAP bm;
m_bmp.GetBitmap(&bm);
CBitmap* pOld =(CBitmap* )mem.SelectObject(&m_bmp);
CRect rc;
GetWindowRect(rc);
dc.StretchBlt(0,0,rc.Width(),rc.Height(),&mem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
mem.SelectObject(pOld);
// CDialog::OnPaint();
delete hbm;
delete mem;
delete pOld;
free(dc);
}
在.h中加入一条
CBitmap m_bmp;
{
CPaintDC dc(this); // device context for painting
HBITMAP hbm =(HBITMAP)::LoadImage(AfxGetInstanceHandle(), "TMKPTZ.bmp ",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
m_bmp.Attach(hbm);
CDC mem;
mem.CreateCompatibleDC(&dc);
BITMAP bm;
m_bmp.GetBitmap(&bm);
CBitmap* pOld =(CBitmap* )mem.SelectObject(&m_bmp);
CRect rc;
GetWindowRect(rc);
dc.StretchBlt(0,0,rc.Width(),rc.Height(),&mem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
mem.SelectObject(pOld);
// CDialog::OnPaint();
delete hbm;
delete mem;
delete pOld;
free(dc);
}
在.h中加入一条
CBitmap m_bmp;