Me uno al comentario que en su dia hizo Rafa, pero por encima de todo esta el respetar las decisiones de cada uno, y agradecerle a William por esta y por tantas contribuciones tan valiosas que nos ha hecho a todos
![Smile :-)](./images/smilies/icon_smile.gif)
Antonio Linares wrote:Que ocurrió finalmente con ese trabajo de William ? Alguien tiene copia ? William, aún lo proporcionas ?
Me uno al comentario que en su dia hizo Rafa, pero por encima de todo esta el respetar las decisiones de cada uno, y agradecerle a William por esta y por tantas contribuciones tan valiosas que nos ha hecho a todos
Code: Select all | Expand
/*
//
// Fecha : 22 de enero del 2010
// Autor : William Morales
// Módulo : Clase para imprimir documentos directos a la impresora de windows
// Nombre : wtraw.prg
//
*/
#include <fivewin.ch>
#xcommand @ <nRow>, <nCol> SAYDOS <Text> => ;
DevPos( <nRow>,<nCol>); DevOut(<Text>)
CLASS TDirectPrint
DATA cIncos AS CHARACTER INIT "TDirectPrint v 0.1"
DATA cBuild AS CHARACTER INIT "20100122"
DATA cCredits AS CHARACTER INIT "Autor: William Morales" + CRLF + ;
"wmormar@hotmail.com" + CRLF + CRLF + ;
"Tester: " + CRLF + ;
" Willi Quintana" + CRLF + ;
" Oscar Chacon (costa rica)"
DATA cMsg AS CHARACTER INIT ""
DATA cFile AS CHARACTER INIT ""
DATA cContent AS CHARACTER INIT ""
DATA cPrinter AS CHARACTER INIT GetDefaultPrinter()
DATA cDocument AS CHARACTER INIT "Imprimiendo documento : Powered by INCOS"
DATA cLogo AS CHARACTER INIT ""
DATA nRow AS NUMERIC INIT 0
DATA nCol AS NUMERIC INIT 0
DATA nCopy AS NUMERIC INIT 1
DATA nHeight AS NUMERIC INIT 20
DATA nWidth AS NUMERIC INIT 35
DATA lDo AS LOGICAL INIT .f.
METHOD new( cPrinter ) CONSTRUCTOR
METHOD printerdefault() INLINE ::cPrinter := GetDefaultPrinter()
METHOD setlpt( nPort )
METHOD jump( nJump )
METHOD esc( cText )
METHOD say( nRow, nCol, cText )
METHOD opencash( cPrinter, nCash )
METHOD sendtoprinter()
METHOD checkport( nPort ) INLINE PrintReady( nPort )
METHOD eject() INLINE ::esc( Chr(12) )
METHOD beginprint() INLINE (::esc( Chr(27) + Chr(64) ), ;
::esc( Chr(27) + Chr(120), Chr( 0 ) ) ;
)
METHOD endprint() INLINE (::esc( Chr(27) + Chr(18) ), ;
::esc( Chr(27) + Chr(50) ), ;
::esc( Chr(27) + Chr(72) ), ;
::esc( Chr(27) + Chr(80) ) ;
)
METHOD bold( lOnOff ) INLINE IF( lOnOff, ::esc( Chr(27) + Chr(71) ), ;
::esc( Chr(27) + Chr(72) ) ;
)
METHOD condensed() INLINE ::esc( Chr(27) + Chr(15) )
METHOD normal() INLINE ::esc( Chr(27) + Chr(18) )
METHOD expansive( lOnOff ) INLINE IF( lOnOff, ::esc( Chr(27) + Chr(14) ), ;
::esc( Chr(27) + Chr(20) ) ;
)
METHOD superscript( lOnOff ) INLINE IF( lOnOff, ::esc( Chr(27) + Chr(83) + Chr(48) ), ;
::esc( Chr(27) + Chr(84) ) ;
)
METHOD subscript( lOnOff ) INLINE IF( lOnOff, ::esc( Chr(27) + Chr(83) + Chr(49) ), ;
::esc( Chr(27) + Chr(84) ) ;
)
METHOD underline( lOnOff ) INLINE IF( lOnOff, ::esc( Chr(27) + Chr(45) + Chr(49) ), ;
::esc( Chr(27) + Chr(45) + Chr(40) ) ;
)
METHOD prnfile( cFile )
METHOD logo( cFile, nHeight, nWidth ) INLINE (::cLogo := cFile, ::nHeight := nHeight, ;
::nWidth := nWidth )
METHOD printlogo()
ENDCLASS
/**************************************************************************************/
METHOD new( cPrinter )
LOCAL nFile := 1
DEFAULT cPrinter := GetDefaultPrinter()
::cPrinter := cPrinter
::lDo := .t.
::cMsg := ::cIncos + " - " + ::cBuild
::cContent := ""
::nCol := 0
::nRow := 0
WHILE .t.
::cFile := "wmprn" + PadL( nFile++, 3, "0" ) + ".gcj"
IF !File( ::cFile )
EXIT
ENDIF
sysrefresh()
ENDDO
SET PRINTER TO (::cFile)
SET DEVICE TO PRINT
RETURN Self
/**************************************************************************************/
METHOD setlpt( nPort )
LOCAL cPort := ""
DEFAULT nPort := 1
::lDo := .t.
cPort := PrinterPortToName( "LPT" + WCStr(nPort) + ":" )
IF Empty( cPort )
MSGINFO( "No hay impresora en el puerto seleccionado...", ::cMsg )
::lDo := .f.
RETURN NIL
ENDIF
::cPrinter := cPort
RETURN NIL
/**************************************************************************************/
METHOD jump( nJump )
LOCAL x := 0
DEFAULT nJump := 1
FOR x := 1 TO nJump
@ ::nRow, 00 SAYDOS ""
::nRow += 1
NEXT
::nCol := 00
RETURN NIL
/**************************************************************************************/
METHOD esc( cText )
@ ::nRow++, 00 SAYDOS cText
::nCol := Len(cText) + 1
RETURN NIL
/**************************************************************************************/
METHOD say( nRow, nCol, cText )
IF nRow < ::nRow
nRow := ::nRow
ENDIF
IF nCol < ::nCol
nCol := ::nCol
ENDIF
::nRow := nRow
::nCol := nCol
@ ::nRow++, ::nCol SAYDOS cText
::nCol := ::nCol + Len(cText) + 1
RETURN NIL
/**************************************************************************************/
METHOD opencash( cPrinter, nCash )
LOCAL cEscape := ""
DEFAULT cPrinter := "epson"
DEFAULT nCash := 0
cEscape := Chr( 27 ) + Chr( 112 ) + WCStr( nCash ) + Chr(40) + Chr( 108 )
IF Lower( cPrinter ) == "start"
cEscape := Chr( 27 ) + Chr( 80 )
ENDIF
@ ::nRow++, 00 SAYDOS cEscape
::nCol := Len(cEscape) + 1
RETURN NIL
/**************************************************************************************/
METHOD sendtoprinter( lDelete )
LOCAL x := 1
LOCAL nRet := 0
LOCAL cMsg := ""
LOCAL lShow := .f.
DEFAULT lDelete := .t.
SET DEVICE TO SCREEN
SET PRINTER TO
IF ::nCopy < 1
::nCopy := 1
ENDIF
FOR x := 1 TO ::nCopy
::printlogo()
nRet := PrintFileRaw( ::cPrinter, ::cFile, ::cDocument )
cMsg += "Copy " + WCStr( x ) + CRLF
IF nRet # 1
lShow := .t.
ENDIF
SWITCH nRet
CASE -1
cMsg += "Invalid parameters passed to function" ; EXIT
CASE -2
cMsg += "WinAPI OpenPrinter() call failed" ; EXIT
CASE -3
cMsg += "WinAPI StartDocPrinter() call failed" ; EXIT
CASE -4
cMsg += "WinAPI StartPagePrinter() call failed" ; EXIT
CASE -5
cMsg += "WinAPI malloc() of memory failed" ; EXIT
CASE -6
cMsg += "File " + ::cFile + " not found" ; EXIT
DEFAULT
cMsg += "PRINTED OK!!!"
END
cMsg += CRLF + CRLF
NEXT
IF lDelete
FErase( ::cFile )
ENDIF
IF lShow
MSGINFO( cMsg, ::cMsg )
ENDIF
RETURN NIL
/**************************************************************************************/
METHOD prnfile( cFile, lDeletepost )
DEFAULT lDeletepost := .f.
::cFile := cFile
::sendtoprinter( lDeletepost )
RETURN NIL
/**************************************************************************************/
METHOD printlogo()
LOCAL cEmf := ""
LOCAL oImg := NIL
IF Empty( ::cLogo )
RETURN NIL
ENDIF
IF !File( ::cLogo )
MSGINFO( "Archivo logo no existe, verifique...", ::cMsg )
RETURN NIL
ENDIF
//oImg := TImage()
//oImg:LoadImage( , ::cLogo )
//wgrabaemf( oImg:hDC, "wmlogo.xxx" )
//PrintFileRaw( ::cPrinter, ::cLogo, ::cDocument )
RETURN NIL
/**************************************************************************************/
Code: Select all | Expand
FUNCTION WCStr( xExp, nDecimals )
LOCAL cType
IF xExp == NIL
RETURN 'NIL'
ENDIF
cType := ValType( xExp )
SWITCH cType
CASE 'C'
RETURN xExp
CASE 'D'
RETURN dToS( xExp )
CASE 'L'
RETURN IIF( xExp, '.T.', '.F.' )
CASE 'N'
IF !HB_IsNil( nDecimals )
RETURN AllTrim(Str( xExp, 11, nDecimals ))
ELSE
RETURN AllTrim(Str( xExp ))
ENDIF
CASE 'A'
RETURN "{ Array of " + LTrim( Str( Len( xExp ) ) ) + " Items }"
CASE 'B'
RETURN '{|| Block }'
CASE 'O'
RETURN "{ " + xExp:ClassName() + " Object }"
CASE 'P'
RETURN NumToHex( xExp )
CASE 'H'
RETURN "{ Hash of " + LTrim( Str( Len( xExp ) ) ) + " Items }"
DEFAULT
RETURN "Type: " + cType
END
RETURN ""