Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Print Queue Monitor
Message
De
14/01/2005 13:35:00
 
 
À
14/01/2005 13:11:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 8
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
00977227
Message ID:
00977308
Vues:
18
Well, you are close. Try this and see if it helps:
CLEAR ALL
CLOSE ALL
CLEAR
**********************************************************************
* Declare the API functions
**********************************************************************
DECLARE INTEGER OpenPrinter IN WinSpool.Drv AS WS_OpenPrinter ;
  STRING pPrinterName, ;
  INTEGER @phPrinter, ;
  STRING pDefault
DECLARE INTEGER ClosePrinter IN WinSpool.Drv AS WS_ClosePrinter ;
  INTEGER hPrinter
DECLARE INTEGER EnumJobs IN WinSpool.Drv AS WS_EnumJobs ;
  INTEGER hPrinter, ;
  INTEGER FirstJob, ;
  INTEGER NoJobs, ;
  INTEGER LEVEL, ;
  STRING @pJob, ;
  INTEGER cbBuf, ;
  INTEGER @pcbNeeded, ;
  INTEGER @pcReturned,;
  DECLARE LONG GetJob IN WinSpool.Drv ;
  LONG hPrinter,;
  LONG nJobID,;
  LONG nLevel,;
  STRING @cJobInfo,;
  LONG nBufSize,;
  LONG @nBufNeeded
DECLARE INTEGER GetLastError IN WIN32API AS WS_GetLastError
DECLARE LONG FormatMessage IN kernel32.DLL ;
  LONG dwFlags, STRING @lpSource, LONG dwMessageId, ;
  LONG dwLanguageId, STRING @lpBuffer, LONG nSize, LONG Arguments
**********************************************************************
* Get List of Printers
**********************************************************************
nNoOfPrinters=APRINTERS(aPrinterList)
FOR N = 1 TO nNoOfPrinters
  **********************************************************************
  * Open the printer
  **********************************************************************
  lcPrinter=aPrinterList[n,1]
  lnHandle=0
  IF !EMPTY(lcPrinter)
    nRetVal=WS_OpenPrinter(@lcPrinter, @lnHandle, 0)
    IF nRetVal != 0
      * The printer was opened
    ELSE
      * The call failed call GetLastError() to retrieve the error number then exit program
      lcError=WS_GetLastError()
      ? lcError
      RETURN
    ENDIF
  ENDIF
  **********************************************************************
  * Get the number of jobs
  **********************************************************************
  lnNeeded = 0
  lnNumberOfJobs = 0
  * Get the size of the buffer in lnNeeded
  lnOK = WS_EnumJobs( lnHandle, 0, 127, 1, .Null., 0, @lnNeeded, @lnNumberOfJobs  )
  IF lnOK=0 THEN
    IF WS_GetLastError() <> 122 && The buffer too small error
      lcErrorTxt = ApiError()
      =WS_ClosePrinter( lnHandle)
      WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
      RETURN -2
    ENDIF
  ENDIF
  * Allocate the buffer
  lcBuffer = REPLICATE( CHR(0), lnNeeded)
  * Get the number of jobs
  lnOK = WS_EnumJobs( ;
    lnHandle, ;
    0, 127, 1,;
    @lcBuffer, ;
    @lnNeeded, ;
    @lnNeeded, ;
    @lnNumberOfJobs )
  IF lnOK = 0 THEN
    lcErrorTxt = ApiError()
    = WS_ClosePrinter( lnHandle )
    WAIT WINDOW NOWAIT "Error enumerating PrintJobs" + CHR(13) + lcErrorTxt
    RETURN -3
  ENDIF
  **********************************************************************
  * Close the printer
  **********************************************************************
  nClosePrinter=WS_ClosePrinter(lnHandle)
  **********************************************************************
  * Display the number of jobs in queue
  **********************************************************************
  ? lcPrinter+" has "+ALLTRIM(STR(lnNumberOfJobs))+" jobs in it's queue"
ENDFOR
CLEAR DLLS
RETURN

FUNCTION ApiError
  LOCAL lcErrBuffer, lcErrorMess, liNewErr, lnErrorCode
  lcErrBuffer = REPL(CHR(0),1000)
  lnErrorCode = WS_GetLastError()
  liNewErr = FormatMessage(0x1000,.NULL., lnErrorCode, 0, @lcErrBuffer,500,0)
  lcErrorMess = TRANSFORM(lnErrorCode) + "    " + LEFT(lcErrBuffer, AT(CHR(0),lcErrBuffer)- 1 )
  RETURN lcErrorMess
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform