xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

GetPrinters()

Retrieves information about available printers.

Syntax

GetPrinters( [<lPortInfo>], [<lLocalPrinters>] ) --> aPrinterInfo

Arguments

<lPortInfo>
The default value for <lPortInfo> is .F. (false). If set to .T. (true), the function includes port information in the returned array.
<lLocalPrinters>
The default value for <lLocalPrinters> is .F. (false). If set to .T. (true), the function returns only information for local printers.

Return

The function returns a one- or two-dimensional array. If <lPortInfo> is .F. (false), a one-dimensional array is returned. Each element contains a character string with the name of an available printer. If <lPortInfo> is .T., each element of the returned array is an array of four elements, holding character strings with additional printer information:

Array elements for additional printer information
ElementDescription
1Printer name
2Port name
3Printer type (e.g. Local/Network)
4Printer driver

Description

The GetPrinters() function obtains information about printers that are currently available. If it is called without arguments, the function returns the names of all available printers. The list can be reduced to local printers only by specifying .T. (true) for <lLocalPrinters>. Additional information about port and printer driver can be retrieved when <lPortInfo> is set to .T. (true)

Info

See also:GetDefaultPrinter(), PrintFileRaw(), PrinterExists(), PrinterPortToName()
Category: Printer functions , xHarbour extensions
Source:rtl\tprinter.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example is a test program for Windows printing

   PROCEDURE Main
      LOCAL aPrinter, i
      CLS
      ?
      ? Set(_SET_DEVICE)

      aPrinter := GetPrinters()

      IF Empty( aPrinter )
         ? '----- No Printers installed'
         QUIT
      ENDIF

      SET PRINTER TO ( GetDefaultPrinter() )
      ? Set( _SET_PRINTER   )
      ? Set( _SET_PRINTFILE )
      SET CONSOLE OFF
      SET PRINTER ON
      ? 'Default Printer'
      ?
      ? GetDefaultPrinter()
      ?
      ? 'Printers available'
      ?'-------------------'
      FOR i:= 1 TO Len( aPrinter )
        ? aPrinter[i]
      NEXT i

      aPrinter:= GetPrinters( .T. )
      ?
      ? 'Printers and Ports'
      ? '-------------------'
      FOR i:= 1 TO Len( aPrinter )
         ? aPrinter[i,1],'on', aPrinter[i,2]
      NEXT

      EJECT
      SET PRINTER OFF
      SET CONSOLE ON
      SET PRINTER TO

      ? Set( _SET_PRINTER )
      ? Set( _SET_DEVICE  )
      WAIT
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe