Antonio,
I've been doing some tests and i think this should be the correct code:
Method New
METHOD New( cDocument, lUser, lMeta, cModel, lModal, lSelection ) CLASS TPrinter
local aOffset
local cPrinter
DEFAULT cDocument := "FiveWin Report" ,;
lUser := .f., lMeta := .f., lModal := .f., lSelection := .f.
if lUser
::hDC := GetPrintDC( GetActiveWindow(), lSelection, PrnGetPagNums() )
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 )
// PrinterInit()
// DeleteDC( ::hDC )
// ::hDC = PrinterDCfromName( cModel )
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
else
::nXOffset = 0
::nYOffset = 0
::nOrient = DMORIENT_PORTRAIT
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 think this is what you initially stated in your first post
Function PrintBegin
function PrintBegin( cDoc, lUser, lPreview, xModel, lModal, lSelection )
local aPrn
local cText, cDevice
local nScan
if xModel == nil
return oPrinter := TPrinter():New( cDoc, lUser, lPreview,, lModal, lSelection )
endif
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 Valtype(xModel) == "N"
if xModel < 0 .or. xModel > len(aPrn)
nScan := 0
else
nScan := xModel
endif
else
if ( nScan := Ascan( aPrn, {|v| Upper( xModel ) == Upper( v ) } ) ) == 0
nScan = Ascan( aPrn, {|v| Upper( xModel ) $ Upper( v ) } )
endif
endif
if nScan == 0
MsgBeep()
return oPrinter := TPrinter():New( cDoc, .T., lPreview,, lModal, lSelection )
endif
cText := GetProfString( "Devices", aPrn[ nScan ] )
cDevice := aPrn[ nScan ] + "," + cText
return oPrinter := TPrinter():New( cDoc, .f., lPreview, cDevice, lModal, lSelection )
This should revert back to it's original state
The above code changes seem to work fine on my system when i specify a printer and also when i dont specify a printer and choose from the printer selection list
Regards,
Pete