代码在这里啦 。
代码语言:javascript复制* the offset to the "Jobs number" member
* in the PRINTER_INFO_2 structure
#DEFINE CJOBS_OFFSET 77
DO declare
LOCAL hPrinter, cPrinter, cPrnInfo, nBufsize, nResult
cPrinter = GetPrnName()
? "Default printer: ", cPrinter
hPrinter = 0
IF OpenPrinter(cPrinter, @hPrinter, 0) = 0
? "Unable to obtain the handle for this printer."
RETURN
ENDIF
nBufsize = 4096 && allocate sufficient buffer
cPrnInfo = REPLICATE(Chr(0), nBufsize)
nResult = GetPrinterA(hPrinter, 2, @cPrnInfo,;
nBufsize, @nBufsize)
IF nResult = 0
? "Error code:", GetLastError()
ELSE
? "Number of print jobs queued:",;
buf2dword(SUBSTR(cPrnInfo, CJOBS_OFFSET,4))
ENDIF
= ClosePrinter(hPrinter)
* end of main
FUNCTION GetPrnName
* returns default printer name from Windows Registry
LOCAL cBuffer, cPrinter, cDriver, cPort
cBuffer = REPLICATE(CHR(0), 120)
= GetProfileString("Windows", "Device", ",,,",;
@cBuffer, Len(cBuffer))
cBuffer = STRTRAN(cBuffer, Chr(0), "")
RETURN SUBSTR(cBuffer, 1, AT(",", cBuffer, 1)-1)
PROCEDURE declare
DECLARE INTEGER OpenPrinter IN winspool.drv;
STRING pPrinterName, INTEGER @phPrinter, INTEGER pDefault
DECLARE INTEGER ClosePrinter IN winspool.drv INTEGER hPrinter
DECLARE INTEGER GetProfileString IN kernel32;
STRING lpApp, STRING lpKey, STRING lpDefault,;
STRING @lpReturnedString, INTEGER nSize
DECLARE INTEGER GetPrinter IN winspool.drv AS GetPrinterA;
INTEGER hPrinter, INTEGER Lvl, STRING @pPrinter,;
INTEGER cbBuf, INTEGER @pcbNeeded
DECLARE INTEGER GetLastError IN kernel32
FUNCTION buf2dword(cBuffer)
RETURN Asc(SUBSTR(cBuffer, 1,1)) ;
BitLShift(Asc(SUBSTR(cBuffer, 2,1)), 8) ;
BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) ;
BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)