Hallo !
Über folgende Funktion kann ich in VB6 unter Windows XP die Druck-Kopien abfragen:
Public Function GetPrinter(frmOwner As Form, Optional PrintFlags As Integer) As _
Printer
Dim PrintDlg As PRINTDLG_TYPE
Dim DevMode As DEVMODE_TYPE
Dim DevName As DEVNAMES_TYPE
Dim lpDevMode As Long, lpDevName As Long
Dim bReturn As Integer
Dim objPrinter As Printer, NewPrinterName As String
Dim strSetting As String
' Use PrintDialog to get the handle to a memory
' block with a DevMode and DevName structures
PrintDlg.lStructSize = Len(PrintDlg)
'PrintDlg.hwndOwner = frmOwner.hWnd
PrintDlg.flags = PrintFlags
'Set the current orientation and duplex setting
DevMode.dmDeviceName = Printer.DeviceName
DevMode.dmSize = Len(DevMode)
DevMode.dmFields = DM_ORIENTATION Or DM_DUPLEX
DevMode.dmOrientation = Printer.Orientation
On Error Resume Next
DevMode.dmDuplex = Printer.Duplex
On Error GoTo 0
'Allocate memory for the initialization hDevMode structure
'and copy the settings gathered above into this memory
PrintDlg.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or _
GMEM_ZEROINIT, Len(DevMode))
lpDevMode = GlobalLock(PrintDlg.hDevMode)
If lpDevMode > 0 Then
CopyMemory ByVal lpDevMode, DevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
End If
'Set the current driver, device, and port name strings
With DevName
.wDriverOffset = 8
.wDeviceOffset = .wDriverOffset + 1 + Len(Printer.DriverName)
.wOutputOffset = .wDeviceOffset + 1 + Len(Printer.Port)
.wDefault = 0
End With
With Printer
DevName.extra = .DriverName & Chr(0) & _
.DeviceName & Chr(0) & .Port & Chr(0)
End With
'Allocate memory for the initial hDevName structure
'and copy the settings gathered above into this memory
PrintDlg.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or _
GMEM_ZEROINIT, Len(DevName))
lpDevName = GlobalLock(PrintDlg.hDevNames)
If lpDevName > 0 Then
CopyMemory ByVal lpDevName, DevName, Len(DevName)
bReturn = GlobalUnlock(lpDevName)
End If
'Call the print dialog up and let the user make changes
If PrintDialog(PrintDlg) Then
'First get the DevName structure.
lpDevName = GlobalLock(PrintDlg.hDevNames)
CopyMemory DevName, ByVal lpDevName, 45
bReturn = GlobalUnlock(lpDevName)
GlobalFree PrintDlg.hDevNames
'Next get the DevMode structure and set the printer
'properties appropriately
lpDevMode = GlobalLock(PrintDlg.hDevMode)
CopyMemory DevMode, ByVal lpDevMode, Len(DevMode)
bReturn = GlobalUnlock(PrintDlg.hDevMode)
GlobalFree PrintDlg.hDevMode
NewPrinterName = UCase$(Left(DevMode.dmDeviceName, InStr( _
DevMode.dmDeviceName, Chr$(0)) - 1))
If UCase(Left(Printer.DeviceName, Len(NewPrinterName))) <> UCase( _
NewPrinterName) Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
End If
Next
End If
On Error Resume Next
'Set printer object properties according to selections made
'by user
With Printer
.PaperBin = DevMode.dmDefaultSource
.Copies = DevMode.dmCopies
.Duplex = DevMode.dmDuplex
.Orientation = DevMode.dmOrientation
End With
ueDeviceName = (Left(DevMode.dmDeviceName, InStr(DevMode.dmDeviceName, _
Chr$(0)) - 1))
uePaperBin = DevMode.dmDefaultSource
ueCopies = DevMode.dmCopies
ueDuplex = DevMode.dmDuplex
ueOrientation = DevMode.dmOrientation
ueQuality = DevMode.dmPrintQuality
On Error GoTo 0
Set GetPrinter = Printer
Else
ueDeviceName = ""
uePaperBin = ""
ueCopies = ""
ueDuplex = ""
ueOrientation = ""
ueQuality = ""
Set GetPrinter = Nothing
End If
End Function Das hat bisher auch wunderbar geklappt-wenn wir nicht unsere Clients auf Win 8.1 bzw Win 7 umgestellt hätten.
Bei devMode.dmCopies steht egal, wieviel Kopien man in dem Druckerdialog wählt, immer eine 1 drinne.
Gibt es da vielleicht einen anderen "Hack" ?
Vielen Dank + Viele Grüße,
Stephan
__________________
Heute ist nicht mein Tag.
|