Private Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Private Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As DEVMODE
DesiredAccess As Long
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Function GetPaperNames(strPrinterName As String) As String
' Uses the DeviceCapabilities API function to display a
' message with the name of the default printer and a
' list of the paper it supports.
Dim lngPaperCount As Long
Dim lngCounter As Long
Dim strDeviceName As String
Dim strDevicePort As String
Dim strPaperNameList As String
Dim strPaperName As String
Dim intLength As Integer
Dim strMsg As String
Dim intPaperNumber() As Integer
Dim P As Printer
Dim Pnt() As POINTAPI
Dim strTemp As String, intTemp As Integer
For Each P In Printers
If P.DeviceName = strPrinterName Then Exit For
Next P
On Error GoTo GetPaperNames_Err
' Get name and port of the default printer.
strDeviceName = P.DeviceName
strDevicePort = P.Port
' Get count of paper bin names supported by printer.
lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, lpPort:=strDevicePort, iIndex:=DC_PAPERNAMES, lpOutput:=ByVal vbNullString, lpDevMode:=DEFAULT_VALUES)
' Re-dimension arrays to count of paper names.
ReDim intPaperNumber(1 To lngPaperCount)
ReDim Pnt(1 To lngPaperCount)
'Pad variable to accept 64 bytes for each paper name.
strPaperNameList = String(Number:=64 * lngPaperCount, Character:=0)
'Get string buffer of paper names supported by printer.
lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, lpPort:=strDevicePort, iIndex:=DC_PAPERNAMES, lpOutput:=ByVal strPaperNameList, lpDevMode:=DEFAULT_VALUES)
'Get array of paper numbers supported by printer
lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, lpPort:=strDevicePort, iIndex:=DC_PAPERS, lpOutput:=intPaperNumber(1), lpDevMode:=0)
'get point list of paper sizes for each paper
lngPaperCount = DeviceCapabilities(lpsDeviceName:=strDeviceName, lpPort:=strDevicePort, iIndex:=DC_PAPERSIZE, lpOutput:=Pnt(1), lpDevMode:=0)
'List available paper names.
strMsg = "Paper available for " & strDeviceName & vbCrLf
For lngCounter = 1 To lngPaperCount
' Parse a paper name from string buffer.
strPaperName = Mid(String:=strPaperNameList, Start:=64 * (lngCounter - 1) + 1, Length:=64)
intLength = VBA.InStr(Start:=1, String1:=strPaperName, String2:=Chr(0)) - 1
strPaperName = Left(String:=strPaperName, Length:=intLength)
' Add bin name and number to text string for message box.
strMsg = strMsg & vbCrLf & strTemp & vbTab & "X=" & Pnt(lngCounter).X & vbTab & "Y=" & Pnt(lngCounter).Y
Next lngCounter
' Show paper bin numbers and names in message box.
'MsgBox Prompt:=strMsg
Thanks vb5, I have a couple of questions/requests.
First in your UDT 'DEVMODE' you have two constants that are not defined 'CCHDEVICENAME' and 'CCHFORMNAME'. Can you post thier values? I am not sure if the code will work properly if I comment them out.
Second you call a function called 'DeviceCapabilities' in the code. Could you possibly post that function as well? Or give me information on where to find it.
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpsDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
ByVal lpDevMode As Long) As Long
[/tt]
Please note that the DeviceCapabilities API that I am using here has been modified from its origional form which follows...
[tt]
Public Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, ByVal lpPort As String, ByVal iIndex As Long, ByVal lpOutput As String, lpDevMode As DEVMODE) As Long
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.