Prikazi cijelu temu 14.12.2010 22:45
zxz Van mreze
Administrator
Registrovan od:03.02.2009
Lokacija:Tuzla


Predmet:Re: Poruka o završetku printanja, dali može?
Nastavak koda.
PreuzmiIzvorni kôd (Visual Basic):
  1. Public Function CheckPrinter(PrinterStr As String, JobStr As String) As String
  2.    Dim hPrinter As Long
  3.    Dim ByteBuf As Long
  4.    Dim BytesNeeded As Long
  5.    Dim PI2 As PRINTER_INFO_2
  6.    Dim JI2 As JOB_INFO_2
  7.    Dim PrinterInfo() As Byte
  8.    Dim JobInfo() As Byte
  9.    Dim result As Long
  10.    Dim LastError As Long
  11.    Dim PrinterName As String
  12.    Dim tempStr As String
  13.    Dim NumJI2 As Long
  14.    Dim pDefaults As PRINTER_DEFAULTS
  15.    Dim I As Integer
  16.    
  17.    'Set a default return value if no errors occur.
  18.   CheckPrinter = "Printer info retrieved"
  19.    
  20.    'NOTE: You can ***** printer from the Printers Collection
  21.   'or use the EnumPrinters() API to select a printer name.
  22.  
  23.    'Use the default printer of Printers collection.
  24.   'This is typically, but not always, the system default printer.
  25. [color=#FF0000]  'Ovdje kopira ime printera iz tabele[/color]
  26.   PrinterName = "\\SERVER\Samsung ML-1640 Series"
  27.    'Set desired access security setting.
  28.   pDefaults.DesiredAccess = PRINTER_ACCESS_USE
  29.    
  30.    'Call API to get a handle to the printer.
  31.   result = OpenPrinter(PrinterName, hPrinter, pDefaults)
  32.    If result = 0 Then
  33.       'If an error occurred, display an error and exit sub.
  34.      CheckPrinter = "Cannot open printer " & PrinterName & _
  35.          ", Error: " & Err.LastDllError
  36.       Exit Function
  37.    End If
  38.  
  39.    'Init BytesNeeded
  40.   BytesNeeded = 0
  41.  
  42.    'Clear the error object of any errors.
  43.   Err.Clear
  44.  
  45.    'Determine the buffer size that is needed to get printer info.
  46.   result = GetPrinter(hPrinter, 2, 0&, 0&, BytesNeeded)
  47.    
  48.    'Check for error calling GetPrinter.
  49.   If Err.LastDllError <> ERROR_INSUFFICIENT_BUFFER Then
  50.       'Display an error message, close printer, and exit sub.
  51.      CheckPrinter = " > GetPrinter Failed on initial call! <"
  52.       ClosePrinter hPrinter
  53.       Exit Function
  54.    End If
  55.    
  56.    'Note that in Charles Petzold's book "Programming Windows 95," he
  57.   'states that because of a problem with GetPrinter on Windows 95 only, you
  58.   'must allocate a buffer as much as three times larger than the value
  59.   'returned by the initial call to GetPrinter. This is not done here.
  60.   ReDim PrinterInfo(1 To BytesNeeded)
  61.    
  62.    ByteBuf = BytesNeeded
  63.    
  64.    'Call GetPrinter to get the status.
  65.   result = GetPrinter(hPrinter, 2, PrinterInfo(1), ByteBuf, _
  66.      BytesNeeded)
  67.    
  68.    'Check for errors.
  69.   If result = 0 Then
  70.       'Determine the error that occurred.
  71.      LastError = Err.LastDllError()
  72.      
  73.       'Display error message, close printer, and exit sub.
  74.      CheckPrinter = "Couldn't get Printer Status!  Error = " _
  75.          & LastError
  76.       ClosePrinter hPrinter
  77.       Exit Function
  78.    End If
  79.  
  80.    'Copy contents of printer status byte array into a
  81.   'PRINTER_INFO_2 structure to separate the individual elements.
  82.   CopyMemory PI2, PrinterInfo(1), Len(PI2)
  83.    
  84.    'Check if printer is in ready state.
  85.   PrinterStr = CheckPrinterStatus(PI2.Status)
  86.    
  87.    'Add printer name, driver, and port to list.
  88.   PrinterStr = PrinterStr & "Printer Name = " & _
  89.      GetString(PI2.pPrinterName) & vbCrLf
  90.    PrinterStr = PrinterStr & "Printer Driver Name = " & _
  91.      GetString(PI2.pDriverName) & vbCrLf
  92.    PrinterStr = PrinterStr & "Printer Port Name = " & _
  93.      GetString(PI2.pPortName) & vbCrLf
  94.    
  95.    'Call API to get size of buffer that is needed.
  96.   result = EnumJobs(hPrinter, 0&, &HFFFFFFFF, 2, ByVal 0&, 0&, _
  97.       BytesNeeded, NumJI2)
  98.    
  99.    'Check if there are no current jobs, and then display appropriate message.
  100.   If BytesNeeded = 0 Then
  101.       JobStr = "No Print Jobs!"
  102.    Else
  103.       'Redim byte array to hold info about print job.
  104.      ReDim JobInfo(0 To BytesNeeded)
  105.      
  106.       'Call API to get print job info.
  107.      result = EnumJobs(hPrinter, 0&, &HFFFFFFFF, 2, JobInfo(0), _
  108.         BytesNeeded, ByteBuf, NumJI2)
  109.      
  110.       'Check for errors.
  111.      If result = 0 Then
  112.          'Get and display error, close printer, and exit sub.
  113.         LastError = Err.LastDllError
  114.          CheckPrinter = " > EnumJobs Failed on second call! <  Error = " _
  115.             & LastError
  116.          ClosePrinter hPrinter
  117.          Exit Function
  118.       End If
  119.      
  120.       'Copy contents of print job info byte array into a
  121.      'JOB_INFO_2 structure to separate the individual elements.
  122.      For I = 0 To NumJI2 - 1   ' Loop through jobs and walk the buffer
  123.          CopyMemory JI2, JobInfo(I * Len(JI2)), Len(JI2)
  124.              
  125.           ' List info available on Jobs.
  126.          Debug.Print "Job ID" & vbTab & JI2.JobId
  127.           Debug.Print "Name Of Printer" & vbTab & _
  128.             GetString(JI2.pPrinterName)
  129.           Debug.Print "Name Of Machine That Created Job" & vbTab & _
  130.             GetString(JI2.pMachineName)
  131.           Debug.Print "Print Job Owner's Name" & vbTab & _
  132.             GetString(JI2.pUserName)
  133.           Debug.Print "Name Of Document" & vbTab & GetString(JI2.pDocument)
  134.           Debug.Print "Name Of User To Notify" & vbTab & _
  135.             GetString(JI2.pNotifyName)
  136.           Debug.Print "Type Of Data" & vbTab & GetString(JI2.pDatatype)
  137.           Debug.Print "Print Processor" & vbTab & _
  138.             GetString(JI2.pPrintProcessor)
  139.           Debug.Print "Print Processor Parameters" & vbTab & _
  140.             GetString(JI2.pParameters)
  141.           Debug.Print "Print Driver Name" & vbTab & _
  142.             GetString(JI2.pDriverName)
  143.           Debug.Print "Print Job 'P' Status" & vbTab & _
  144.             GetString(JI2.pStatus)
  145.           Debug.Print "Print Job Status" & vbTab & JI2.Status
  146.           Debug.Print "Print Job Priority" & vbTab & JI2.Priority
  147.           Debug.Print "Position in Queue" & vbTab & JI2.Position
  148.           Debug.Print "Earliest Time Job Can Be Printed" & vbTab & _
  149.             JI2.StartTime
  150.           Debug.Print "Latest Time Job Will Be Printed" & vbTab & _
  151.             JI2.UntilTime
  152.           Debug.Print "Total Pages For Entire Job" & vbTab & JI2.TotalPages
  153.           Debug.Print "Size of Job In Bytes" & vbTab & JI2.Size
  154.           'Because of a bug in Windows NT 3.51, the time member is not set correctly.
  155.          'Therefore, do not use the time member on Windows NT 3.51.
  156.          Debug.Print "Elapsed Print Time" & vbTab & JI2.time
  157.           Debug.Print "Pages Printed So Far" & vbTab & JI2.PagesPrinted
  158.              
  159.           'Display basic job status info.
  160.          JobStr = JobStr & "Job ID = " & JI2.JobId & _
  161.              vbCrLf & "Total Pages = " & JI2.TotalPages & vbCrLf
  162.          
  163.           tempStr = ""   'Clear
  164.          'Check for a ready state.
  165.          If JI2.pStatus = 0& Then   ' If pStatus is Null, check Status.
  166.            If JI2.Status = 0 Then
  167.                tempStr = tempStr & "Ready!  " & vbCrLf
  168.             Else  'Check for the various print job states.
  169.               If (JI2.Status And JOB_STATUS_SPOOLING) Then
  170.                   tempStr = tempStr & "Spooling  "
  171.                End If
  172.                
  173.                If (JI2.Status And JOB_STATUS_OFFLINE) Then
  174.                   tempStr = tempStr & "Off line  "
  175.                End If
  176.                
  177.                If (JI2.Status And JOB_STATUS_PAUSED) Then
  178.                   tempStr = tempStr & "Paused  "
  179.                End If
  180.                
  181.                If (JI2.Status And JOB_STATUS_ERROR) Then
  182.                   tempStr = tempStr & "Error  "
  183.                End If
  184.                
  185.                If (JI2.Status And JOB_STATUS_PAPEROUT) Then
  186.                   tempStr = tempStr & "Paper Out  "
  187.                End If
  188.                
  189.                If (JI2.Status And JOB_STATUS_PRINTING) Then
  190.                   tempStr = tempStr & "Printing  "
  191.                End If
  192.                
  193.                If (JI2.Status And JOB_STATUS_USER_INTERVENTION) Then
  194.                   tempStr = tempStr & "User Intervention Needed  "
  195.                End If
  196.                
  197.                If Len(tempStr) = 0 Then
  198.                   tempStr = "Unknown Status of " & JI2.Status
  199.                End If
  200.             End If
  201.         Else
  202.             ' Dereference pStatus.
  203.            tempStr = PtrCtoVbString(JI2.pStatus)
  204.         End If
  205.          
  206.           'Report the Job status.
  207.          JobStr = JobStr & tempStr & vbCrLf
  208.           Debug.Print JobStr & tempStr
  209.       Next I
  210.    End If
  211.    
  212.    'Close the printer handle.
  213.   ClosePrinter hPrinter
  214. End Function

Obrati paznju sto je obiljezeno crvenim.
Tu trebas upisati ime tvog printera iz tabele sa podacima iz predhodnog koda.
Onaj kod ti nece vise trebati.
Bar ne za ovo sto ti treba pa ga mozes i skloniti. Bio je samo zbog toga da ti da pravo ime printera.
Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.