GET THE PRINJOB STATUS SOLVED

GET THE PRINJOB STATUS SOLVED

Postby Maurizio » Fri Sep 27, 2013 4:59 pm

Antonio ,
I found in Harbou forum
https://groups.google.com/forum/?fromgr ... MH4zmPJKsJ

a very useful feature to monitor the printer spooler

function CheckJob( hPrinter, nPrintJob )

It would be interesting to use it with the class tPrinter .

My question is:
is it possible from tPrinter have : hPrinter and nPrintJob

hPrinter from
Code: Select all  Expand view
nRet:=OpenPrinter( cPrinter, @hPrinter, NIL )
   hPrinter:=bin2u(hPrinter)
u

nPrintJob from
Code: Select all  Expand view
 nPrintJob:=StartDocPrinter( hPrinter, 1, oDocInfo )
 


Regards Maurizio
http://www.nipeservice.com
Last edited by Maurizio on Tue Oct 01, 2013 10:25 am, edited 1 time in total.
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm

Re: GET THE PRINJOB STATUS SOLVED

Postby Maurizio » Tue Oct 01, 2013 10:24 am

Code: Select all  Expand view
//#include "cstruct.ch"
#include "hbdll.ch"
#include "fivewin.ch"

IMPORT OpenPrinter( par1, par2, par3 ) FROM winspool.drv
IMPORT StartDocPrinter( par1, par2, par3 ) FROM winspool.drv
IMPORT WritePrinter( par1, par2, par3, par4 ) FROM winspool.drv
IMPORT EndDocPrinter( par1 ) FROM winspool.drv
IMPORT ClosePrinter( par1 ) FROM winspool.drv
IMPORT GetJob( par1, par2, par3, par4, par5, par6 ) FROM winspool.drv


   C structure DOC_INFO_1 align 4
      member pDocName    is CTYPE_CHAR_PTR
      member pOutputFile is CTYPE_CHAR_PTR
      member pDataType   is CTYPE_CHAR_PTR
   end C structure

   C structure JOB_INFO_1
      member JobId        is CTYPE_UNSIGNED_LONG
      member pPrinterName is CTYPE_CHAR_PTR
      member pMachineName is CTYPE_CHAR_PTR
      member pUserName    is CTYPE_CHAR_PTR
      member pDocument    is CTYPE_CHAR_PTR
      member pDatatype    is CTYPE_CHAR_PTR
      member pStatus      is CTYPE_CHAR_PTR
      member Status       is CTYPE_UNSIGNED_LONG
      member Priority     is CTYPE_UNSIGNED_LONG
      member Position     is CTYPE_UNSIGNED_LONG
      member TotalPages   is CTYPE_UNSIGNED_LONG
      member PagesPrinted is CTYPE_UNSIGNED_LONG
      member Submitted    is CTYPE_VOID_PTR
   end C structure


function main()
   local i, hPrinter:=u2Bin(0)
   local nPrintJob :=0
   local cPrinter:= GetDefaultPrinter()
   

//-------------------------------------------------------------------------------------------
   local oPrn, oFont
   local nRowStep, nColStep
   local nRow := 0, nCol := 0, n, m
   Local nC := 1
   Local nX := 1
   Local lOk := .f.
   Local cDocu := alltrim(str(seconds()))
   
 
   // ?  "default printer... " + cPrinter
   if !StartPrn( @hPrinter, cPrinter )
      ? "Errore 1 "
      return NIL
   endif
   
   
   
 
  PRINT oPrn TO cPrinter
   
   oPrn:cDocument := cDocu
 
   if Empty( oPrn:hDC )
      ? "Printer was not installed or ready"
         return nil          // Printer was not installed or ready
   endif
   nRowStep = oPrn:nVertRes() / 20   // We want 20 rows
   nColStep = oPrn:nHorzRes() / 15   // We want 15 cols
   PAGE
         oPrn:SayBitmap( 1, 1, "..\bitmaps\fivewin.bmp" )
         
         for n = 1 to 20  // rows
             nCol = 0
             oPrn:Say( nRow, nCol, Str( n, 2 ), oFont )
             nCol += nColStep
             for m = 1 to 15
                oPrn:Say( nRow, nCol, "+", oFont )
                nCol += nColStep
             next
             nRow += nRowStep
         next
         oPrn:Line( 0, 0, nRow, nCol )
      ENDPAGE
  ENDPRINT


  FOR nX := 1 TO 20
     ThreadSleep(1000)
     IF CheckJob(hPrinter, nPrintJob ,cDocu )
        lOk := .t.
        exit
     else
        ThreadSleep(1000)
     endif    
  NEXT
 
  IF ! lOk
     ? "Printer not Ready"
  ELSE
     ? "Printer Ready"  
  ENDIF    
 
  StopPrn( hPrinter )
 

return NIL
//-------------------------------------------------------------------------------------------
Static function StartPrn( hPrinter, cPrinter )
   local nRet

   nRet:=OpenPrinter( cPrinter, @hPrinter, NIL )
   if !( nRet > 0 )
      ? "openprinter error"+str( GetLastError() )+"..."

      return .F.
   endif
   hPrinter:=bin2u(hPrinter)
   
return .T.
//-------------------------------------------------------------------------------------------

Static function StopPrn( hPrinter )
   local nRet
   nRet:=ClosePrinter( hPrinter )
   if !( nRet > 0 )
      ? "closeprinter error"+str( GetLastError() )+"..."
   endif
   
return NIL
//-------------------------------------------------------------------------------------------
Static  function CheckJob(hPrinter, nPrintJob,cDocu )
   local oJob:=(struct JOB_INFO_1)
   local nLenJob:=oJob:sizeof()
   local nRet, nLenBuf, nNeeded:=u2bin(0), cBuf:=NIL
   Local cT := ""
   Local nJob  := 0
   Local lReturn := .t.
   
   FOR nJob := 1 to 100
       // nRet:=GetJob( hPrinter, nPrintJob, 1, @cBuf, 0, @nNeeded )
       nRet:=GetJob( hPrinter, nJob, 1, @cBuf, 0, @nNeeded )
       nLenBuf:=bin2u(nNeeded)
       
       if nLenBuf < nLenJob
          //return .F.
       ELSE
          // ?  "Job:" + STR(nPrintJob)
          cBuf:=oJob:Value() + replicate( chr(0), nLenBuf-nLenJob )
          nRet:=GetJob( hPrinter, nJob, 1, @cBuf, nLenBuf, @nNeeded )
          nLenBuf:=bin2u(nNeeded)
          if !( nRet > 0 ) .or. ( nLenBuf < nLenJob )
             // ? "GetJob error "+str( GetLastError() )+"..."
             return .f.
          endif
          oJob:Buffer( cBuf )
          IF alltrim(oJob:pDocument) == cDocu
             //? cDocu + "Posizione:"+ str( oJob:Position )
             IF  oJob:Position  >  0
                 lReturn := .f.
             ENDIF
          ENDIF
       endif
   NEXT
   
return lReturn

 


Maurizio
www.nipeservice.com
User avatar
Maurizio
 
Posts: 824
Joined: Mon Oct 10, 2005 1:29 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 56 guests