csantos
Feb 21st, 2001, 10:07 AM
How can i get Printer Available Trays???? And all that information associated to a printer?
Thanks,
Arcom
Feb 22nd, 2001, 05:40 PM
You can use the DeviceCapabilities (http://msdn.microsoft.com/library/psdk/gdi/prntspol_21bn.htm) API call.
csantos
Feb 23rd, 2001, 10:08 AM
Thanks,
But can someone give me an example of how to use this API? (DeviceCapabilities)
Arcom
Feb 23rd, 2001, 04:37 PM
Here ya go...
This example retrieves supported paper sizes. Taken from API Guide (http://www.allapi.net/agnet/apiguide.php).
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, lpDevMode As Any) As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long, PaperSizes() As Integer
' First find out how many array fields do we need (by sending 0& for lpOutput and lpDevMode)
Ret = DeviceCapabilities(Printer.DeviceName, "LPT1", DC_PAPERS, ByVal 0&, ByVal 0&)
' Resize array to accept required data
ReDim PaperSizes(1 To Ret) As Integer
' Call the function again, but this time to retrieve the actual data
Call DeviceCapabilities(Printer.DeviceName, "LPT1", DC_PAPERS, PaperSizes(1), ByVal 0&)
Me.AutoRedraw = True
Me.Print "Supported papersizes:"
Dim Cnt As Long
For Cnt = 1 To Ret
Me.Print Str$(PaperSizes(Cnt))
Next
End Sub
You can easily get any parameter (look at MSDN's page for available params - link above). First call to DeviceCapabilities returns the number of bytes required for the output data and the second call retrieves the actual data (you just have to resize the buffer array).