VB中擷取指定印表機的各種紙張類型及大小

來源:互聯網
上載者:User
列印   放入一個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 LongWith fgd1
    .Clear
   
    .FormatString = "^紙張編號|^紙張名稱|^紙張長度|^紙張寬度"
    For i = 0 To .Cols - 1
        .ColWidth(i) = 1700
    Next i
    .AllowUserResizing = flexResizeColumns
    .Left = 0
    .Width = Me.ScaleWidth
End WithGetPaperInfoEnd SubPrivate 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&)'顯示在表格中
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 SubPrivate Sub Form_Resize()
With fgd1
    .Left = 0
    .Width = Me.ScaleWidth
    .Height = Me.ScaleHeight
    .Top = 0
End WithEnd Sub

相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。