共用方式為


CRichEditCtrl::FormatRange

格式化文字的範圍在 Rich Edit 控制項的特定裝置的。

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

參數

  • pfr
    其包含有關此輸出裝置的資訊的 FORMATRANGE 結構的指標。 NULL 表示 Rich Edit 控制項內的快取資訊可以被釋放。

  • bDisplay
    表示文字是否應呈現。 如果 ,文字測量。

傳回值

以納入區域加最後一個字元的索引。

備註

通常,呼叫由 DisplayBand的呼叫之後。

如需詳細資訊,請參閱 EM_FORMATRANGE 訊息和 FORMATRANGE 結構在 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

請參閱

參考

CRichEditCtrl 類別

階層架構圖

CRichEditCtrl::DisplayBand