VB的代码<br>'*********************************************************************<br>' Add a list of the available paper sources for <PrinterName> to<br>' the combobox <cbo><br>'*********************************************************************<br>Public Sub EnumPrinterBins(PrinterName As String, cbo As ComboBox)<br> Dim prn As Printer<br> Dim hPrinter As Long ' Handle of the selected printer<br> Dim dwbins As Long ' The number of paperbins in the printer<br> Dim i As Long ' counter<br> Dim nameslist As String ' The string returned with all the bin names<br> Dim NameBin As String ' The parsed bin name<br> Dim numBin() As Integer ' Used as part of the DeviceCapabilities API call<br> Dim szBinID As String<br> <br> cbo.Clear<br> For Each prn In Printers<br> ' Look through all the currently installed printers<br> If prn.DeviceName = PrinterName Then<br> ' We've found our printer -- open a handle to it<br> If OpenPrinter(prn.DeviceName, hPrinter, 0) <> 0 Then<br> ' Get the available bin numbers<br> dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br> DC_BINS, ByVal vbNullString, 0)<br> ReDim numBin(1 To dwbins)<br> nameslist = String(24 * dwbins, 0)<br> szBinID = String(1000, 0)<br> dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br> DC_BINS, numBin(1), 0)<br> dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br> DC_BINNAMES, ByVal nameslist, 0)<br> 'MsgBox Len(nameslist)<br> For i = 1 To dwbins<br> ' For each bin number, add its corresponding name<br> ' to our combo box<br> <br> NameBin = Mid(nameslist, 24 * (i - 1) + 1, 24)<br> NameBin = Left(NameBin, InStr(NameBin, Chr(0)) - 1)<br> cbo.AddItem NameBin & "/" & numBin(i)<br> <br> cbo.ItemData(cbo.NewIndex) = numBin(i)<br> Next i<br> ' Close the printer<br> Call ClosePrinter(hPrinter)<br> Else<br> ' OpenPrinter failed, so we can't retrieve information about it<br> cbo.AddItem prn.DeviceName & " <Unavailable>"<br> End If<br> End If<br> Next prn<br>End Sub<br>