FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ComDlgErr() or IsPrinter()
Posts: 187
Joined: Mon Oct 20, 2008 06:33 PM
ComDlgErr() or IsPrinter()
Posted: Fri Mar 07, 2014 11:39 AM
When there is no printer installed in MS-Windows, the PRINTER and REPORT commands show GPF errors when the print is sent without preview.

I noticed that the IsPrinter() causes problems and I chose to use the ComDlgErr() to detect if there is printer installed. I'm on the right track?

Thanks,
Oscar Ribeiro

OASyS Informática

Fwh18.02 + xHarbour 1.2.3 + Bcc72
Posts: 187
Joined: Mon Oct 20, 2008 06:33 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 10:50 AM
The ComDlgErr() printer.prg class works correctly to detect if there is printer installed in Windows?

I did numerous tests and noticed that in a few cases it fails indicating that there is printer, in this cases error occurs and in the PRNGETNAME() command.
Oscar Ribeiro

OASyS Informática

Fwh18.02 + xHarbour 1.2.3 + Bcc72
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 03:31 PM
A printer has to be both installed AND available.

I don't have xHarbour's source for the isPrinter() function, but here is an old one I have been using. I don't have a computer without an installed printer so I am not sure how it works in that case.

Code (fw): Select all Collapse
//Returns .t. if current printer is available
Function isPrinter()
   local oPrn,lSuccess:=.t.
   PRINTER oPrn NAME "Report..." PREVIEW
   IF oPrn:hDC == 0
      lSuccess:=.f.
   END IF
return lSuccess


Give it a try.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 187
Joined: Mon Oct 20, 2008 06:33 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 04:25 PM

Thanks James.

Oscar Ribeiro

OASyS Informática

Fwh18.02 + xHarbour 1.2.3 + Bcc72
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 04:35 PM

I also have a function that returns an array of installed printers which you could use to check to see if there are no installed printers. If you need it, let me know.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 187
Joined: Mon Oct 20, 2008 06:33 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 04:49 PM

Interesting! send me this function, please.

Thanks a lot.

oscar@oasysitu.com

Oscar Ribeiro

OASyS Informática

Fwh18.02 + xHarbour 1.2.3 + Bcc72
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: ComDlgErr() or IsPrinter()
Posted: Mon Mar 10, 2014 09:15 PM
Code (fw): Select all Collapse
//Returns an array of all available printers.
FUNCTION GetPrinters()

   local aPrn,  cText

   cText := StrTran(GetProfString("Devices"),Chr(0), chr(13)+chr(10))
   aPrn  := Array(Mlcount(cText, 250))
   Aeval(aPrn, {|v,e| aPrn[e] := Trim(Memoline(cText, 250, e)) } )

Return aPrn
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 187
Joined: Mon Oct 20, 2008 06:33 PM
Re: ComDlgErr() or IsPrinter()
Posted: Tue Mar 11, 2014 10:07 AM

Very good James,
Thanks a lot.

Oscar Ribeiro

OASyS Informática

Fwh18.02 + xHarbour 1.2.3 + Bcc72

Continue the discussion