Hi,
How to get a list of printers connected to a computer ?
// http://fivewin.com.br/index.php?/topic/ ... etprintdc/
#include "FiveWin.ch"
#include "Objects.ch"
#define RGB_BLACK RGB( 0, 0, 0 )
#define RGB_RED RGB( 255, 0, 0 )
#define RGB_GREEN RGB( 0,255, 0 )
#define RGB_BLUE RGB( 0, 0,255 )
#define RGB_CYAN RGB( 0,255,255 )
#define RGB_YELLOW RGB( 255,255, 0 )
#define RGB_MAGENTA RGB( 255, 0,255 )
#define RGB_WHITE RGB( 255,255,255 )
#define FW_DONTCARE 0
#define FW_THIN 100
#define FW_EXTRALIGHT 200
#define FW_LIGHT 300
#define FW_NORMAL 400
#define FW_MEDIUM 500
#define FW_SEMIBOLD 600
#define FW_BOLD 700
#define FW_EXTRABOLD 800
#define FW_HEAVY 900
#define DMPAPER_A4 9
FUNCTION Main()
LOCAL oPrn, oPrint, oFnt, cPrinter := ""
LOCAL oDlg, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1
// GetPrinters() and GetDefaultPrinter() do not work in Harbour
#ifdef __HARBOUR__
aPrn := aGetPrinters ()
cDef := DefaultPrinter()
#else // Harbour
aPrn := GetPrinters ()
cDef := GetDefaultPrinter()
#endif
IF Empty ( aPrn )
MsgAlert ( "No Printers found" )
RETURN NIL
ENDIF
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, 20 BUTTON "&Print (FW)" OF oDlg ACTION TestCopias ( aPrn[i] )
@ 2, 20 BUTTON "&Print (xH)" OF oDlg ACTION Test2 ( aPrn[i] )
@ 3, 20 BUTTON "&End " OF oDlg ACTION( oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
RETURN NIL
FUNCTION TestCopias( cPrn ) // Imprimir varias copias
LOCAL nI, nCopias := 2
// SetCopies
FOR nI := 1 TO nCopias
TestPrint( cPrn )
NEXT
RETURN NIL
FUNCTION TestPrint( cPrn )
LOCAL oFnt, oPrint
LOCAL cText := "Este é um texto de teste para impressão"
PRINT oPrint NAME "Formulario" TO ( cPrn )
DEFINE FONT oFnt NAME "ARIAL" SIZE 0, - 14 OF oPrint
// oPrint:SetCopies ( 2 ) // No funciona
oPrint:SetLandscape()
// oPrint:Setup () // check the settings
PAGE
oPrint:CmSay ( 1, 1, cText, oFnt )
ENDPAGE
ENDPRINT
oFnt:End()
RETURN NIL
FUNCTION Test2 ( cPrn )
LOCAL oPrinter
LOCAL aFonts, cFont, nFont
oPrinter := Win32Prn():new( cPrn ) // Create printer object and configure print job
oPrinter:landscape := .F.
oPrinter:formType := DMPAPER_A4
oPrinter:copies := 2 // <--- 2 copies !!
IF ! oPrinter:create() // Create device context
Alert( "Cannot create device context" )
QUIT
ENDIF
IF ! oPrinter:startDoc( "xHarbour test page" ) // Create print job
Alert( "Cannot create document" )
QUIT
ENDIF
oPrinter:textOut( "Text in default font" ) // Text in fixed font
oPrinter:bold( FW_EXTRABOLD )
oPrinter:textOut( oPrinter:fontName )
oPrinter:bold( FW_NORMAL )
oPrinter:newLine()
aFonts := oPrinter:getFonts()
nFont := AScan( aFonts, ;
{|a| "ARIAL" $ Upper( a[1] ) } )
cFont := aFonts[nFont,1]
oPrinter:setFont( cFont ) // Text in proportional font
oPrinter:textOut( "Text in Arial font" )
oPrinter:bold( FW_EXTRABOLD )
oPrinter:textOut( oPrinter:fontName )
oPrinter:bold( FW_NORMAL )
oPrinter:newLine()
oPrinter:setColor( RGB_YELLOW, RGB_BLUE ) // Colored text
oPrinter:textOut( "Yellow on Blue" )
oPrinter:newLine()
oPrinter:setPen( PS_DASH, 5, RGB_GREEN ) // Draw colored line across page
oPrinter:line( oPrinter:posX, ;
oPrinter:posY, ;
oPrinter:rightMargin, ;
oPrinter:posY )
oPrinter:endDoc() // Send output to printer
oPrinter:destroy() // Release GDI device context
RETURN NIL
FUNCTION DefaultPrinter()
LOCAL nPrn, nRet, sGetDefaultPrinter
nRet := PrinterSetUp()
nPrn := PrnGetName()
IF( nRet # 0 )
SetDefaultPrinter( PRNGETNAME() )
sGetDefaultPrinter := GetDefaultPrinter()
// ? PrnStatus( sGetDefaultPrinter )
IF PrnStatus( sGetDefaultPrinter ) = 4096
// Verifica se SPOOLER esta desligado e tenta liga-lo
MsgRun( sGetDefaultPrinter + ": " + isprint( GetDefaultPrinter() ) + ;
" ou Spooler Desligado.", "Status da Impressora", ;
{|| WinExec( "NET START SPOOLER", 7 ) } )
ENDIF
//? GetPrinter()
ELSE
MsgAlert ( "No Printers found" )
RETURN( .F. )
ENDIF
RETURN( sGetDefaultPrinter )
// FIM
FUNCTION ADEVNAMES()
LOCAL cDevName := STRTRAN( GETPROFSTRING( "Devices" ), CHR( 0 ), CRLF )
LOCAL aDevNames := { "" }
LOCAL i
FOR i = 1 TO MLCOUNT( cDevName )
AADD( aDevNames, RTRIM( MEMOLINE( cDevName, , i ) ) )
NEXT
RETURN ASORT( aDevNames )
#Include "FiveWin.ch"
FUNCTION Main()
LOCAL cPrint
cPrint := ADEVNAMES()
xBrowse( cPrint )
RETURN NIL
FUNCTION ADEVNAMES()
LOCAL cDevName := STRTRAN( GETPROFSTRING( "Devices" ), CHR( 0 ), CRLF )
LOCAL aDevNames := { "" }
LOCAL i
FOR i = 1 TO MLCOUNT( cDevName )
AADD( aDevNames, RTRIM( MEMOLINE( cDevName, , i ) ) )
NEXT
RETURN ASORT( aDevNames )
// FIN / END
Natter wrote:Hi,
How to get a list of printers connected to a computer ?
aPrinters := aGetPrinters() // FWH builtin function
XBROWSER aPrinters
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 109 guests