void CMFCApplication1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
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;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
CBitmap m_bitmap;
m_bitmap.LoadBitmap(IDB_BITMAP1);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
memdc.SelectObject(&m_bitmap);
int width,height;
BITMAP bmp;
m_bitmap.GetBitmap(&bmp);
width = bmp.bmWidth;
height = bmp.bmHeight;
CRect rect;
this->GetClientRect(&rect);
dc.SetStretchBltMode(HALFTONE);
dc.StretchBlt(rect.left,rect.top,rect.Width(),rect.Height(),\
&memdc,0,0,width,height,SRCCOPY);
}
}