You don't need to restore anything as the routine doesn't change the windows default printer nor the application default printer. Try this:James Bott wrote:Enrico,
I have made the changes you suggested but the routine is not restoring the original printer. Ideas?
Code: Select all
#include "fivewin.ch"
function main()
local oWnd
define window oWnd
activate window oWnd on init doit()
return nil
function doit()
local cPrinter:= "Your alternate printer" //prnGetName()
// printerSetup()
msgInfo( prnGetName() )
setPrinter( cPrinter )
msgInfo( prnGetName() )
return nil
//--- Set application's current printer. Returns .T. if successful.
// Author: James Bott, jbott@compuserve.com
function setPrinter( cPrinter )
local hDC:=0, aPrn, cText:="", lSuccess:=.f., cDriver:="", cPort:=""
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
// Code by Enrico Maria Giordano
cDriver := StrToken( GetProfString( "Devices", cPrinter, "" ), 1, "," )
cPort := StrToken( GetProfString( "Devices", cPrinter, "" ), 2, "," )
hDC := CreateDC( cDriver, cPrinter, cPort )
sysrefresh()
msgInfo( cDriver, "cDriver") // returns "winspool"
msgInfo( cPort, "cPort") // returns "Ne00:"
msgInfo( hDC, "hDC" ) // sometimes positive, sometimes negative
if hDC != 0
lSuccess := DeleteDC( hDC )
endif
sysRefresh()
endif
endif
return lSuccess