Page 1 of 2
FWH 13.12 printer SetCopies problem
Posted: Sun Jan 19, 2014 11:21 am
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
Re: FWH 13.12 printer SetCopies problem
Posted: Sun Jan 19, 2014 2:00 pm
by Antonio Linares
Birol,
Instead of calling oPrn:SetCopies( 2 ) please do PrnSetCopies( 2 ) and let me know your results, thanks
Re: FWH 13.12 printer SetCopies problem
Posted: Sun Jan 19, 2014 4:32 pm
by betoncu
Antonio,
Thanks for your help. It is working now.
Re: FWH 13.12 printer SetCopies problem
Posted: Wed Jan 22, 2014 4:31 pm
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
Re: FWH 13.12 printer SetCopies problem
Posted: Wed Jan 22, 2014 7:12 pm
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?
Re: FWH 13.12 printer SetCopies problem
Posted: Thu Jan 23, 2014 12:10 am
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
Re: FWH 13.12 printer SetCopies problem
Posted: Thu Jan 23, 2014 2:46 pm
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
Re: FWH 13.12 printer SetCopies problem
Posted: Fri Jan 24, 2014 7:30 am
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.
Re: FWH 13.12 printer SetCopies problem
Posted: Fri Jan 24, 2014 7:50 am
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.
Re: FWH 13.12 printer SetCopies problem
Posted: Fri Jan 24, 2014 8:55 am
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
Re: FWH 13.12 printer SetCopies problem
Posted: Sat Jan 25, 2014 11:33 am
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 ?
Re: FWH 13.12 printer SetCopies problem
Posted: Sat Jan 25, 2014 4:47 pm
by James Bott
Stefan,
Are you using the fixed Rebuild() method?
James
Re: FWH 13.12 printer SetCopies problem
Posted: Sat Jan 25, 2014 7:39 pm
by StefanHaupt
Yes
Re: FWH 13.12 printer SetCopies problem
Posted: Sun Jan 26, 2014 8:47 am
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
Re: FWH 13.12 printer SetCopies problem
Posted: Wed Jan 29, 2014 9:05 am
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.