1> 首先导入资源图片bmp格式的
2> 然后相应该对话框类(CERPDlg)的函数OnPaint,在其中写入:
void CERPDlg::OnPaint()
{
//CPaintDC dc(this); // device context for painting
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
//CDialog::OnPaint();
CPaintDC dc(this);
CRect rect;
GetClientRect( &rect );
CDC dcMem;
dcMem.CreateCompatibleDC( &dc );
CBitmap bmpBackground;
bmpBackground.LoadBitmap( IDB_BITMAP1);//此处的要和导入进来的ID一致
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 );
}
}
其中else里面的代码是自己写的,其他地方的是自己生成的。