Lavede et eksempel:
void CNg81Dlg::OnButton1()
{
CPrintDialog dlg(FALSE);
LOGFONT LogFont = {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"};
if(dlg.DoModal() == IDOK)
{
HDC hdc = dlg.GetPrinterDC();
ASSERT(hdc);
CDC Dc;
Dc.Attach(hdc);
HDC TDc = ::GetDC(0);
LogFont.lfHeight = ::MulDiv(LogFont.lfHeight, Dc.GetDeviceCaps(LOGPIXELSY), ::GetDeviceCaps(TDc, LOGPIXELSY));
::ReleaseDC(0, TDc);
CFont Font;
Font.CreateFontIndirect(&LogFont);
CFont *OldFont = Dc.SelectObject(&Font);
DOCINFO DocInfo;
memset(&DocInfo, 0, sizeof(DocInfo));
DocInfo.cbSize = sizeof(DocInfo);
DocInfo.lpszDocName = "Whatever.txt";
if(Dc.StartDoc(&DocInfo) < 0)
{
MessageBox("Printer wouldn't initalize");
}
else
{
if(Dc.StartPage() < 0)
{
MessageBox("Could not start page");
Dc.AbortDoc();
}
else
{
CEdit *Edit = (CEdit *)GetDlgItem(IDC_EDIT1);
ASSERT(Edit);
CString S;
Edit->GetWindowText(S);
Dc.TextOut(50, 50, S, S.GetLength());
Dc.EndPage();
Dc.EndDoc();
}
}
Dc.SelectObject(OldFont);
}
}
Det henter teksten fra IDC_EDIT1 og udskriver denne.
Der er et komplet project her:
http://home20.inet.tele.dk/midgaard/ng81.zip