James Bott wrote:Many users (and many programmers) don't understand how the print driver system works (I don't completely understand it either). There is a default print driver in the registry that is set using the Control Panel. When any app runs it users this driver as the apps' default driver. You can then select a different driver (within the app) and this driver remains the apps driver until another driver is selected (within the app). The Windows registry default driver remains as it was.
So, you can change the driver within an application without changing the Windows default.
FWH changes the default printer, gets the hDC of the new printer and then resets the original default printer. This leaves the default printer changed for a very small time.
cPrinter:= prnGetName() // FW function
setPrinter( cNewPrinter )
// print here
setPrinter( cPrinter ) // restore the old printer
//--- Set application's current printer. Returns .T. if successful.
// Author: James Bott, jbott@compuserve.com
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
James Bott wrote:Yes, a "very small time" being less than a second. This is also how my setPrinter() function works.
cDriver := StrToken( GetProfString( "Devices", cModel, "" ), 1, "," )
cPort := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," )
::hDC := CreateDC( cDriver, cModel, cPort )
//--- 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
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 := resetDC( hDC )
endif
sysRefresh()
endif
endif
return lSuccess
James Bott wrote:if hDC > 0
if hDC != 0
James Bott wrote:lSuccess := resetDC( hDC )
lSuccess := DeleteDC( hDC )
#include "fivewin.ch"
function main()
local oWnd
define window oWnd
activate window oWnd on init doit()
return nil
function doit()
local cPrinter:= 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
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 52 guests