EndPage Function

Declare Function EndPage Lib "gdi32.dll" (ByVal hDC As Long) As Long

Platforms

Description & Usage

EndPage informs the print spooler that the program has finished drawing the contents of a printed page. The StartPage and EndPage functions must bracket all code which draws the contents of the printed page. The print spooler must have already been informed that it is receiving a document to be printed via StartDoc before drawing the page had begun. The printer does not actually print the page until the print spooler is told via EndDoc that the entire document is complete.

Return Value

If an error occured, the function returns either zero or a negative value (Windows NT, 2000: use GetLastError to get the error code). If successful, the function returns a positive value.

Visual Basic-Specific Issues

None.

Parameters

hDC
A handle to a device context to the printer being used to print the document.

Example

' This code is licensed according to the terms and conditions listed here.

' Print out a page with an ellipse drawn with a thickened black
' pen on it.  The page is printed on the computer's default printer.

' The following are special declarations needed to allow string
' manipulation functions to use pointers to strings.
Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long

' Variable declarations
Dim hPrintDC As Long  ' handle to the printer's device context
Dim di As DOCINFO  ' information about the document to print
Dim hPen As Long  ' handle to the pen to draw the ellipse with
Dim hOldPen As Long  ' handle to the printer's previously selected pen
Dim buffer(0 To 3076 / 4) As Long  ' 3076-byte buffer
Dim pi2 As PRINTER_INFO_2  ' receives info about the default printer
Dim printret As Long  ' receives the number of printers returned from EnumPrinters
Dim spaceneeded As Long  ' receives space requires for EnumPrinters
Dim retval As Long  ' return value

' Get the device and driver names of the default printer.  For a more detailed
' description of the semi-confusing code below, consult the
' EnumPrinters page.
retval = EnumPrinters(PRINTER_ENUM_DEFAULT, "", 2, buffer(0), 3076, spaceneeded, printret)
If retval = 0 Then
  Debug.Print "No default printer is configured."
  End  ' abort the program
End If
' Copy the device and driver names to the structure.  All the
' other information retrieved is not needed and is omitted here.
pi2.pPrinterName = Space(lstrlen(buffer(1)))
retval = lstrcpy(pi2.pPrinterName, buffer(1))
pi2.pDriverName = Space(lstrlen(buffer(4)))
retval = lstrcpy(pi2.pDriverName, buffer(4))

' Create a device context to the printer, using its default initialization.
hPrintDC = CreateDC("", pi2.pPrinterName, 0, ByVal CLng(0))
' Create a solid black brush with a thickness of 5.
hPen = CreatePen(PS_SOLID, 5, RGB(0, 0, 0))

' Load information about the document to print into the structure.
di.cbSize = Len(di)  ' size of structure
di.lpszDocName = "Printer API Demonstration"  ' name of document
di.lpszOutput = 0  ' do not print to a file
di.lpszDatatype = ""  ' data type of file doesn't apply
di.fwType = 0  ' no additional information

' Begin the print job.
retval = StartDoc(hPrintDC, di)
' Begin the first and only page to print.
retval = StartPage(hPrintDC)
' Select the pen for use with the printer.
hOldPen = SelectObject(hPrintDC, hPen)
' Draw an ellipse with bounding rectangle corners (1000,1500)-(2000,3000)
retval = Ellipse(hPrintDC, 1000, 1500, 2000, 3000)
' Restore the printer's previously selected pen.
retval = SelectObject(hPrintDC, hOldPen)
' End information about the first and only page.
retval = EndPage(hPrintDC)
' End information about the document.
retval = EndDoc(hPrintDC)
' The printer will now begin printing the document.

' Delete the pen created for drawing.
retval = DeleteObject(hPen)
' Delete the device context to the printer.
retval = DeleteDC(hPrintDC)

See Also

StartPage

Category

Printers

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: November 5, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/e/endpage.html