Printers

Printers

Postby Anderson.OL » Fri May 29, 2009 5:09 pm

How to get the default printer on the computer?

How to get the printer port standard?

If the default is mapped, how to get the path?
Example: \\computer\printer
FiveWin 9.03 + xHarbour !!
User avatar
Anderson.OL
 
Posts: 92
Joined: Thu Feb 15, 2007 11:37 am
Location: Itaocara - RJ - Brasil

Re: Printers

Postby StefanHaupt » Tue Jun 02, 2009 7:27 am

Anderson,

with xharbour you can use GetPrinters(lPorts) to get an array of all available printers and GetDefaultPrinter () to get the default printer.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Printers

Postby Otto » Tue Jun 02, 2009 8:36 am

Hello Stefan,

thank you for your information.
Do you know if you could also get the status of the printer?

Thanks in advance
Otto

Code: Select all  Expand view
 
For nX := 1 To Len(aPrinters)
   ?  "Druckername:   " + aPrinters[nX][1],;
  "Drucker-Port:  " + aPrinters[nX][2],;
 "Lokal/Netz: " + aPrinters[nX][3] ,;
            "Modell: " + aPrinters[nX][4],;
"Freigabename: " + aPrinters[nX][5]  
   Next
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Printers

Postby ukoenig » Tue Jun 02, 2009 10:57 am

Hello Otto,

I think it is possible, to add PrnStatus() inside the For Next.

Code: Select all  Expand view

#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

For nX := 1 To Len(aPrinters)
   ?  "Druckername:   " + aPrinters[nX][1],;
      "Drucker-Port:  " + aPrinters[nX][2],;  
      "Lokal/Netz: " + aPrinters[nX][3] ,;
      "Modell: " + aPrinters[nX][4],;
      "Freigabename: " + aPrinters[nX][5], ;  
      "Status : " + STR ( PrnStatus( aPrinters[nX][2] ) )  
Next

// Syntax : PrnStatus( "LPT1:" )
// I don't know, if aPrinters[nX][2]  Returns a string : "LPT1" or "LPT1:" ( not tested )
// Maybe to change in : aPrinters[nX][2] + ":"  

return nil
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Printers

Postby StefanHaupt » Tue Jun 02, 2009 11:22 am

Hello Ootto,

there is a function PrintStat (nLpt) in xHarbour, which should return the status. But it seems to exist only for compatibility reasons.

Better you use Uwe´s suggestion, this is a fivewin function.

Uwe,

according to the docu this function needs the printer name as parameter, in your sample you use the port. What is correct now ?
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Printers

Postby ukoenig » Tue Jun 02, 2009 12:09 pm

Hello Stefan,

The sample prnstat.prg shows :

Function Main()
local nStatus := PrnStatus( "LPT1:" )
MsgInfo( nStatus )
return nil

I had a look at printdc.c ( subdirectory /winapi )
PRNSTATUS( PARAMS ) // cPrinter or cPrinterServer --> nStatus

I have to test on a different computer.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Printers

Postby Otto » Tue Jun 02, 2009 2:38 pm

Hello Stefan, hello Uwe,

thank you for your help.
With printername parameter 1 I get the correct results.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Printers

Postby StefanHaupt » Wed Jun 03, 2009 8:13 am

Hi Uwe,

the portname seems to be the correct parameter.

I enhanced the sample to get all printers with their status. But for all network printers I get the status 4096 (not available).

Could you please check, if you get other results

Code: Select all  Expand view
#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 nStatus := PrnStatus( "LPT1:" )

   MsgInfo( nStatus)
   
   CheckAll ()

return nil


FUNCTION CheckAll ()

LOCAL nx, aPrinters, cPrn

aPrinters := GetPrinters(.t.)

For nX := 1 To Len(aPrinters)
   cPrn := "Druckername:   " + aPrinters[nX][1] +CRLF+;
           "Drucker-Port:  " + aPrinters[nX][2] +CRLF+;  
           "Lokal/Netz:    " + aPrinters[nX][3] +CRLF+;
           "Modell:        " + aPrinters[nX][4] +CRLF+;
           "Freigabename:  " + aPrinters[nX][5] +CRLF+ ;  
           "Status :       " + STR ( PrnStatus( aPrinters[nX][2]+":" ) )  
  MsgInfo (cPrn)
Next

RETURN (nil)
Last edited by StefanHaupt on Thu Jun 04, 2009 6:49 am, edited 1 time in total.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Printers

Postby frose » Wed Jun 03, 2009 8:41 am

Hello Stefan,

getting always 4096 for all printers, network AND local!
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Printers

Postby Otto » Wed Jun 03, 2009 10:33 am

Hello Frank,

I have the same results as you. If I try – I have a VISTA system – with the printername as parameter I get the correct results.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: Printers

Postby frose » Wed Jun 03, 2009 10:59 am

Hello Stefan, hello Otto,

even with 'aPrinters[nX][1]' the return value is always 4096!
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: Printers

Postby StefanHaupt » Thu Jun 04, 2009 7:23 am

Hi all,

the correct parameter for PrnStatus () is the printer name, not the port !

If specify a real printer name, the function returns 0 (PRINTER_STATUS_OK). But it does not return the real status of the printer. Windows can not get the correct status of a printer, if no jobs are in it´s queue.

This is what I found in the web about this issue:

To further complicate things, it turns out that Windows only queries the printer for its status when there's a print job for the it, which means that if you are not printing you probably can't find out the real printer status. If you are not concerned about this, you'll be glad to know that you can obtain the same information on WinNT and Win9x by querying the print job instead of the printer for the status, via the GetJob() api.


I think, windows should do the job, it´s not DOS anymore. Windows tells us, if there are errors while printing. In our applications it is enough to check if a printer exists or not.


This is a modified version of PrnStatus, which return a correct error code if the printer does not exist.

Code: Select all  Expand view
#define ERROR_INVALID_PRINTER_NAME  1801

FUNCTION CheckStatus (cPrinter)

LOCAL nStatus := PrinterStatus (cPrinter)
LOCAL cStatus := IIF (nStatus = ERROR_INVALID_PRINTER_NAME, ;
                                "Invalid Printer name", STR (nStatus) )

RETURN (cStatus)



#pragma BEGINDUMP


#include <Windows.h>
#include <HbApi.h>


HB_FUNC ( PRINTERSTATUS ) // cPrinter or cPrinterServer --> nStatus
{
  HANDLE hPrinter = NULL;
  DWORD cBytesNeeded = 0, cBytesUsed = 0, pstatus = -1;
  PRINTER_INFO_2 * pPrinterInfo = NULL;

   if( OpenPrinter( hb_parc( 1 ), &hPrinter, NULL ) )
   {
      GetPrinter( hPrinter, 2, NULL, 0, &cBytesNeeded );
      pPrinterInfo = ( PRINTER_INFO_2 * ) hb_xgrab( cBytesNeeded );
      //cBytesUsed = cBytesNeeded;
      GetPrinter( hPrinter, 2, ( unsigned char * ) pPrinterInfo, cBytesNeeded, &cBytesUsed );
      pstatus = (pPrinterInfo->Status) ;
      hb_retnl( pPrinterInfo->Status ) ;
      hb_xfree( pPrinterInfo );
      ClosePrinter( hPrinter );

   }
   else
      hb_retnl( GetLastError() );  // return error code if Openprinter() fails
}

 
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests