FWH 13.12 printer SetCopies problem

User avatar
betoncu
Posts: 120
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

FWH 13.12 printer SetCopies problem

Post by betoncu »

Hello,
After I switch to FWH 13.12, I faced with a strange problem with the function oPrn:SetCopies(n).
If I use this function, My program always prints to de default printer.

Code: Select all

#INCLUDE "FiveWin.ch"
FUNCTION Main()
LOCAL oPrn, aPrinters:=aGetPrinters()

   PRINT oPrn TO aPrinters[5]
   
   oPrn:SetCopies(2)  // If I remove this line, everything is OK, It will print to aPrinters[5]
                      // otherwise it will always print to default printer (aPrinters[3] in my case)
   PAGE
      oPrn:Say( 1, 1, "Hello" )
   ENDPAGE
   
   ENDPRINT
RETURN NIL
Regards,
Birol Betoncu
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by Antonio Linares »

Birol,

Instead of calling oPrn:SetCopies( 2 ) please do PrnSetCopies( 2 ) and let me know your results, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
betoncu
Posts: 120
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Re: FWH 13.12 printer SetCopies problem

Post by betoncu »

Antonio,
Thanks for your help. It is working now. :D
Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by James Bott »

Antonio,

The problem seems to be in the Rebuild() method of TPrinter. It is calling the getPrnDefault():

Code: Select all

      ::hDC := GetPrintDefault( GetActiveWindow() )
Which is changing the current printer to the default printer. Since the Rebuild() method is called from setCopies() and a lot of other methods, it seems this needs to be fixed.

James
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Re: FWH 13.12 printer SetCopies problem

Post by Greg Gammon »

I have a different question relating to number of copies to print. I would like my user to be able to simply select on the printer setup dialog the number of copies to print.

printersetup() dialog does not have a "Copies to Print" option...is there a fix for this?
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by James Bott »

Greg,
printersetup() dialog does not have a "Copies to Print" option...is there a fix for this?
Why not just design your own printer-setup dialog with a number of copies field? Then you can set it by calling oPrn:setCopies().

Regards,
James
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Re: FWH 13.12 printer SetCopies problem

Post by Greg Gammon »

Thanks James....was just hoping there was something simple I wasn't aware of. I might do that...someday...but have 100 other more important things to implement first :x
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: FWH 13.12 printer SetCopies problem

Post by StefanHaupt »

James,
Why not just design your own printer-setup dialog with a number of copies field? Then you can set it by calling oPrn:setCopies().
oPrn:SetCopies() is calling the method Rebuild(), which always sets the default printer. Maybe it´s the best solution is to remove the call of Rebuild() from the methods :SetCoppies(), :SetLandscape(), :SetPortrait(), :SetSize(), :SetPage() and :SetBin(). This avoids setting the device to the default printer.

I see no sense to change the setting of the choosen device first and then reset that device to another.
kind regards
Stefan
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: FWH 13.12 printer SetCopies problem

Post by StefanHaupt »

Inside the method Rebuild() I don´t undersatnd that line

Code: Select all

if ::hDC != 0  // <--------
      DeleteDC( ::hDC )
      ::hDC := GetPrintDefault( GetActiveWindow() )
      ::lStarted   := .F.
      ::lModified  := .T.
   endif
 
That means the default printer is only set, if a device is already active, why ?

I think, it´s more logical only to set the default printer if no device is selected

Code: Select all

if ::hDC = 0  // no device active, set the default printer
      //DeleteDC( ::hDC )
      ::hDC := GetPrintDefault( GetActiveWindow() )
      ::lStarted   := .F.
      ::lModified  := .T.
   endif
 
Please Antonio, could you check this change.

If I´m wrong, please could you explain that code snippet to me, thanks.
kind regards
Stefan
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by Antonio Linares »

Stefan,

Yes, you are right, I agree with you that this seems to be the right fix (Method Rebuild()):

Code: Select all

   if ::hDC == 0
      ::hDC       = GetPrintDefault( GetActiveWindow() )
      ::lStarted  = .F.
      ::lModified = .T.
   endif
I appreciate feedback to be sure that this way we don't break existing code, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: FWH 13.12 printer SetCopies problem

Post by StefanHaupt »

Antonio,

I made this small test-function

Code: Select all

#include "Fivewin.ch"

Procedure Main()

LOCAL oPrn, oPrint,oFnt, cPrinter := ""
LOCAL oWnd, oBrw
LOCAL aPrn := {}
LOCAL cDef, i := 1

aPrn := GetPrinters ()

IF Empty (aPrn)
  MsgAlert ("No Printers found" )//+ CRLF +;
  RETURN
ENDIF
cDef := GetDefaultPrinter()

DEFINE DIALOG oWnd FROM 2, 2 TO 21, 50 TITLE "Available Printers"

@ 1, 2 LISTBOX oBrw FIELDS aPrn[ i ] ;
      HEADERS "Printer Array" ;
      FIELDSIZES 200 ;
      OF oWnd ;
      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,22 BUTTON "&Print" OF oWnd ACTION Testprint (aPrn[i])
   @ 2,22 BUTTON "&End  " OF oWnd ACTION oWnd:End()

ACTIVATE DIALOG oWnd CENTERED

RETURN
//--------------------------------------------------------------
PROCEDURE TestPrint(cPrn)

LOCAL oFnt, oPrint
LOCAL cText := "Dies ist ein Testtext zum Drucken"

IF MsgYesNo ("Print to " + cPrn)

  PRINT oPrint NAME "Formular" TO (cPrn)

  DEFINE FONT oFnt NAME "ARIAL" SIZE 0,12 OF oPrint

  oPrint:SetCopies (2)
  oPrint:SetLandscape()

  oPrint:Setup ()  // check the settings

  PAGE
    oPrint:CmSay (1,1, cText,oFnt)
  ENDPAGE

  ENDPRINT

  oFnt:End()
ENDIF
RETURN
Everything seems to be fine, the printer is correct, the settings are correct (2 copies, landscape), but the printer ignores these settings. It prints only 1 copy in portrait.
I tested it on 2 computers, with local printers an network printers, always just 1 copy.

Printing from Word works fine with 2 copies.

Is anyone able, to print more than 1 copy with this code ?
kind regards
Stefan
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by James Bott »

Stefan,

Are you using the fixed Rebuild() method?

James
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: FWH 13.12 printer SetCopies problem

Post by StefanHaupt »

Yes
kind regards
Stefan
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWH 13.12 printer SetCopies problem

Post by Antonio Linares »

Stefan,

Many thanks for your great example. I am testing it here but only have the XPS and the Fax drivers (I am not at the office right now) and they don't allow multiple copies.

I appreciate if some others test it with different installed printers, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
StefanHaupt
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: FWH 13.12 printer SetCopies problem

Post by StefanHaupt »

Hmm, really nobody who wants to help to solve this problem ? :(

Please, can anyone run the small test and report the results, many thanks.
kind regards
Stefan
Post Reply