TDOSPRN.PRG que uso.
Code: Select all
/*
ÚÄ Programa ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Aplication: Class TDosPrint ³
³ File: TDOSPRN.PRG ³
³ Author: Ignacio Ortiz de Z£¤iga Echeverr¡a ³
³ CIS: Ignacio Ortiz (Ignacio_Ortiz) ³
³ Internet: http://www.ozs.com ³
³ Date: 09/13/96 ³
³ Time: 20:20:07 ³
³ Copyright: 1997 by Ortiz de Zu¤iga, S.L. ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
NOTES:
This peace of software is freeware and is not part of FiveWin.
The following code will let you print directly to the printer from inside
any Fivewin program, like OLD DOS days. Those users that need DOS printing
speed can use this class instead of the TPrinter class.
The use of the class is very easy and is very similar to the TPrinter class
of Fivewin, but we have not create any command to avoid the use of any
static vars.
This is a little sample of how to use the new class:
LOCAL oPrn
oPrn := TDosPrn():New("lpt1")
oPrn:StartPage() // optional
oPrn:Say(10,20, "This goes in line 10, column 20")
oPrn:EndPage() // optional
oPrn:End()
A little description of all the members of this class:
DATA:
cPort: Printing port, by default "LPT1"
cCompress: String for compressed mode, by default "15"
cNormal: String for normal mode, by default "18"
cFormFeed: String for EJECT, by default "12"
hDC: Printing file Handle (Internal use)
nRow: Current printing row
nCol: Current pringing column
nLeftMargin: Left margin, by default 0
nTopMargin: Top margin, by default 0
METHODS:
New(cPort) Constructor, no comment
End() Destructor, no comment
StartPage() Begining of a page, this method is optional
EndPage() End of page, this method is optional if there is only on page,
or you try to print in a row that is before the current one,
like it did happen with the SAY command
Command(c) Let you send any command to the printer without changing the
current row and col. The string to pass as a parameter should
content the ascii values of the command separated with commas,
for example, the command to reset Epson printers should
be: "27,69"
SetCoors(r,c) Let you change the current row and col is the equivalent of
SetPrc() of Ca-Clipper
NewLine() Increments the current row
Write(cText) Prints the string cText in the current row and column
Say(nRow ,; Prints the string cText in nRow, nCol
nCol ,;
cText )
SayCmp() The same as the method Say but prints in compressed mode and
the row is updated accordly.
NOTE:
At the end of this class is a little function call WorkSheet that will make
the job of DOS printing a lot easier.
Enjoy it!
*/
/*
// Baixei de http://www.fivewin.com.br em 01/11/2002
// Modifiquei em 03/11/2002 - kapiabafwh@bol.com.br By Joao.
// InclusÆo: Parte Modificada Por Ednaldo Rolim - edrol@pop.com.br
// Acrescentada a Parte Modificada Pelo Gilmer: http://www.fivewin.com.br
*/
#Include "FiveWin.Ch"
#Include "Fileio.Ch"
#Translate nTrim(<n>) => AllTrim(Str(<n>,10,0))
#define PF_BUFLEN 2048
//----------------------------------------------------------------------------//
CLASS TDosPrn
DATA LastError
DATA cPort, cCompress, cNormal, cFormFeed, cBuffer
DATA hDC, nRow, nCol, nLeftMargin, nTopMargin
DATA lAnsiToOem, lCompress
DATA lZeraBuffer // By Gilmer http://www.fivewin.com.br
DATA ImpUSB // AS LOGICAL By Diego@sysfar.com.br // Imprimir na USB
DATA oWnd, oPagina // Ednaldo
DATA nPage AS NUMERIC // Ednaldo
//METHOD New(cPort) CONSTRUCTOR
METHOD New(cPort, cVerUSB) CONSTRUCTOR // By Diego da Sysfar
METHOD End()
// Antigo(Old)
// METHOD StartPage() VIRTUAL // NÆo Conta as P ginas
// METHOD EndPage()
// Novo (New) // Conta as P ginas By Ednaldo Rolim
METHOD StartPage() INLINE ::ShowProc() // Ednaldo
METHOD EndPage()
// METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) //velho
METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5) // novo
METHOD SetCoors(nRow, nCol)
METHOD NewLine() INLINE (::cBuffer += CRLF ,;
::nRow++ ,;
::nCol := 0 )
METHOD Write(cText, lAToO) ;
INLINE (IIF(lAtoO == NIL, lAtoO := .T.,),;
::cBuffer += iif(lAtoO, AnsitoOem(cText), cText) ,;
::nCol += len(cText) )
METHOD Say(nRow, nCol, cText, lAToO)
METHOD SayCmp(nRow, nCol, cText)
METHOD CharSay(nRow,nCol,cText) INLINE (IIf(::lCompress,;
::SayCmp(nRow,nCol,cText),;
::Say(nRow,nCol,cText)))
METHOD ZeraBuffer() // By. Gilmer
METHOD PrintFile(cFile)
METHOD ShowProc() // Ednaldo
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( cPort, lFile, lCompress, cVerUSB ) CLASS TDosPrn
DEFAULT cPort := "LPT1", ;
cVerUSB := .F., ;
lFile := .T. , ;
lCompress := .F.
cPort := Upper(cPort)
/* // Copiei de DOSPRINT.PRG
[EPSON]
Normal=18
Bold=27,18,27,69
Medium=27,70,27,58
Compress=15
Large=27,69,27,18,27,14
Tiny=27,70,27,83,0,27,49,18,15
NoTiny=27,70,27,84,27,50
FormFeed=12
Length=27,67,0
[OKIDATA]
Normal=27,70,27,84,27,50,27,15,18
Bold=27,18,27,69
Medium=27,70,27,58
Compress=27,70,27,84,27,15
Large=27,69,27,18,27,14
Tiny=27,70,27,83,0,27,49,18,15
NoTiny=27,70,27,84,27,50
Image=27,76
Header=
Footer=
Jump=216
FormFeed=12
Length=27,67,0
*/
::ImpUSB := .F.
::cCompress := "15"
::cNormal := "18"
::cFormFeed := " " // 12 //Pulo de P gina
::cBuffer := ""
::nLeftMargin := 0
::nTopMargin := 0
::nRow := 0
::nCol := 0
::lAnsiToOem := .T.
::cPort := cPort + iif(!"." $ cPort, ".PRN", "")
If cVerUSB .and. upper( PrnGetPort( ) )="USB"
//::cPort := DirTempdoWindows()+"\usb.imp"
::cPort := cPort + iif(!"." $ cPort, ".IMP", "")
Endif
::hDC := fCreate(::cPort)
::LastError := 0
// By. Gilmer // .F. Pula P gina, .T. NÆo Pula a P gina (Cupom Fiscal)
::lZeraBuffer := .F.
IF ::hDC < 0
::LastError := fError()
ENDIF
::nPage := 1 // Ednaldo
::ShowProc() // Ednaldo
RETURN Self
//----------------------------------------------------------------------------//
METHOD End() CLASS TDosPrn
IF !empty(::nRow+::nCol)
::EndPage()
ENDIF
::LastError := 0
IF !fClose(::hDC)
::LastError := fError()
ENDIF
CursorArrow()
if ::oWnd != Nil // Ednaldo
::oWnd:End() // Ednaldo
endif // Ednaldo
RETURN NIL
//----------------------------------------------------------------------------//
METHOD EndPage() CLASS TDosPrn
LOCAL nFor, nLen, nSec
LOCAL lError
If !::lZeraBuffer // By Gilmer
::Command(::cFormFeed)
End
::LastError := 0
IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
::LastError := fError()
ENDIF
::cBuffer := ""
::nRow := 0
::nCol := 0
RETURN NIL
//----------------------------------------------------------------------------//
//METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) CLASS TDosPrn // Velho
METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5) CLASS TDosPrn // Novo
LOCAL cCommand, cToken, cString
LOCAL nToken
//cString := cValToChar(xPar1) // Velho
cString := cStr1 // Novo
/* // Velho
IF xPar2 != NIL
cString += ","+cValToChar(xPar2)
ENDIF
*/
IF cStr2 != NIL
cString += ","+cStr2
ENDIF
/* // Velho
IF xPar3 != NIL
cString += ","+cValToChar(xPar3)
ENDIF
*/
IF cStr3 != NIL
cString += ","+cStr3
ENDIF
/* // Velho
IF xPar4 != NIL
cString += ","+cValToChar(xPar4)
ENDIF
*/
IF cStr4 != NIL
cString += ","+cStr4
ENDIF
/* // Velho
IF xPar5 != NIL
cString += ","+cValToChar(xPar5)
ENDIF
*/
IF cStr5 != NIL
cString += ","+cStr5
ENDIF
cCommand := ""
nToken := 1
DO WHILE !Empty(cToken := StrToken(cString, nToken++, ","))
cCommand += Chr(Val(cToken))
ENDDO
::cBuffer += cCommand
RETURN NIL
//----------------------------------------------------------------------------//
METHOD SetCoors(nRow, nCol) CLASS TDosPrn
nRow += ::nTopMargin
nCol += ::nLeftMargin
IF ::nRow > nRow
::EndPage()
::nPage++ // Ednaldo
::StartPage()
ENDIF
/* // do Site
IF ::nRow > nRow
::EndPage()
::StartPage()
ENDIF
*/
// Tava Aqui
/* // do Site
IF nRow == ::nRow .AND. nCol < ::nCol
::EndPage()
::StartPage()
ENDIF
*/
DO WHILE ::nRow < nRow
::NewLine()
ENDDO
IF nCol > ::nCol
::Write(Space(nCol-::nCol))
ENDIF
// Para Imprimir Primeiro na coluna desejada exemplo 1§ na Coluna 50
// Depois na coluna 05... By NetSpeed Inverte-se a Ordem da Cabe‡a de
// ImpressÆo, Come‡ando do Fim Para o Inicio...
If nRow == ::nRow .and. nCol < ::nCol
::Write(Chr(13)) // NetSpeed
Endif
// Aqui Inicia da Coluna 1 em diante, nÆo faz como a anterior.
// Ou Seja do Inicio Para o Fim da Cabe‡a de ImpressÆo, o Que ‚ Normal.
IF nRow == ::nRow .AND. nCol < ::nCol
::EndPage()
::nPage++ // Ednaldo
::StartPage()
ENDIF
// By. Gilmer
If Len(::cBuffer)>=7928
::ZeraBuffer()
Endif
RETURN NIL
//----------------------------------------------------------------------------//
METHOD Say(nRow, nCol, cText, lAToO) CLASS TDosPrn
DEFAULT lAToO := ::lAnsiToOem
IF VALTYPE( cText ) = "D"
cText := DTOC( cText )
ENDIF
IF VALTYPE( cText ) = "N"
cText := STR( cText )
ENDIF
::SetCoors(nRow, nCol)
::Write(cText, lAToO)
RETURN NIL
//----------------------------------------------------------------------------//
METHOD SayCmp(nRow, nCol, cText, lAToO) CLASS TDosPrn
DEFAULT lAToO := ::lAnsiToOem
::Command(::cCompress)
::SetCoors(nRow, nCol)
::cBuffer += iif(lAToO, AnsitoOem(cText), cText)
::nCol += Int(len(cText))
* by Digao ::nCol += Int(len(cText)/1.7+.5)
::Command(::cNormal)
RETURN NIL
//----------------------------------------------------------------------------//
METHOD ZeraBuffer() CLASS TDosPrn
/* // Em Ingles
::LastError := 0
If ::lZeraBuffer
IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
::LastError := fError()
ENDIF
::cBuffer := ""
Endif
*/
// Em Clipper Puro Como ‚!
Self:LastError := 0
If Self:lZeraBuffer
IF fWrite(Self:hDC, Self:cBuffer) < len(Self:cBuffer)
Self:LastError := fError()
ENDIF
Self:cBuffer := ""
Endif
RETURN NIL
//----------------------------------------------------------------------------//
FUNCTION WorkSheet(cPort)
LOCAL oPrn
LOCAL cLine
LOCAL nFor
cLine := ""
FOR nFor := 0 TO 7
cLine += Str(nFor,1)+Replicate(".",9)
NEXT
cLine := Substr(cLine,3)
oPrn := TDosPrn():New(cPort)
oPrn:StartPage()
//alterei em 29/03/2004, Pois Com o Five 2.4, Pulo de P gina estava errado
FOR nFor := 0 TO 56 //65
oPrn:Say(nFor,0,StrZero(nFor,2)+cLine)
NEXT
oPrn:EndPage()
oPrn:End()
RETURN NIL
//----------------------------------------------------------------------------//
METHOD PrintFile(cFile) CLASS TDosPrn
LOCAL hFile
LOCAL nRead
LOCAL cBuffer
hFile := FOpen(cFile, FO_READ)
IF hFile < 0
RETURN .F.
ENDIF
cBuffer := Space(PF_BUFLEN)
DO
nRead := fRead(hFile, @cBuffer, PF_BUFLEN)
IF fWrite(::hDC, Left(cBuffer, nRead)) < nRead
::LastError := fError()
fClose(hFile)
RETURN .F.
ENDIF
UNTIL nRead == PF_BUFLEN
fClose(hFile)
RETURN .T.
//----------------------------------------------------------------------------//
// Visualiza Processo de impressao // Ednaldo
//----------------------------------------------------------------------------//
METHOD ShowProc() CLASS TDosPrn
IF ::oWnd = Nil
* DEFINE DIALOG ::oWnd TITLE "Imprimindo ..." ;
* FROM 230, 217 TO 360, 575 PIXEL ;
* COLORS CLR_BLACK, nRGB(193,205,205)
*
* @ 10, 08 TO 40, 172 OF ::oWnd PIXEL
*
* @ 1.4, 2 ICON NAME "PRINT.ICO" OF ::oWnd
*
* @ 25, 35 SAY "Imprimindo Página :" ;
* PIXEL OF ::oWnd SIZE 70, 12 RIGHT
*
* @ 25, 107 SAY ::oPagina VAR ::nPage ;
* PIXEL OF ::oWnd UPDATE SIZE 15, 12 RIGHT
*
* @ 47, 60 BUTTON "Aguarde..." SIZE 60, 12 ;
* PIXEL OF ::oWnd ACTION .t.
*
* ::oWnd:bPainted := {|| iif(::nPage>0, ::oPagina:Refresh(), )}
*
* ACTIVATE DIALOG ::oWnd CENTER NOWAIT
*
* EndDialog()
ResAllFree()
CursorWait()
SysRefresh()
ELSE
::oWnd:BeginPaint()
::oWnd:Paint()
::oWnd:EndPaint()
ENDIF
RETURN NIL
// Fim do Programa. kapiabafwh@gmail.com - Sao Paulo - Brazil.
Regards, saludos.