Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CRichEditCtrl, Printing, and Fonts

84 views
Skip to first unread message

Ryan Wagner

unread,
Mar 2, 2003, 2:08:44 PM3/2/03
to
I've been experiencing great difficulty in printing the
contents of a CRichEditCtrl (via FormatRange() and
DisplayBand()) using a font other than the default printer
font. I have the RichEditCtrl displaying using the
Courier font, and I can print the contents of the
RichEditCtrl. But no matter how I try to set the font for
the printer before printing, it always prints in it's
default font. (I'm trying to do this from a Dialog Box
application)

Any suggestions?

Thanks in advance,
Ryan Wagner

////////////////
// Code excerpt
//
CPrintDialog dlg(FALSE, PD_ALLPAGES | PD_RETURNDC |
PD_NOSELECTION | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS,
this);

dlg.m_pd.nCopies = 1;
dlg.m_pd.hDevMode = NULL;
dlg.m_pd.hDevNames = NULL;

if (dlg.DoModal() != IDOK)
return;

HDC hdc = dlg.GetPrinterDC();
ASSERT(hdc);
::GlobalFree(dlg.m_pd.hDevMode);
::GlobalFree(dlg.m_pd.hDevNames);

CDC *pPrintDC = CDC::FromHandle(hdc);

pPrintDC->StartDoc("Judgment Interest Calculation");
CFont font;
font.CreatePointFont(120, "Courier", pPrintDC)

// This code is from the MSDN help on
// CRichEditCtrl::FormatRange()
FORMATRANGE fr;

// Get the page width and height from the printer.
long lPageWidth = ::MulDiv(printDC->GetDeviceCaps
(PHYSICALWIDTH), 1440, printDC->GetDeviceCaps
(LOGPIXELSX));
long lPageHeight = ::MulDiv(printDC->GetDeviceCaps
(PHYSICALHEIGHT), 1440, printDC->GetDeviceCaps
(LOGPIXELSY));
CRect rcPage(0, 0, lPageWidth, lPageHeight);

pPrintDC->StartPage();

CFont *pOldFont = pPrintDC->SelectObject(&font);

// Format the text and render it to the printer->
fr.hdc = printDC->m_hDC;
fr.hdcTarget = printDC->m_hDC;
fr.rc = rcPage;
fr.rcPage = rcPage;
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;

m_recDisplay.FormatRange(&fr, TRUE);

// Update the display with the new formatting.
RECT rcClient;
m_recDisplay.GetClientRect(&rcClient);
m_recDisplay.DisplayBand(&rcClient);

pPrintDC->SelectObject(pOldFont);
pPrintDC->EndPage();

pPrintDC->EndDoc();
pPrintDC->DeleteDC();
font.DeleteObject();

// END

Johan Rosengren

unread,
Mar 4, 2003, 1:20:36 PM3/4/03
to
Ryan,

The control ought to use the fonts you have set on the text, and so your
SelectObject outside the printing itself ought to be without effects.
Wouldn't it be easier to just set the font you want in the control itself?

Johan Rosengren
Abstrakt Mekanik AB

"Ryan Wagner" <rwa...@starcrest.ca> wrote in message
news:037301c2e0ef$24e6b460$3001...@phx.gbl...

0 new messages