June 30th, 2010, 11:51 AM
Scaling issue when replaying metafile
I am trying to replay a metafile that has been saved on the disk. It works except for one thing. I cannot figure out how to get a proper scaling. If I don't do anything, when drawing the bitmap on the screen from the metafile, it appears much, much bigger than it should. Well, given that the window size is 100*100, it never exceeds that on the screen, but it means only a small part of a much bigger bitmap is visible.
Here is a code sample that reproduces the problem.
I am trying to calculate this ratio that would display a proper 100*100 pixels bitmap on the screen.
CString strFileName = "c:\\test\\test.emf";
CRect rect (0, 0, 100, 100);
memDC.CreateEnhanced(&memDC, strFileName, rect, "just a test");
CPen m_pen(PS_SOLID, 1, COLORREF(RGB(0, 255, 0)));
HENHMETAFILE hmf = memDC.CloseEnhanced();
CRect rect (100, 100, 200, 200);
wnd.CreateEx(NULL, NULL, NULL,WS_POPUP | WS_CHILD | WS_CLIPSIBLINGS, rect, NULL, NULL, NULL);
hmf = GetEnhMetaFile(strFileName);
CRect rectWnd = rect;
CPoint ptToolTipLeft = rectWnd.TopLeft();
SetWindowPos(wnd.m_hWnd, HWND_TOPMOST,ptToolTipLeft.x+1, ptToolTipLeft.y+1, rectWnd.Width(), rectWnd.Height(),SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE);
int ratio = 1;
CRect rect1 (0, 0, 100, 100);
I have tried to play with different mappings, including by applying mappings to the metafile. On my PC at least, the correct ratio would be around 39, but using a hard coded value is not satisfactory as it does not give the same result on someone else's PC.
A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
-- George Steiner
Tags for this Thread
Click Here to Expand Forum to Full Width