Print Preview (again?)
Hi
I'm getting very confused with trying to draw a small print preview box. I'm
trying to draw fonts the exact proportionate size. Because I can't show
fractional font sizes on screen, I'm trying to draw it into a memory DC
(quite big?) then StretchBlt it down onto my box (I don't mind if it's a
bit pixelly as long as it's in proportion).
This code works after a fashion but what do my values need to be? Do I need
to set the map mode to a higher value? It comes about 1/3 size.
Thanks for any advice,
Greg Chapman
void CA4Page::OnPaint()
{
CPaintDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
// ??? memDC.SetMapMode(MM_HIMETRIC);
int deviceRes = memDC.GetDeviceCaps(LOGPIXELSY);
CRect rect;
this->GetClientRect(&rect);
// this is roughly 210 x 297 ie a mm to a pixel
CRect memRect(0,0, 2100, 2970);
// nice big one for best resolution?
CBitmap bmp;
bmp.CreateCompatibleBitmap(&memDC, memRect.Width(), memRect.Height());
memDC.SelectObject(&bmp);
LOGFONT fontStruct;
// this fills out the struct
Utilities::FillFontStruct("Times New Roman", 0, 0, 4, fontStruct);
CString str("Hello World");
CFont font;
int pointSize = 60;
fontStruct.lfHeight = (int)-MulDiv(pointSize, deviceRes, 72);
font.CreateFontIndirect(&fontStruct);
memDC.SelectObject(&font);
memDC.DrawText(str, memRect, 0);
dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&memDC, 0, 0, memRect.Width(), memRect.Height(),
SRCCOPY);
}