//#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