Forums Neueste Beiträge
 

Druckermodell anzeigen lassen

06/01/2009 - 15:01 von Gernot Meyer | Report spam
Hallo,

ich möchte den ersten Schacht meines Druckers abhàngig vom Druckermodell
wàhlen.
Also, sowas wie
wenn Drucker X vom Typ ABC, dann .PageSetup.FirstPageTray%8
wenn Drucker Y vom Typ DEF, dann .PageSetup.FirstPageTray&0
wenn Drucker Z vom Typ GHI, dann .PageSetup.FirstPageTray&1

Wie bekomme ich vom aktuell gewàhlten Drucker den Typ (im Dialog immer mit
"Modell" bezeichnet) wie z.B. HP LJ P2015N o.à. heraus.

Danke für Hilfe
Gernot
 

Lesen sie die antworten

#1 Christian Freßdorf
06/01/2009 - 15:12 | Warnen spam
Hallo,

Wie bekomme ich vom aktuell gewàhlten Drucker den Typ (im Dialog immer mit
"Modell" bezeichnet) wie z.B. HP LJ P2015N o.à. heraus.



also den Namen wie er im Druckdialog angezeigt wird?

Z.B. mit foldenden APIs

Option Explicit

Const PRINTER_ENUM_CONNECTIONS = &H4
Const PRINTER_ENUM_LOCAL = &H2
Const c_cap = "Dateiübersicht: "
' Printer
Private Declare Function EnumPrinters Lib "winspool.drv" Alias
"EnumPrintersA" _
(ByVal Flags As Long, ByVal Name As String, ByVal Level As Long, _
pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, _
pcReturned As Long) As Long
Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" _
(ByVal hdc As Long, lpdi As DOCINFO) As Long
Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) As Long
Private Type DOCINFO
cbSize As Long
lpszDocName As String
lpszOutput As String
lpszDatatype As String
fwType As Long
End Type
Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA"
_
(ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function EnumJobs Lib "winspool.drv" Alias _
"EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob _
As Long, ByVal NoJobs As Long, ByVal Level As Long, _
pJob As Long, ByVal cdBuf As Long, pcbNeeded As _
Long, pcReturned As Long) As Long

Private Declare Function StrLen Lib "kernel32.dll" Alias "lstrlenA" (ByVal
lpString As Long) As Long
Private Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyA" _
(ByVal RetVal As String, ByVal Ptr As Long) As Long
Private Declare Function DeviceCapabilities Lib "winspool.drv" Alias
"DeviceCapabilitiesA" ( _
ByVal lpDeviceName As String, _
ByVal lpPort As String, _
ByVal iIndex As Long, _
lpOutput As Any, _
lpDevMode As Any) _
As Long

Public Function ListPrinters() As Variant

Dim bSuccess As Boolean
Dim iBufferRequired As Long
Dim iBufferSize As Long
Dim iBuffer() As Long
Dim iEntries As Long
Dim iIndex As Long
Dim strPrinterName As String
Dim iDummy As Long
Dim iDriverBuffer() As Long
Dim strPrinters() As String

iBufferSize = 3072

ReDim iBuffer((iBufferSize \ 4) - 1) As Long

'EnumPrinters will return a value False if the buffer is not big enough
bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
PRINTER_ENUM_LOCAL, vbNullString, _
1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)

If Not bSuccess Then
If iBufferRequired > iBufferSize Then
iBufferSize = iBufferRequired
Debug.Print "iBuffer too small. Trying again with "; _
iBufferSize & " bytes."
ReDim iBuffer(iBufferSize \ 4) As Long
End If
'Try again with new buffer
bSuccess = EnumPrinters(PRINTER_ENUM_CONNECTIONS Or _
PRINTER_ENUM_LOCAL, vbNullString, _
1, iBuffer(0), iBufferSize, iBufferRequired, iEntries)
End If

If Not bSuccess Then
'Enumprinters returned False
MsgBox "Error enumerating printers."
Exit Function
Else
'Enumprinters returned True, use found printers to fill the array
ReDim strPrinters(iEntries - 1)
For iIndex = 0 To iEntries - 1
'Get the printername
strPrinterName = Space$(StrLen(iBuffer(iIndex * 4 + 2)))
iDummy = PtrToStr(strPrinterName, iBuffer(iIndex * 4 + 2))

strPrinters(iIndex) = strPrinterName '& " an " &
Form_Load(strPrinterName)
Next iIndex
End If

ListPrinters = strPrinters

End Function
Public Function IsBounded(vArray As Variant) As Boolean

'If the variant passed to this function is an array, the function will
return True;
'otherwise it will return False
On Error Resume Next
IsBounded = IsNumeric(UBound(vArray))

End Function
'
Sub subListPrinters()
' Listet alle Drucker mit Namen auf
Dim strPrinters As Variant, X As Long
strPrinters = ListPrinters
'Fist check whether the array is filled with anything, by calling another
function, IsBounded.
If IsBounded(strPrinters) Then
For X = LBound(strPrinters) To UBound(strPrinters)
Debug.Print strPrinters(X)
Next X
Else
Debug.Print "No printers found"
End If

End Sub


subListPrinters zeigt dann die Drucker an.

HTH
Christian

Ähnliche fragen