Reputation: 143
I have started learning about MFC recently and the first thing that is really confusing to me so far are Enhanced MetaFiles, specifically, the purpose of and the difference between the bounding rectangles in these two functions
BOOL CreateEnhanced(
CDC* pDCRef,
LPCTSTR lpszFileName,
LPCRECT lpBounds,
LPCTSTR lpszDescription
);
BOOL PlayEnhMetaFile(
_In_ HDC hdc,
_In_ HENHMETAFILE hemf,
_In_ const RECT *lpRect
);
I've written a function DrawLogo
that creates Enhanced MetaFile like this:
CMetaFileDC mf;
CString mf_name = CString("name.emf");
CRect bnds = CRect(0,0, 8000, 8000);
mf.CreateEnhanced(pDC, mf_name, &bnds, mf_name);
//some drawing...
mf.CloseEnhanced();
And then, I "play" it like this from another function:
CString mf_name = CString("name.emf");
DrawLogo(pDC);
HENHMETAFILE hmf;
hmf = GetEnhMetaFile(mf_name);
ENHMETAHEADER mfh;
GetEnhMetaFileHeader(hmf, sizeof(ENHMETAHEADER), &mfh);
int width = mfh.rclBounds.right - mfh.rclBounds.left;
int height = mfh.rclBounds.bottom - mfh.rclBounds.top;
TRACE("WIDTH = %d", width);
TRACE("HEIGHT = %d", height);
PlayEnhMetaFile(pDC->m_hDC, hmf, CRect(0, 0, width, height));
//and I draw a rect using same bounds
CRect frame = CRect(0, 0, width, height);
pDC->Rectangle(&frame);
So my expectation was that metafile will be INSIDE of frame
CRect, but that is not the case - the image exceeds the rect bounds.
Can anyone provide an explanation? Thank you.
EDIT:
As requested:
Upvotes: 1
Views: 2347
Reputation: 39581
The RECT
passed to PlayEnhMetaFile
is only used to scale the image drawn based on the bounding box supplied when the metafile was created. If the metafile draws outside the bounding box then it will also draw outside of the RECT
. If you want to the image to be clipped to RECT
then set a clipping region on the DC before playing back the metafile. If you want to the image to be scaled so that it fits inside the RECT
you'll need to provide the correct bounding box when you create the metafile.
Upvotes: 1