Private Const DC_PAPERNAMES = 16
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
'http://www.csdn.net/expert/Topic/463/463443.shtm
Private Sub Form_Load()
Dim i As Integer
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long, PaperSizes() As Byte, Cnt As Long, AllNames As String
Dim lStart As Long, lEnd As Long
'Retrieve the number of available paper names
Ret = DeviceCapabilities(Printer.DeviceName, "LPT1", DC_PAPERNAMES, ByVal 0&, ByVal 0&)
'resize the array
ReDim PaperSizes(1 To Ret * 64) As Byte
'retrieve all the available paper names
Call DeviceCapabilities(Printer.DeviceName, "LPT1", DC_PAPERNAMES, PaperSizes(1), ByVal 0&)
'set the form's graphic mode to persistent
Me.AutoRedraw = True
Me.Print "Supported papersizes:"
'convert the retrieved byte array to a string
AllNames = StrConv(PaperSizes, vbUnicode)
'loop through the string and search for the names of the papers
Do
lEnd = InStr(lStart + 1, AllNames, Chr$(0), vbBinaryCompare)
If (lEnd > 0) And (lEnd - lStart - 1 > 0) Then
'Combo1.AddItem Mid$(AllNames, lStart + 1, lEnd - lStart - 1)
Me.Print Mid$(AllNames, lStart + 1, lEnd - lStart - 1)
'Me.Print AllNames
End If
lStart = lEnd
Loop Until lEnd = 0
End Sub