VB中获取指定打印机的各种纸张类型及大小

放入一个MSFlexGrid,名称为fgd1,列数为4
'Option Explicit
Private Const DC_MAXEXTENT = 5
Private Const DC_MINEXTENT = 4
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_PAPERSIZE = 3
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 Type POINTS
        x  As Long
        y  As Long
End Type
Private Sub Form_Load()
Dim i As Long
With fgd1
    .Clear
   
    .FormatString = "^纸张编号|^纸张名称|^纸张长度|^纸张宽度"
    For i = 0 To .Cols - 1
        .ColWidth(i) = 1700
    Next i
    .AllowUserResizing = flexResizeColumns
    .Left = 0
    .Width = Me.ScaleWidth
End With
GetPaperInfo
End Sub
Private Sub GetPaperInfo()
Dim i As Long, ret As Long
Dim Length As Integer, Width As Integer
Dim PaperNo() As Integer, PaperName() As String, PaperSize() As POINTS
'支持最大打印纸:
ret = DeviceCapabilities(打印机名称, "LPT1", DC_MAXEXTENT, ByVal 0&, ByVal 0&)
Length = ret / 65536
Width = ret - Length * 65536
'lblMaxLength.Caption = Length
'lblMaxWidth.Caption = Width
'支持最小打印纸:
ret = DeviceCapabilities(打印机名称, "LPT1", DC_MINEXTENT, ByVal 0&, ByVal 0&)
Length = ret / 65536
Width = ret - Length * 65536

'支持纸张种类数
ret = DeviceCapabilities(打印机名称, "LPT1", DC_PAPERS, ByVal 0&, ByVal 0&)
'纸张编号
ReDim PaperNo(1 To ret) As Integer
Call DeviceCapabilities(打印机名称, "LPT1", DC_PAPERS, PaperNo(1), ByVal 0&)
'纸张名称
Dim arrPageName() As Byte
Dim allNames As String
Dim lStart As Long, lEnd As Long
ReDim PaperName(1 To ret) As String
ReDim arrPageName(1 To ret * 64) As Byte
Call DeviceCapabilities(打印机名称, "LPT1", DC_PAPERNAMES, arrPageName(1), ByVal 0&)
allNames = StrConv(arrPageName, vbUnicode)
'loop through the string and search for the names of the papers
i = 1
Do
    lEnd = InStr(lStart + 1, allNames, Chr$(0), vbBinaryCompare)
    If (lEnd > 0) And (lEnd - lStart - 1 > 0) Then
        PaperName(i) = Mid$(allNames, lStart + 1, lEnd - lStart - 1)
        i = i + 1
    End If
    lStart = lEnd
Loop Until lEnd = 0
'纸张尺寸
ReDim PaperSize(1 To ret) As POINTS
'Call DeviceCapabilities(Form2.Combo1.Text, "LPT1", DC_PAPERSIZE, PaperSize(1), ByVal 0&)
'注:上行有更改,更改代码如下:  Modify By CHX 20060428
Call DeviceCapabilities(打印机名称, "LPT1", DC_PAPERSIZE, PaperSize(1), ByVal 0&)
'显示在表格中
For i = 1 To ret
    fgd1.AddItem PaperNo(i) & vbTab & PaperName(i) & vbTab & PaperSize(i).y & vbTab & PaperSize(i).x
Next i
'移除第一个空行
fgd1.Row = 1
fgd1.RemoveItem 1

End Sub
Private Sub Form_Resize()
With fgd1
    .Left = 0
    .Width = Me.ScaleWidth
    .Height = Me.ScaleHeight
    .Top = 0
End With
End Sub
  • 0
    点赞
  • 3
    收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论 7

打赏作者

还想懒够

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值