在往打印机发送打印命令后,如何知道打印是否成功,或发生错误的原因?最好有代码。

解决方案 »

  1.   

    API:EnumJobs 
    Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long
    Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    Private Declare Function EnumJobs Lib "winspool.drv" Alias "EnumJobsA" (ByVal hPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, pJob As Any, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
    Private Sub Form_Load()    Dim hPrinter As Long, lNeeded As Long, lReturned As Long
        Dim lJobCount As Long
        OpenPrinter Printer.DeviceName, hPrinter, ByVal 0&
        EnumJobs hPrinter, 0, 99, 1, ByVal 0&, 0, lNeeded, lReturned
        If lNeeded > 0 Then
            ReDim byteJobsBuffer(lNeeded - 1) As Byte
            EnumJobs hPrinter, 0, 99, 1, byteJobsBuffer(0), lNeeded, lNeeded, lReturned
            If lReturned > 0 Then
                lJobCount = lReturned
            Else
                lJobCount = 0
            End If
        Else
            lJobCount = 0
        End If
        ClosePrinter hPrinter
        MsgBox "Jobs in printer queue: " + CStr(lJobCount), vbInformation
    End Sub
      

  2.   

    看看这个:Const PT_LINETO = &H2
    Const PT_BEZIERTO = &H4
    Const PT_CLOSEFIGURE = &H1
    Const DI_APPBANDING = &H1
    Const DI_ROPS_READ_DESTINATION = &H2
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Type DOCINFO
            cbSize As Long
            lpszDocName As String
            lpszOutput As String
            lpszDatatype As String
            fwType As Long
    End Type
    Private Declare Function PolyDraw Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, lpbTypes As Byte, ByVal cCount As Long) As Long
    Private Declare Function StartDoc Lib "gdi32" Alias "StartDocA" (ByVal hdc As Long, lpdi As DOCINFO) As Long
    Private Declare Function StartPage Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function EndPage Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function EndDoc Lib "gdi32" (ByVal hdc As Long) As Long
    Private Sub Form_Load()    Dim Pt(1 To 2) As POINTAPI, bTypes(1 To 2) As Byte, DI As DOCINFO
        'fill the DOCINFO-structure
        DI.cbSize = Len(DI)
        DI.lpszDocName = "API-Guide Code Demonstration"
        DI.lpszOutput = vbNullString
        DI.lpszDatatype = vbNullString
        'starts a print job
        Call StartDoc(Printer.hdc, DI)
        'prepare the printer driver to accept data
        Call StartPage(Printer.hdc)
        Pt(2).x = 50
        Pt(2).y = 30
        bTypes(1) = PT_LINETO
        bTypes(2) = PT_LINETO
        'draw a set of line segments
        PolyDraw Printer.hdc, Pt(1), bTypes(1), 2
        'inform the device that the application has finished writing to a page
        Call EndPage(Printer.hdc)
        'end the print job
        Call EndDoc(Printer.hdc)
    End Sub
      

  3.   

    楼上的兄弟,能不能解释一下代码呢。我对API不太熟悉