Condividi tramite


CRichEditCtrl::SetTargetDevice

Sets the target device and line width used for WYSIWYG (what you see is what you get) formatting in this CRichEditCtrl object.

BOOL SetTargetDevice(
   HDC hDC,
   long lLineWidth 
);
BOOL SetTargetDevice(
   CDC& dc,
   long lLineWidth 
);

Parameters

  • hDC
    Handle to the device context for the new target device.

  • lLineWidth
    Line width to use for formatting.

  • dc
    CDC for the new target device.

Return Value

Nonzero if successful; otherwise, 0.

Remarks

If this function is successful, the rich edit control owns the device context passed as a parameter. In that case, the calling function should not destroy the device context.

For more information, see EM_SETTARGETDEVICE in the Windows SDK.

Example

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

   // Get line width information from the printer.
   long lLineWidth = ::MulDiv(pMyPrinterDC->GetDeviceCaps(PHYSICALWIDTH),
       1440, pMyPrinterDC->GetDeviceCaps(LOGPIXELSX));

   // Set the printer as the target device.
   m_myRichEditCtrl.SetTargetDevice(*pMyPrinterDC, lLineWidth);   

   pMyPrinterDC->DeleteDC();
}

Requirements

Header: afxcmn.h

See Also

Reference

CRichEditCtrl Class

Hierarchy Chart

CRichEditCtrl::FormatRange

CRichEditCtrl::DisplayBand

Other Resources

CRichEditCtrl Members