FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Changing default printer for current application only
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Changing default printer for current application only
Posted: Thu Mar 02, 2023 07:47 AM
Guys,
I am getting different result here when I compile this code with my FWH11.08 and FWH1912.

This is the old behavior that I want to retain.
1. Run program
2. Click menu Printer Setup
3. Select a different printer than windows default. e.g. Microsoft Print To Pdf
4. Click Print [will go to recently selected printer]
5. Click Print again [will still go the printer recently selected within the program]

This is the behavior with FWH1912
1. Run program
2. Click menu Printer Setup
3. Select a different printer than windows default. e.g. Microsoft Print To Pdf
4. Click Print [will go to recently selected printer]
5. Click Print again [will now go to windows default printer]

Any help is deeply appreciated as customers have been complaining about the different behavior after their program was upgraded.

TIA

This is the self-contained test code
Code (fw): Select all Collapse
#include "FiveWin.ch"

static oWnd

//----------------------------------------------------------------------------//

function Main()

   DEFINE WINDOW oWnd FROM 1, 1 TO 20, 60 MENU SysMenu() 

   @ 3, 3 BUTTON "&Print" OF oWnd SIZE 80, 20 ;
      ACTION PrintMe()  // try also with oWnd:HardCopy()

   ACTIVATE WINDOW oWnd

return nil

//----------------------------------------------------------------------------//

function PrintMe()

   local oPrn

   PRINT oPrn NAME "Test"
      PAGE
         oPrn:Say( 20, 20, "This is a test" )
      ENDPAGE
   ENDPRINT

return nil

//----------------------------------------------------------------------------//
STATIC FUNC SysMenu()

   local oMenu

   MENU oMenu

      MENUITEM "Printer Setup" action printerSetup()
      MENUITEM "Exit" action oWnd:end()
   ENDMENU
return oMenu
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Changing default printer for current application only
Posted: Thu Mar 02, 2023 03:31 PM
Hua,

I don't know if this will help, but I found it in my notes.

Use the following to set the application's current printer. It will remain the current printer until changed.
Code (fw): Select all Collapse
//--- Set application's current printer. Returns .T. if successful.
// Author: James Bott
function setPrinter( cPrinter )
   local cOldPrinter:="", hDC:=0, aPrn, cText:="", lSuccess:=.f.

   if cPrinter <> prnGetName()

      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)) } )

      if  ascan(aPrn,cPrinter) > 0

         cOldPrinter := GetProfString( "windows", "device" , "" )
         WriteProfString( "windows", "device", cPrinter )
         SysRefresh()
         PrinterInit()
         hDC := GetPrintDefault( GetActiveWindow() )
         if hDC>0
            lSuccess:= resetDC( hDC )
         endif
         SysRefresh()
         WriteProfString( "windows", "device", cOldPrinter  )

      endif
endif
return lSuccess
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: Changing default printer for current application only
Posted: Fri Mar 03, 2023 02:50 AM

Thanks James.

The code helps in setting the app to the last printer selected.

For my earlier problem, I rem out PrinterEnd() at method End() of TPrinter

FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour

Continue the discussion