ComDlgErr() or IsPrinter()

ComDlgErr() or IsPrinter()

Postby ORibeiro » 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
User avatar
ORibeiro
 
Posts: 187
Joined: Mon Oct 20, 2008 6:33 pm
Location: Itu, Sao Paulo, Brazil

Re: ComDlgErr() or IsPrinter()

Postby ORibeiro » 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
User avatar
ORibeiro
 
Posts: 187
Joined: Mon Oct 20, 2008 6:33 pm
Location: Itu, Sao Paulo, Brazil

Re: ComDlgErr() or IsPrinter()

Postby James Bott » Mon Mar 10, 2014 3: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: Select all  Expand view
//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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: ComDlgErr() or IsPrinter()

Postby ORibeiro » Mon Mar 10, 2014 4:25 pm

Thanks James.
Oscar Ribeiro
OASyS Informática
Fwh18.02 + xHarbour 1.2.3 + Bcc72
User avatar
ORibeiro
 
Posts: 187
Joined: Mon Oct 20, 2008 6:33 pm
Location: Itu, Sao Paulo, Brazil

Re: ComDlgErr() or IsPrinter()

Postby James Bott » Mon Mar 10, 2014 4: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: ComDlgErr() or IsPrinter()

Postby ORibeiro » Mon Mar 10, 2014 4: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
User avatar
ORibeiro
 
Posts: 187
Joined: Mon Oct 20, 2008 6:33 pm
Location: Itu, Sao Paulo, Brazil

Re: ComDlgErr() or IsPrinter()

Postby James Bott » Mon Mar 10, 2014 9:15 pm

Code: Select all  Expand view
//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
 
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: ComDlgErr() or IsPrinter()

Postby ORibeiro » 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
User avatar
ORibeiro
 
Posts: 187
Joined: Mon Oct 20, 2008 6:33 pm
Location: Itu, Sao Paulo, Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 48 guests