zoukankan      html  css  js  c++  java
  • VB 获取默认打印机的状态


    如何获取默认打印机的状态,包括缺纸、卡纸、无连接等状态,还有将某文件打印后,如何得知打印成功? 
    Option Explicit
    Declare Function MapPhysToLin Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysSize As Long, ByRef PhysMemHandle) As Long
    Declare Function UnmapPhysicalMemory Lib "WinIo.dll" (ByVal PhysMemHandle, ByVal LinAddr) As Boolean
    Declare Function GetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByRef PhysVal As Long) As Boolean
    Declare Function SetPhysLong Lib "WinIo.dll" (ByVal PhysAddr As Long, ByVal PhysVal As Long) As Boolean
    Declare Function GetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByRef PortVal As Long, ByVal bSize As Byte) As Boolean
    Declare Function SetPortVal Lib "WinIo.dll" (ByVal PortAddr As Integer, ByVal PortVal As Long, ByVal bSize As Byte) As Boolean
    Declare Function InitializeWinIo Lib "WinIo.dll" () As Boolean
    Declare Function ShutdownWinIo Lib "WinIo.dll" () As Boolean
    Declare Function InstallWinIoDriver Lib "WinIo.dll" (ByVal DriverPath As String, ByVal Mode As Integer) As Boolean
    Declare Function RemoveWinIoDriver Lib "WinIo.dll" () As Boolean
    Public IOStat As Boolean
    '************************************************************
    '* 函数名称:GetPrnStat *
    '* 功能:根据打印机的内存地址,检测打印机的目前工作状态 *
    '* 参数:lptport: 要检测的打印机的端口号,如LPT1: *
    '* 返回值:打印机的工作状态值。 *
    '* 0:正常 1:缺纸 2:无联系 3:异常(其他错误) *
    '* 调用:本模块中的API函数InitializeWinIo和GetPortVal *
    '* 备注:检测的内存地址,是在打印端口所在的基地址上加1; *
    '* 作者:谷霖 *
    '* LPT1口的基地址为&H378;LPT2口的基地址为&H278 *
    '************************************************************
    Public Function GetPrnStat(ByVal LptPort As String) As Long
    Dim PrnAddr As Long
    On Error Resume Next
    If IOStat = False Then IOStat = InitializeWinIo()
    If IOStat Then
    If UCase(LptPort) = "LPT1:" Then
    PrnAddr = &H379
    ElseIf UCase(LptPort) = "LPT2:" Then
    PrnAddr = &H279
    End If
    GetPortVal PrnAddr, GetPrnStat, 1
    Else
    GetPrnStat = &HFF
    End If
    GetPrnStat = GetPrnStat And &HF8
    Select Case GetPrnStat
    Case &H68, &H58, &H70
    GetPrnStat = 1 '缺纸
    Case &H78
    GetPrnStat = 2 '无联系
    Case &HD8
    GetPrnStat = 0 '正常
    Case Else
    GetPrnStat = 3 '异常
    End Select
    End Function

    '*************************************************************************
    '* 函数功能:检查打印机的状态主函数 *
    '* 输入参数:PrintName 要检测的打印机名称 *
    '* 输出参数:checkprinterr *
    '* 检查结果(0:正常 1:打印机缺纸 2:打印机无联系 3:打印机异常 *
    '* 4:没有安装打印机 5:打印机名称错误) *
    '*************************************************************************
    Public Function CheckPrintErr(ByVal PrintName As String) As Long
    'CheckPrintErr参数说明
    '0:没有错误
    '1:打印机无联系
    '2:打印机缺纸
    '3:没有安装打印机
    Dim printjieguo As Long
    Dim i As Long, k As Long
    On Error GoTo ErrCheckPrint

    If Printers.Count = 0 Then
    CheckPrintErr = 4 '没有安装打印机
    Exit Function
    End If
    '检测发票打印机是否可以联系
    For i = 0 To Printers.Count - 1
    If (Printers(i).DeviceName = PrintName) Then
    k = k + 1
    Exit For
    End If
    Next
    If k = 0 Then '打印机名称错误
    CheckPrintErr = 5
    Exit Function
    End If
    Set Printer = Printers(i)

    CheckPrintErr = GetPrnStat(Printer.Port)
    Exit Function
    ErrCheckPrint:
    CheckPrintErr = 3
    Exit Function
    End Function

    用vb编程怎么获得打印机列表内容?

    在VB中有一个Printers对象,包含了本机安装的所有打印机。 
    For Each p In Printers
    MsgBox p.DeviceName
    Next
  • 相关阅读:
    监控网速
    nginx与apache 对比 apache是同步多进程模型,一个连接对应一个进程;nginx是异步的,多个连接(万级别)可以对应一个进程
    shell 爬虫
    shell 读写远程数据库
    tmp
    交换分区 在dd命令执行期间 top 其消耗系统约14%的cpu,而mem占比约为0
    中间变量 加层 对解决问题的思路 逆序生成
    ALLOWED_HOSTS = ['*']
    搭建一个简单的Python的Web环境 监控服务器内存 线程 进程 网络
    小米加步枪
  • 原文地址:https://www.cnblogs.com/rosesmall/p/3140417.html
Copyright © 2011-2022 走看看