VB3: Obtain and Change the Paper Bins for the Default PrinterID: Q96797
|
By using the Windows API Escape() function, an application can change the
paper bin on the printer and obtain a list of available paper bins for the
default printer.
To return a list of paper bin names and a list of corresponding of bin
numbers, pass the ENUMPAPERBINS printer escape constant to the Escape()
function. You can use the first list to display the available paper bins
for the user, and use the second list to change the paper bin.
To change the paper bin, pass the GETSETPAPERBINS printer escape constant
along with the bin number to the Escape() function. GETSETPAPERBINS returns
the current bin and the number of bins supported by the default printer.
The example code listed below demonstrates how to use both ENUMPAPERBINS
and GETSETPAPERBINS with the Windows API Escape() function.
Global Const MaxBins = 6
Type PaperBin ' Used for EnumPaperBins
BinList(1 To MaxBins) As Integer
PaperNames(1 To MaxBins) As String * 24
End Type
Type BinInfo ' Used for GetSetPaperBins
CurBinNumber As Integer ' Current Bin
NumBins As Integer ' Number of bins supported by printer
Reserved1 As Integer ' Reserved
Reserved2 As Integer ' Reserved
Reserved3 As Integer ' Reserved
Reserved4 As Integer ' Reserved
End Type
'Enter each of the following Declare statements on one, single line.
Declare Function EnumPaperBinEscape% Lib "GDI" Alias "Escape"
(ByVal hDC%, ByVal nEscape%, ByVal nCount%, NumBins%,
lpOutData As Any)
Declare Function GetPaperBinEscape% Lib "GDI" Alias "Escape"
(ByVal hDC%, ByVal nEscape%, ByVal nCount%, InBinInfo As Any,
OutBinInfo As Any)
Global Const ENUMPAPERBINS = 31
Global Const GETSETPAPERBINS = 29
Sub Command1_Click ()
Dim InPaperBin As PaperBin
Dim InBinInfo As BinInfo
' Enter each of the following result% statements on one,
' single line:
result% = GetPaperBinEscape(Printer.hDC, GETSETPAPERBINS, 0,
ByVal 0&, InBinInfo)
result% = EnumPaperBinEscape(Printer.hDC, ENUMPAPERBINS, 2,
MaxBins, InPaperBin)
List1.Clear
For I% = 1 To InBinInfo.NumBins ' Fill list1 with available bins
List1.AddItem InPaperBin.PaperNames(I%)
List1.ItemData(List1.NewIndex) = InPaperBin.BinList(I%)
Next I%
End Sub
Sub List1_Click ()
Dim InBinInfo As BinInfo
Dim NewBinInfo As BinInfo
NewBinInfo.CurBinNumber = List1.ItemData(List1.ListIndex)
' Enter the following result% statement on one, single line.
result% = GetPaperBinEscape(Printer.hDC, GETSETPAPERBINS,
Len(NewBinInfo), NewBinInfo, NewBinInfo)
MsgBox "Sending Sample Output to printer using Bin: " + List1.Text
Printer.Print "This should of have come from Bin: "; List1.Text
Printer.EndDoc
End Sub
Keywords : kbprint
Version : 2.0 3.0
Platform :
Issue type :
Last Reviewed: June 14, 1999