Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CRichEditCtrl::FormatRange
Collapse the table of content
Expand the table of content

CRichEditCtrl::FormatRange

Formats a range of text in a rich edit control for a specific device.

long FormatRange( 
   FORMATRANGE* pfr, 
   BOOL bDisplay = TRUE  
);

pfr

Pointer to the FORMATRANGE structure which contains information about the output device. NULL indicates that cached information within the rich edit control can be freed.

bDisplay

Indicates if the text should be rendered. If FALSE, the text is just measured.

The index of the last character that fits in the region plus one.

Typically, this call is followed by a call to DisplayBand.

For more information, see EM_FORMATRANGE message and FORMATRANGE structure in the Windows SDK.

// First obtain a pointer to a printer DC.
CPageSetupDialog psDlg;
if (IDOK == psDlg.DoModal())
{
   CDC* pMyPrinterDC = CDC::FromHandle(psDlg.CreatePrinterDC());

   FORMATRANGE fr;

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

   // Format the text and render it to the printer.
   fr.hdc = pMyPrinterDC->m_hDC;
   fr.hdcTarget = pMyPrinterDC->m_hDC;
   fr.rc = rcPage;
   fr.rcPage = rcPage;
   fr.chrg.cpMin = 0;
   fr.chrg.cpMax = -1;
   m_myRichEditCtrl.FormatRange(&fr, TRUE);

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

   pMyPrinterDC->DeleteDC();
}

Header: afxcmn.h

Show:
© 2015 Microsoft