Возможно ли узнать какой документ последний раз печатался? - VB

Узнай цену своей работы

Формулировка задачи:

Есть сетевой принтер. Возможно ли узнать какой документ последний раз печатался? С компьютера на котором подключен принтер. А может есть полная статистика в каком либо INI файле? Скажите пожалуйста. Огромное спасибо.

Решение задачи: «Возможно ли узнать какой документ последний раз печатался?»

textual
Листинг программы
'Module1
Option Explicit
'==========================
'Printers Jobs
'
'VisualSoft
'©2005, Konst Popov
'==========================
Public Const CCHDEVICENAME = 32
Public Const CCHFORMNAME = 32
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Type DEVMODE
    dmDeviceName As String * CCHDEVICENAME
    dmSpecVersion As Integer
    dmDriverVersion As Integer
    dmSize As Integer
    dmDriverExtra As Integer
    dmFields As Long
    dmOrientation As Integer
    dmPaperSize As Integer
    dmPaperLength As Integer
    dmPaperWidth As Integer
    dmScale As Integer
    dmCopies As Integer
    dmDefaultSource As Integer
    dmPrintQuality As Integer
    dmColor As Integer
    dmDuplex As Integer
    dmYResolution As Integer
    dmTTOption As Integer
    dmCollate As Integer
    dmFormName As String * CCHFORMNAME
    dmUnusedPadding As Integer
    dmBitsPerPel As Long
    dmPelsWidth As Long
    dmPelsHeight As Long
    dmDisplayFlags As Long
    dmDisplayFrequency As Long
End Type
Public Type PRINTER_DEFAULTS
    pDatatype As String
    pDevMode As DEVMODE
    DesiredAccess As Long
End Type
Public Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Public Type JOB_INFO_1_API
    JobId As Long
    pPrinterName As Long
    pMachineName As Long
    pUserName As Long
    pDocument As Long
    pDatatype As Long
    pStatus As Long
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type
Public Type JOB_INFO_1
    JobId As Long
    pPrinterName As String
    pMachineName As String
    pUserName As String
    pDocument As String
    pDatatype As String
    pStatus As String
    Status As Long
    Priority As Long
    Position As Long
    TotalPages As Long
    PagesPrinted As Long
    Submitted As SYSTEMTIME
End Type
Public Declare Function OpenPrinter Lib 'winspool.drv' Alias 'OpenPrinterA' (ByVal pPrinterName As String, phPrinter As Long, pDefault As PRINTER_DEFAULTS) As Long
Public Declare Function EnumJobs Lib 'winspool.drv' Alias 'EnumJobsA' (ByVal HPrinter As Long, ByVal FirstJob As Long, ByVal NoJobs As Long, ByVal Level As Long, ByVal pJob As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Sub CopyMem Lib 'kernel32.dll' Alias 'RtlMoveMemory' (pTo As Any, uFrom As Any, ByVal lSize As Long)
Public Declare Function CloseHandle Lib 'kernel32.dll' (ByVal hObject As Long) As Long
Private Declare Function lstrlenW Lib 'kernel32.dll' (ByVal lpString As Long) As Long
Private Declare Function HeapAlloc Lib 'kernel32.dll' (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GetProcessHeap Lib 'kernel32.dll' () As Long
Private Declare Function HeapFree Lib 'kernel32.dll' (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
'
Public JobsDesc(0 To 127) As JOB_INFO_1
'
 
Public Function TrimStr(strName As String) As String
'Finds a null then trims the string
Dim x As Integer
    x = InStr(strName, vbNullChar)
    If x > 0 Then TrimStr = Left(strName, x - 1) Else TrimStr = strName
End Function
 
Function LPSTRtoSTRING(ByVal lngPointer As Long) As String  _Name = 'Form1'
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
 
Private Sub chkStart_Click()
    If Me.chkStart.Value = vbChecked Then
        Me.Timer1.Enabled = True
    Else
        Me.Timer1.Enabled = False
    End If
End Sub
 
Private Sub Command1_Click()
Dim i As Integer
 
    i = GetPrinterQueue(Me.Combo1.Text)
    'MsgBox 'Количество запущенных заданий: ' & i
    
    If i > 0 Then
        
        Me.txtOut.Text = 'Кол-во заданий: ' & i & vbCrLf & vbCrLf
    
        For i = 0 To 127
            If JobsDesc(i).JobId > 0 Then
            With Me.txtOut
                .SelText = 'JobID=' & JobsDesc(i).JobId & vbCrLf
                .SelText = 'Document=' & JobsDesc(i).pDocument & vbCrLf
                .SelText = 'MachineName=' & JobsDesc(i).pMachineName & vbCrLf
                .SelText = 'UserName=' & JobsDesc(i).pUserName & vbCrLf
                .SelText = 'TotalPages=' & JobsDesc(i).TotalPages & vbCrLf
                .SelText = vbCrLf
            End With
            End If
        Next i
        
    End If
    
End Sub
 
Private Sub Form_Load()
Dim prn As Printer
 
    Me.Combo1.Clear
    For Each prn In VB.Printers
        Me.Combo1.AddItem prn.DeviceName
    Next prn
    If Me.Combo1.ListCount > 0 Then
        Me.Combo1.ListIndex = 0
    End If
    
End Sub
 
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Me.Timer1.Enabled = False
End Sub
 
Private Sub Timer1_Timer()
    Command1_Click
End Sub

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

15   голосов , оценка 4 из 5
Похожие ответы