Click to See Complete Forum and Search --> : printing problems using GDI+ enhanced metafile


pdehon
October 20th, 2004, 06:57 AM
Hello,

In a Visual C++ 6.0 application a emf-file is generated with code fragment shown below.

.....
HINSTANCE hInst = GetModuleHandle(NULL);

WNDCLASS wc; // The window class

m_pszClassName = strdup("Win32App");

memset(&wc, 0, sizeof(WNDCLASS)); // Initialise the size of the class
wc.style = CS_HREDRAW | CS_VREDRAW; // Regular drawing capabilities
wc.lpfnWndProc = DefWindowProc; // Pass our function pointer as the window procedure
wc.hInstance = hInst; // Assign our hInstance
wc.hIcon = LoadIcon(hInst, IDI_APPLICATION); // General icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // An arrow for the cursor
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // set the window background to black
wc.lpszClassName = m_pszClassName; // Assign the class name

if(!RegisterClass(&wc))
{
return;
}

if(!(m_hWnd = CreateWindow(m_pszClassName, "Simple Win32 Application", // class name, window title
WS_OVERLAPPEDWINDOW, // we want the window to be on top
0, 0, // the position of the window
500, 500, // width and height of the window
NULL, NULL, // no parent window, no menu
hInst, NULL)))
{
// the window could not be created
return;
}

m_hdc = GetDC(m_hWnd);

.......

USES_CONVERSION;
WCHAR* pw = A2W(filename);

m_pMTF = new Metafile(pw, m_hdc, EmfTypeEmfPlusDual);

m_pGraphics = new Graphics(m_pMTF);

m_pGraphics->SetPageUnit(UnitMillimeter);
m_pGraphics->SetPageScale(1.0);
....


In this program a line with a length of 80 mm is drawn (and saved in the metafile).

In another program this emf-file is read by using a GDI+ Metafile-object (m_pMetafile) and then printed with the code :

Graphics graphics(pDC->m_hDC); // m_hDC is a printer device context
graphics.DrawImage(m_pMetafile, 0, 0);

On the print, the line has a length of 76 mm instead of 80 mm.

When I insert the line : graphics.SetPageUnit(UnitMillimeter); before DrawImage the printed line has a length of 75 mm.

Can anybody explain this?