I have managed to retreive all the papers/names supported by a printer.
Do I have to compare all the values to those listed in devmode (40 + ) in
order to display them? Is there a better way of going about it?
Any assistance is appreciated.
Regards,
Reena
Option Explicit
Const DC_PAPERNAMES = 16
Const DC_PAPERS = 2
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
ByVal dev As Long) As Long
Private Sub cboPaperSize_Click()
Printer.PaperSize = cboPaperSize.ItemData(cboPaperSize.ListIndex)
MsgBox "Paper size set to: " & Printer.PaperSize & _
" (" & cboPaperSize.List(cboPaperSize.ListIndex) & ")"
End Sub
Private Sub Form_Load()
FillPaperCombo
cboPaperSize.ListIndex = 0
End Sub
Private Sub FillPaperCombo()
Dim dwpapers As Long
Dim ct As Long
Dim nameslist As String
Dim paperinfo As String
Dim PaperNum As Long
Dim numPaper() As Integer
cboPaperSize.Clear
dwpapers = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
DC_PAPERS, ByVal vbNullString, 0)
ReDim numPaper(1 To dwpapers)
nameslist = String(64 * dwpapers, 0)
dwpapers = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
DC_PAPERS, numPaper(1), 0)
dwpapers = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
DC_PAPERNAMES, ByVal nameslist, 0)
For ct = 1 To dwpapers
paperinfo = Mid(nameslist, 64 * (ct - 1) + 1, 64)
PaperNum = numPaper(ct)
cboPaperSize.AddItem paperinfo
cboPaperSize.ItemData(cboPaperSize.NewIndex) = PaperNum
Next ct
End Sub
For i = 0 To cboPaperSize.ListCount - 1
If cboPaperSize.ItemData(i) = Printer.PaperSize Then
cboPaperSize.ListIndex = i
End If
Next i
That way, when the form first loads, your just making the combobox text
reflect the current papersize, rather that explicity changing it to the
papersize that appears first in the list.