Rubrik: Drucken | 22.03.05 |
EndPage-Funktion Diese Funktion teilt dem Druckerspooler mit, dass das Bearbeiten einer Seite für den Ausdruck beendet ist. Nach dieser Funktion kann eine weitere Seite mit der StartPage-Funktion gestartet werden oder der Ausdruck mittels der EndDoc-Funktion gestartet werden. | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 7.601 |
Deklaration:
Declare Function EndPage Lib "gdi32.dll" (ByVal hDC As Long) As Long
Beschreibung:
Diese Funktion teilt dem Druckerspooler mit, dass das Bearbeiten einer Seite für den Ausdruck beendet ist. Nach dieser Funktion kann eine weitere Seite mit der StartPage-Funktion gestartet werden oder der Ausdruck mittels der EndDoc-Funktion gestartet werden.
Parameter:
hDC | Erwartet den Devicekontext des Druckers, dem mitgeteilt werden soll, dass eine Druckseite fertiggestellt ist. |
Rückgabewert:
Ist die Funktion erfolgreich, so wird ein Wert "Größer als 0" zurückgegeben, andernfalls ein wert "kleiner als 0". Unter Windows NT/2000 könnenSie die GetLastError-Funktion für erweiterte Fehlerinformationen aufrufen.
Beispiel:
Private Declare Function CreateDC Lib "gdi32" _ Alias "CreateDCA" ( _ ByVal lpDriverName As String, _ ByVal lpDeviceName As String, _ ByVal lpOutput As String, _ lpInitData As Any) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nIndex As Long) As Long Private Declare Function StartDoc Lib "gdi32" _ Alias "StartDocA" ( _ ByVal hdc As Long, _ lpdi As DOCINFO) As Long Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteObject Lib "gdi32" ( _ ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal hObject As Long) As Long Private Declare Function CreatePen Lib "gdi32" ( _ ByVal nPenStyle As Long, _ ByVal nWidth As Long, _ ByVal crColor As Long) As Long Private Declare Function TextOut Lib "gdi32.dll" _ Alias "TextOutA" ( _ ByVal hdc As Long, _ ByVal X As Long, _ ByVal Y As Long, _ ByVal lpString As String, _ ByVal nCount As Long) As Long Private Declare Function Ellipse Lib "gdi32.dll" ( _ ByVal hdc As Long, _ ByVal X1 As Long, _ ByVal Y1 As Long, _ ByVal X2 As Long, _ ByVal Y2 As Long) As Long Private Declare Function GetTextExtentPoint32 Lib "gdi32" _ Alias "GetTextExtentPoint32A" ( _ ByVal hdc As Long, _ ByVal lpsz As String, _ ByVal cbString As Long, _ lpSize As POINTAPI) As Long Private Type POINTAPI X As Long Y As Long End Type Private Type DOCINFO cbSize As Long lpszDocName As String lpszOutput As Long lpszDatatype As String fwType As Long End Type ' DOCINFO fwType-Konstanten Private Const DI_APPBANDING = &H1 Private Const DI_ROPS_READ_DESTINATION = &H2 ' einige GetDeviceCaps nIndex-Konstanten Private Const PHYSICALHEIGHT = 111 Private Const PHYSICALOFFSETX = 112 Private Const PHYSICALOFFSETY = 113 Private Const PHYSICALWIDTH = 110 ' CreatePen nPenStyle-Konstanten Private Const PS_DASH = 1 ' Linien mit leeren Zwischenräumen Private Const PS_DOT = 2 ' Punkte mit leeren Zwischenräumen Private Const PS_DASHDOT = 3 ' Linien und Punkte mit leeren Zwischenräumen Private Const PS_DASHDOTDOT = 4 ' Linie, Punkt, Punkt mit leeren Zwischenräumen Private Const PS_NULL = 5 ' Unsichtbar Private Const PS_INSIDEFRAME = 6 ' Der Pen ist Solid wird aber im inneren des Objektes gezeichnet Private Const PS_SOLID = 0 ' Durchgezogene Linie
Private Sub Command1_Click() Dim PrinterDC As Long, Retval As Long, Doc As DOCINFO Dim PWidth As Long, PHeight As Long, PYMargin As Long, PXMargin As Long Dim hPen As Long, hOldPen As Long, OutputStr As String, OutputSize As POINTAPI Dim TLeft As Long, TTop As Long, TWidth As Long, THeight As Long ' Drucker Devicekontext erstellen PrinterDC = CreateDC(vbNullString, Printer.DeviceName, vbNullChar, _ ByVal 0&) If PrinterDC = 0 Then Exit Sub ' Ausdruckgröße ermitteln PWidth = GetDeviceCaps(PrinterDC, PHYSICALWIDTH) PHeight = GetDeviceCaps(PrinterDC, PHYSICALHEIGHT) ' Nichtbedruckbare Ränder ermitteln PYMargin = GetDeviceCaps(PrinterDC, PHYSICALOFFSETY) PXMargin = GetDeviceCaps(PrinterDC, PHYSICALOFFSETX) ' Ausdruck für den Spoolmanager definieren With Doc .cbSize = Len(Doc) .lpszDocName = "VB Api Helpline Print Example" End With ' Starten des Ausdrucks StartDoc PrinterDC, Doc ' Beginnen einer Seite StartPage PrinterDC ' roten Pen erstellen hPen = CreatePen(PS_DASHDOT, 0, RGB(255, 0, 0)) ' Pen dem Drucker zuweisen hOldPen = SelectObject(PrinterDC, hPen) ' String für den Ausdruck definieren OutputStr = "VB API HELPLINE" ' Größe der Ausgabe bei aktuellen Fonteinstellungen ermitteln GetTextExtentPoint32 PrinterDC, OutputStr, Len(OutputStr), OutputSize ' Koordinaten zum Positionieren in der Mitte des Ausdrucks ermitteln TWidth = OutputSize.X THeight = OutputSize.Y TTop = (PHeight - (2 * PYMargin) - OutputSize.Y) / 2 TLeft = (PWidth - (2 * PXMargin) - OutputSize.X) / 2 ' Ellipse zeichnen (mit neu erstelltem Pen) Ellipse PrinterDC, TLeft - 50, TTop - 50, TLeft + 50 + TWidth, TTop + _ 50 + THeight ' Text auf die Ellipse platzieren TextOut PrinterDC, TLeft, TTop, OutputStr, Len(OutputStr) ' Alten Pen wiederherstellen SelectObject PrinterDC, hOldPen ' Pen Zerstören DeleteObject hPen ' Abschließen der Seite EndPage PrinterDC ' Beenden des Ausdrucks EndDoc PrinterDC ' Drucker Devicekontext zerstören DeleteDC PrinterDC End Sub