Antonio,
Here is a part of Fivewin 2.5 PRINTER.PRG file, the method New() :
- Code: Select all Expand view
METHOD New( cDocument, lUser, lMeta, cModel, lModal ) CLASS TPrinter
local aOffset
local cPrinter
DEFAULT cDocument := "FiveWin Report" ,;
lUser := .f. ,;
lMeta := .f. ,;
lModal := .f.
if lUser
::hDC := GetPrintDC( GetActiveWindow() )
if ::hDC != 0
cModel := ::GetModel()+","+::GetDriver()+","+::GetPort()
endif
elseif cModel == NIL
::hDC := GetPrintDefault( GetActiveWindow() )
if ::hDC != 0
cModel := ::GetModel()+","+::GetDriver()+","+::GetPort()
endif
else
cPrinter := GetProfString( "windows", "device" , "" )
WriteProfString( "windows", "device", cModel )
SysRefresh()
PrinterInit()
::hDC := GetPrintDefault( GetActiveWindow() )
SysRefresh()
WriteProfString( "windows", "device", cPrinter )
endif
if ::hDC != 0
aOffset := PrnOffset( ::hDC )
::nXOffset := aOffset[1]
::nYOffset := aOffset[2]
::nOrient := ::GetOrientation()
elseif ComDlgXErr() != 0
MsgStop( "There are no printers installed!" + CRLF + ;
"Please exit this application and install a printer." )
::nXOffset := 0
::nYOffset := 0
endif
::cDocument := cDocument
::cModel := cModel
::nPage := 0
::nPad := 0
::lMeta := lMeta
::lStarted := .F.
::lModified := .F.
::lPrvModal := lModal
if !lMeta
::hDcOut := ::hDC
else
::aMeta := {}
::cDir := GetEnv("TEMP")
if empty(::cDir)
::cDir := GetEnv("TMP")
endif
if Right( ::cDir, 1 ) == "\"
::cDir = SubStr( ::cDir, 1, Len( ::cDir ) - 1 )
endif
if !empty(::cDir)
if !lIsDir(::cDir)
::cDir := GetWinDir()
endif
else
::cDir := GetWinDir()
endif
endif
return Self
//----------------------------------------------------------------------------//
I never use GetPrintDC().
Below is my method New() for class TPrinter() :
- Code: Select all Expand view
METHOD New( cDocument, lUser, lMeta, cModel, lModal) CLASS TPrinter
local aOffset
local cPrinter
LOCAL cPortDrv
DEFAULT cDocument := "Impression ICIM" ,;
lUser := .f. , ;
lMeta := .f. , ;
lModal := .f.
IF cModel = NIL
cModel := WinDefPrn()
ENDIF
cPortDrv := WinGetPrnP(cModel)
cModel := cModel + "," + cPortDrv
SysRefresh()
::hDC := CreateDC( TOKEN(cModel,",",2), ;
TOKEN(cModel,",",1), TOKEN(cModel,",",3))
SysRefresh()
if ::hDC != 0
aOffset := PrnOffset( ::hDC )
::nXOffset := aOffset[1]
::nYOffset := aOffset[2]
::nOrient := ::GetOrientation()
elseif ComDlgXErr() != 0
MsgStop( OemToAnsi("Aucune imprimante n'est installée ou accessible actuellement...") )
::nXOffset := 0
::nYOffset := 0
endif
::cDocument := cDocument
::cModel := cModel
::nPage := 0
::nPad := 0
::lMeta := lMeta
::lStarted := .F.
::lModified := .F.
::lPrvModal := lModal
if !lMeta
::hDcOut := ::hDC
else
::aMeta := {}
::cDir := GetEnv("TEMP")
if empty(::cDir)
::cDir := GetEnv("TMP")
endif
if Right( ::cDir, 1 ) == "\"
::cDir = LEFT( ::cDir, LEN( ::cDir ) - 1 )
endif
if !empty(::cDir)
if !lIsDir(::cDir)
::cDir := GetWinDir()
endif
else
::cDir := GetWinDir()
endif
endif
return Self
See my last contributions to find source code of WinDefPrn()
and WinGetPrnP().
I suggest to delete all calls of theses functions :
PrinterInit(), GetModel(), GetDriver(), GetPort(), GetPrintDefault()
All functions who call theses functions need to be rewritted,
or rewritte theses functions.
Delete also all read-write in .ini files to manage printers.