Click to See Complete Forum and Search --> : Metafile does not print correctly in ActiveX Control


August 26th, 1999, 05:02 PM
Hello,

Does anybody know why the data in my control is not printing correctly.
When I insert the control into microsoft word and print it. The formating is
wrong. All of the characters are bunched together. I know this has to do with
the metafile. I don't understand how to fix it because in the control it looks fine (while in word).

I figured out that calls to OnDraw from OnDrawMetaFile have different mapping modes. This forces me to config the mapping modes in OnDraw and OnDrawMetaFile. This might be the wrong approach.

Here is my code:


void COnDrawTestCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
int cx = rcBounds.left;
int cy = rcBounds.top;

// Force the mapping mode

pdc->SetMapMode(MM_TEXT);
pdc->SetWindowOrg(0,0);
pdc->SetWindowExt(1, 1);
pdc->SetViewportOrg(0, 0);
pdc->SetViewportExt(1, 1);

// For now Force a White Back Ground

pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject WHITE_BRUSH)));

CSize yExt;

pdc->TextOut(rcBounds.left, cy, "410?");
yExt = pdc->GetTextExtent("410?");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "9533");
yExt = pdc->GetTextExtent("9533");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "0562");
yExt = pdc->GetTextExtent("0562");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "3032");
yExt = pdc->GetTextExtent("3032");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "2067");
yExt = pdc->GetTextExtent("2067");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "34;8");
yExt = pdc->GetTextExtent("34;8");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "7==<");
yExt = pdc->GetTextExtent("7==<");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, ";071");
yExt = pdc->GetTextExtent(";071");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "7=??");
yExt = pdc->GetTextExtent("7=??");
}


/////////////////////////////////////////////////////////////////////////////
// COnDrawTestCtrl message handlers

void COnDrawTestCtrl::OnDrawMetafile(CDC* pdc, const CRect& rcBounds)
{
int cx = rcBounds.left;
int cy = rcBounds.top;

// Force mapping. When I don't, the mapping is different than from OnDraw
// which results in wrong values when calling GetTextExtent

pdc->SetMapMode(MM_TEXT);
pdc->SetWindowOrg(0,0);
pdc->SetWindowExt(300, 300);
pdc->SetViewportOrg(0, 0);
pdc->SetViewportExt(1, 1);

// Clear the entire client rectangle
// If this rect is not declared and used,
// only part of the control will be redrawn when drawing the meta file.

CRect rect;
GetClientRect(rect);

// For now Force a White Back Ground

pdc->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));

CSize yExt;

pdc->TextOut(rcBounds.left, cy, "410?");
yExt = pdc->GetTextExtent("410?");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "9533");
yExt = pdc->GetTextExtent("9533");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "0562");
yExt = pdc->GetTextExtent("0562");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "3032");
yExt = pdc->GetTextExtent("3032");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "2067");
yExt = pdc->GetTextExtent("2067");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "34;8");
yExt = pdc->GetTextExtent("34;8");
cy = yExt.cy + cy;

pdc->TextOut(rcBounds.left, cy, "7==<");
yExt = pdc->GetTextExtent("7==<");

}

Can somebody please help with this if have any ideas. What do I need to do so
that I can get this stuff to print right?

Thank You

Bret