传入IDbitmap
HBITMAP m_Bitmap;
CBitmap hbmp;
CDC dcMem;
CDC* pDC;
m_Bitmap = ::LoadBitmap(getThisModuleHandle(), MAKEINTRESOURCE(IDB_Bitmap_01));
CWnd* pWnd = GetDlgItem(id);
pDC = pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(&rect);
hbmp.Attach(m_Bitmap);
BITMAP bm;
hbmp.GetBitmap(&bm);
dcMem.CreateCompatibleDC(pDC);
CBitmap *poldBitmap = (CBitmap*)dcMem.SelectObject(hbmp);
int nWidth;
int nHeight;
if (bm.bmWidth / rect.Width() > bm.bmHeight / rect.Height())
{
nWidth = rect.Width();
nHeight = int((double)bm.bmHeight * (double)rect.Width() / (double)(bm.bmWidth));
}
else
{
nHeight = rect.Height();
nWidth = int((double)bm.bmWidth * (double)rect.Height() / (double)(bm.bmHeight));
}
nWidth = int((double)nWidth * 0.95);
nHeight = int((double)nHeight * 0.95);
CRect rcBmp = rect;
rcBmp.left += (rect.Width() - nWidth) / 2;
rcBmp.right = rcBmp.left + nWidth;
rcBmp.top += (rect.Height() - nHeight) / 2;
rcBmp.bottom = rcBmp.top + nHeight;
CBrush brush;
brush.CreateSolidBrush(RGB(255, 255, 255));
pDC->FillRect(rect, &brush);
pDC->StretchBlt(rcBmp.left, rcBmp.top, nWidth, nHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
pWnd->ReleaseDC(pDC);
weixin_45699553
原创文章 15获赞 6访问量 1107
关注
私信
展开阅读全文