Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Clear the Print Queue
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00997996
Message ID:
00998156
Vues:
19
Thanks, is 'tcPrinterName' the name as it appears
in the Printers dialog?



>>Is there any way to programmatically clear all
>>print jobs from the queue?
>
>Sure
FUNCTION ClearPrintQueue(tcPrinterName)
>LOCAL lnOK, lcErrorTxt, lnHandle, lcBuffer, lcPrDef
>
>DECLARE Long GetLastError IN kernel32.dll
>DECLARE Long FormatMessage IN kernel32.dll ;
>	Long dwFlags, String @lpSource, Long dwMessageId, ;
>	Long dwLanguageId, String @lpBuffer, Long nSize, Long Arguments
>
>DECLARE Long OpenPrinter IN WinSpool.Drv ;
>	String pPrinterName, Long@ phPrinter, String pDefault
>DECLARE Long ClosePrinter IN WinSpool.Drv  ;
>	Long hPrinter
>DECLARE Long SetPrinter IN WinSpool.Drv;
>    Long hPrinter, Long Level, ;
>    Long pPrinter, Long Command
>
>#DEFINE PRINTER_CONTROL_PURGE 3
>#DEFINE PRINTER_ACCESS_ADMINISTER 4
>
>* Open a Pinter with proper access rights
>lcPrDef = REPLICATE(CHR(0),8) + CHR(PRINTER_ACCESS_ADMINISTER) + REPLICATE(CHR(0),3)
>lnOK = OpenPrinter( tcPrinterName, @lnHandle, lcPrDef)
>IF lnOK = 0 THEN
>	lcErrorTxt = ApiError()	
>	WAIT WINDOW NOWAIT "Cannot Open Printer " + tcPrinterName + CHR(13) + lcErrorTxt
>	RETURN -1
>ENDIF	
>* Clear Print Queueu
>lnOK = SetPrinter( lnHandle, 0, 0, PRINTER_CONTROL_PURGE)
>IF lnOK = 0 THEN
>	lcErrorTxt = ApiError()	
>	= ClosePrinter( lnHandle )
>	WAIT WINDOW NOWAIT "Error Clearing Print Queue" + CHR(13) + lcErrorTxt
>	RETURN -2
>ENDIF	
>= ClosePrinter( lnHandle )
>* lnOk > 0 - success
>RETURN lnOk
>*-------------------------------------------------
>
>FUNCTION ApiError
>Local lcErrBuffer, lcErrorMess, liNewErr, lnErrorCode
>lcErrBuffer = REPL(CHR(0),1000)
>lnErrorCode = GetLastError()
>liNewErr = FormatMessage(0x1000,.NULL., lnErrorCode, 0, @lcErrBuffer,500,0)
>lcErrorMess = Transform(lnErrorCode) + "    " + LEFT(lcErrBuffer, AT(CHR(0),lcErrBuffer)- 1 )
>RETURN lcErrorMess
>
Tested under WinXP only.
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform