To All
Is there a way to test if the Default USB printer is turned on, Ready and plugged in ?
Thanks
Rick Lipkin
cPorta := PrnGetPort()
cPrinter := PrinterPortToName( cPorta )
if empty(cPrinter)
cPrinter := PrinterPortToName( "USB002" )
if empty(cPrinter)
cPrinter := PrinterPortToName( "USB001" )
if empty(cPrinter)
MsgStop("No printers Installed")
return nil
endif
endif
endif
#include "Fivewin.ch"
FUNCTION Main()
LOCAL oPrn, oPrint,oFnt, cPrinter := ""
LOCAL oDlg, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1
aPrn := GetPrinters()
IF Empty (aPrn) // Empty( oPrn:hDC )
MsgAlert ("No Printers found" )
RETURN NIL
ENDIF
cDef := GetDefaultPrinter()
DEFINE DIALOG oDlg FROM 2, 2 TO 21, 50 TITLE "Available Printers"
@ 1, 2 LISTBOX oBrw FIELDS aPrn[ i ] ;
HEADERS "Printer Array" ;
FIELDSIZES 200 ;
OF oDlg ;
SIZE 100, 100
oBrw:bGoTop = { || i := 1 }
oBrw:bGoBottom = { || i := Eval( oBrw:bLogicLen )}
oBrw:bSkip = { | nWant, nOld | nOld := i, i += nWant, ;
i := Max( 1, Min( i, Eval( oBrw:bLogicLen ) ) ),;
i - nOld }
oBrw:bLogicLen = { || Len( aPrn ) }
oBrw:cAlias = "Array" // Just put something
@ 7.8,2 SAY "DEFAULT PRINTER: " + cDef
@ 1,22 BUTTON "&Print" OF oDlg ACTION Testprint (aPrn[i])
@ 2,22 BUTTON "&End " OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
//--------------------------------------------------------------
FUNCTION TestPrint(cPrn)
LOCAL oFnt, oPrint
LOCAL cText := "Printer Test - Default Printer"
IF MsgYesNo ( "Print to " + cPrn)
PRINT oPrint NAME "Formular" TO (cPrn)
DEFINE FONT oFnt NAME "ARIAL" SIZE 0,12 OF oPrint
oPrint:SetCopies (2)
oPrint:SetLandscape()
oPrint:Setup () // check the settings
PAGE
oPrint:CmSay (1,1, cText,oFnt)
ENDPAGE
ENDPRINT
oFnt:End()
ENDIF
RETURN NIL
PRINTER oPRINT FROM USER ;
PREVIEW MODAL ;
NAME "Gross Sales Report for "+xLOGIN
IF EMPTY( oPRINT:hDC )
MsgStop ( "Printer not Ready !" )
CLOSE DATABASES
oDlg:END()
RETURN(NIL)
ENDIF
PrnStatus()
Retrieves the status of a printer.
Syntax:
PrnStatus( <cPrinter> ) --> nStatus
Parameters:
<cPrinter> The printer of which the status is to be retrieved.
Returns:
<nStatus> One of the following values:
#define PRINTER_STATUS_OK 0
#define PRINTER_STATUS_PAUSED 1
#define PRINTER_STATUS_ERROR 2
#define PRINTER_STATUS_PENDING_DELETION 4
#define PRINTER_STATUS_PAPER_JAM 8
#define PRINTER_STATUS_PAPER_OUT 16
#define PRINTER_STATUS_MANUAL_FEED 32
#define PRINTER_STATUS_PAPER_PROBLEM 64
#define PRINTER_STATUS_OFFLINE 128
#define PRINTER_STATUS_IO_ACTIVE 256
#define PRINTER_STATUS_BUSY 512
#define PRINTER_STATUS_PRINTING 1024
#define PRINTER_STATUS_OUTPUT_BIN_FULL 2048
#define PRINTER_STATUS_NOT_AVAILABLE 4096
#define PRINTER_STATUS_WAITING 8192
#define PRINTER_STATUS_PROCESSING 16384
#define PRINTER_STATUS_INITIALIZING 32768
#define PRINTER_STATUS_WARMING_UP 65536
#define PRINTER_STATUS_TONER_LOW 131072
#define PRINTER_STATUS_NO_TONER 262144
#define PRINTER_STATUS_PAGE_PUNT 524288
#define PRINTER_STATUS_USER_INTERVENTION 1048576
#define PRINTER_STATUS_OUT_OF_MEMORY 2097152
#define PRINTER_STATUS_DOOR_OPEN 4194304
#define PRINTER_STATUS_SERVER_UNKNOWN 8388608
#define PRINTER_STATUS_POWER_SAVE 16777216
#include "Fivewin.ch"
#define PRINTER_STATUS_OK 0
#define PRINTER_STATUS_PAUSED 1
#define PRINTER_STATUS_ERROR 2
#define PRINTER_STATUS_PENDING_DELETION 4
#define PRINTER_STATUS_PAPER_JAM 8
#define PRINTER_STATUS_PAPER_OUT 16
#define PRINTER_STATUS_MANUAL_FEED 32
#define PRINTER_STATUS_PAPER_PROBLEM 64
#define PRINTER_STATUS_OFFLINE 128
#define PRINTER_STATUS_IO_ACTIVE 256
#define PRINTER_STATUS_BUSY 512
#define PRINTER_STATUS_PRINTING 1024
#define PRINTER_STATUS_OUTPUT_BIN_FULL 2048
#define PRINTER_STATUS_NOT_AVAILABLE 4096
#define PRINTER_STATUS_WAITING 8192
#define PRINTER_STATUS_PROCESSING 16384
#define PRINTER_STATUS_INITIALIZING 32768
#define PRINTER_STATUS_WARMING_UP 65536
#define PRINTER_STATUS_TONER_LOW 131072
#define PRINTER_STATUS_NO_TONER 262144
#define PRINTER_STATUS_PAGE_PUNT 524288
#define PRINTER_STATUS_USER_INTERVENTION 1048576
#define PRINTER_STATUS_OUT_OF_MEMORY 2097152
#define PRINTER_STATUS_DOOR_OPEN 4194304
#define PRINTER_STATUS_SERVER_UNKNOWN 8388608
#define PRINTER_STATUS_POWER_SAVE 16777216
//------------------------
FUNCTION Main()
Local cPort,aPrn,nStatus,aPrinter
cPort := PrnGetPort()
Msginfo( cPort )
cPrinter := GetDefaultPrinter()
msginfo( "cPrinter" )
msginfo( cPrinter )
nStatus := PrnStatus( cPrinter )
msginfo( nStatus )
nStatus := PrnStatus( cPort )
msginfo( nStatus)
RETURN
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Natter and 66 guests