Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Device Capabilities : PaperNames

0 views
Skip to first unread message

Reena Rajdev

unread,
Aug 17, 2001, 5:34:29 AM8/17/01
to
Hi,

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


db

unread,
Aug 17, 2001, 9:42:20 AM8/17/01
to
Try this. Add a combo box to your form and call it cboPaperSize...then
paste this code into the form:

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


db

unread,
Aug 17, 2001, 10:10:21 AM8/17/01
to
You may want to replace the cboPaperSize.ListIndex = 0 in the FormLoad()
event with the following:

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.


0 new messages