1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
* Windows API
lcPrintername = GETPRINTER()
IF NOT EMPTY(lcPrintername)
IF ClearPrintQueue(lcPrintername)
? "The print queue has been successfully cleared"
ELSE
? "Error"
ENDIF
ENDIF
RETURN
*--------------------------------------------------------------------
FUNCTION ClearPrintQueue(tcPrinterName)
LOCAL lcErrorTxt, lnHandle, lcBuffer, lcPrDef, llOK
DECLARE Long GetLastError IN kernel32.dll
#DEFINE PRINTER_CONTROL_PURGE 3
#DEFINE PRINTER_ACCESS_ADMINISTER 4
lcCrLf = CHR(13) + CHR(10)
lcTab = CHR(9)
lnHandle = 0
* Open a Pinter with proper access rights
lcPrDef = REPLICATE(CHR(0),8) + CHR(PRINTER_ACCESS_ADMINISTER) + REPLICATE(CHR(0),3)
llOK = OpenPrinter( tcPrinterName, @lnHandle, lcPrDef) <> 0
IF NOT llOK THEN
lcErrorTxt = WinApiErrMsg(GetLastError())
? "Cannot Open Printer " + tcPrinterName + lcCrLf + lcTab + lcErrorTxt
RETURN llOK
ENDIF
* Clear Print Queueu
llOK = SetPrinter( lnHandle, 0, 0, PRINTER_CONTROL_PURGE) <> 0
IF NOT llOK THEN
lcErrorTxt = WinApiErrMsg(GetLastError())
*= ClosePrinter( lnHandle )
? "Error Clearing Print Queue for " + tcPrinterName + lcCrLf + lcTab + lcErrorTxt
*RETURN llOK
ENDIF
= ClosePrinter( lnHandle )
RETURN llOK
*---------------------------------------------------------------
FUNCTION OpenPrinter(tcPrinterName, thPrinter, tcDefault)
DECLARE Long OpenPrinter IN WinSpool.Drv String pPrinterName, Long@ phPrinter, String pDefault
RETURN OpenPrinter(tcPrinterName, @thPrinter, tcDefault)
FUNCTION ClosePrinter (thPrinter)
DECLARE Long ClosePrinter IN WinSpool.Drv Long hPrinter
RETURN ClosePrinter(thPrinter)
FUNCTION SetPrinter(thPrinter, tnLevel, tnPrinter, tnCommand)
DECLARE Long SetPrinter IN WinSpool.Drv Long hPrinter, Long Level, Long pPrinter, Long Command
RETURN SetPrinter(thPrinter, tnLevel, tnPrinter, tnCommand)
|
Comments