Help Center

CPrint.AttachPrintermethod

Attaches the specified printer to the class.

PrintingmethodCPrint.incdocumented

Syntax

FUNCTION AttachPrinter (BYREF wszPrinterName AS WSTRING) AS BOOLEAN

Parameters

NameDescription
wszPrinterNameThe name of the printer to attach (as shown in the Devices and Printers applet of the Control Panel).

Return value

BOOLEAN. True or false.

Description

Creates a device context (DC) for the specified printer and attaches it to the class.

Examples

'#CONSOLE ON #define UNICODE #INCLUDE ONCE "AfxNova/CPrint.inc" #INCLUDE ONCE "AfxNova/CGdiplus.inc" USING AfxNova

DIM pPrint AS CPrint pPrint.AttachPrinter("Microsoft Print to PDF") DIM hdcPrint AS HDC = pPrint.GetDC DIM docInfo AS DOCINFOW docInfo.cbSize = SIZEOF(DOCINFOW) DIM wszDocName AS WSTRING * 260 = "GdiplusPrint" docInfo.lpszDocName = VARPTR(wszDocName) StartDocW(hdcPrint, @docInfo) StartPage(hdcPrint) SCOPE DIM graphics AS CGpGraphics = hdcPrint DIM pen AS CGpPen = GDIP_ARGB(255, 0, 0, 0) graphics.DrawLine(@pen, 50, 50, 350, 550) graphics.DrawRectangle(@pen, 50, 50, 300, 500) graphics.DrawEllipse(@pen, 50, 50, 300, 500) END SCOPE EndPage(hdcPrint) EndDoc(hdcPrint)

PRINT "Press any key to end..." SLEEP

The following console example creates an instance of the CPrint class to attach the "Microsoft Print to PDF" driver, retrieves a handle to its device context and uses the WinFBX GDI+ classes to draw the contents of the page.

Reference

  • Include file CPrint.inc
  • Defined in AfxNova/CPrint.inc:229
  • Documented in Printing/CPrint Class.md
  • Topic: CPrint Class