void CShowPicture1View::OnDraw(CDC* pDC)
{
CShowPicture1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
if( strFilename != "" )
{
BITMAP bmpProperties;
// Create a bitmap handle using the name of the file
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,
strFilename,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
CBitmap bmpPicture;
CDC mdcPicture;
// Convert the Win32 bitmap handle into an MFC bitmap object
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);
bmpPicture.Attach(bmpHandle);
// Call the Win32 GetObject() function to get the properties
// of the bitmap and store them in a BITMAP structure
::GetObject(bmpPicture,
sizeof(bmpProperties),
&bmpProperties);
// Create a compatible device context
mdcPicture.CreateCompatibleDC(pDC);
// Select the bitmap into the device context
CBitmap * bmpPrevious =
mdcPicture.SelectObject(bmpFromHandle);
// Using the dimensions store in the BITMAP object,
// display the picture
pDC->BitBlt(0, 0,
bmpProperties.bmWidth, bmpProperties.bmHeight,
&mdcPicture, 0, 0, SRCCOPY);
// Get the dimensions of the new picture
SIZE sizeTotal;
sizeTotal.cx = bmpProperties.bmWidth;
sizeTotal.cy = bmpProperties.bmHeight;
// Change the scrolling area/dimensions of the view
SetScrollSizes(MM_TEXT, sizeTotal);
// Restore the bitmap
pDC->SelectObject(bmpPrevious);
// Delete the Win32 bitmap handle
DeleteObject(bmpHandle);
}
}
|