O conceito, não é mais DOS (monousuário) nem tem apenas uma impressora na LPTX
Use as ferramentas que o sistema operacional oferece e que já tem na linguagem.
aPrn := WIN_PRINTERLIST() //Retorna array com todas as impressoras disponiveis.
cPrint := win_PrinterGetDefault() //Retorna a impressora padrão.
Criar o arquivo em disco e depois escolher a forma. Se for da maneira antiga use printfileraw()
Código: Selecionar todos
nRet := Win_PrintFileRaw(cPrint,cArq,cTit)
if nRet < 1
cMsg := 'Erro Imprimindo: '
SWITCH nRet
CASE -1
cMsg += "Parâmetro inválido passado" ; EXIT
CASE -2
cMsg += "WinAPI OpenPrinter() Falha na chamada" ; EXIT
CASE -3
cMsg += "WinAPI StartDocPrinter() Falha na chamada" ; EXIT
CASE -4
cMsg += "WinAPI StartPagePrinter() Falha na chamada" ; EXIT
CASE -5
cMsg += "WinAPI malloc() of memory failed" ; EXIT
CASE -6
cMsg += "Arquivo " + cArq + " não Localizado" ; EXIT
//DEFAULT
// cMsg += cFile + " PRINTED OK!!!"
END
hwg_Msgstop(cMsg)
EndIf
Return .T.
Código: Selecionar todos
*********************************
Function PrintWinPrn(cArq,cPrint)
*********************************
*
*
Local oPrn, aPrn:=WIN_PRINTERLIST(), n := 0
if empty(aPrn)
hwg_Msginfo('Não há impressoras instaladas')
return .f.
endif
If cPrint == Nil
cPrint := win_PrinterGetDefault()
EndIf
oPrn := win_prn():New(cPrint)
oPrn : LandScape := .f.
oPrn : FormType := FORM_A4
oPrn : Copies := 1
oPrn : CharSet(255)
oPrn : setfont('Courier New',,10,,,,255)
If !oPrn:Create()
hwg_Msginfo("Não foi criado documento")
Return Nil
EndIf
If !oPrn:startDoc("Imprimindo Documento")
hwg_Msginfo("Erro na Impressora")
Return Nil
EndIf
HB_CDPSelect("PT850")
//setprc(7,0)
cText := memoread(cArq)
nLinh := mlcount(cText)
oPrn:NewLine()
oPrn:NewLine()
For n := 1 to nLinh
oPrn:Textout(WIN_ansitooem(memoline(cText,,n)),.t.)
Next
oPrn:EndDoc()
HB_CDPSelect( "PTISO")
Return .t.
Esses comandos só existem ainda para fins de compatibilidade.
As impressoras de hoje, são todas wireless!!! não ensina coisa errada para as pessoas não!
Saudações,
Itamar M. Lins Jr.




