Página 1 de 1

Função para Usar o ICapture da Novell

Enviado: 09 Fev 2012 20:10
por asimoes
Função para atribuir uma lptn (1 a 9) usando o comando icapture da novell.
As novell substituiu o capture pelo comando icapture.

Sem a função abaixo, o usuário é obrigado a selecionar e atribuir uma porta LPTn, correndo o risco também de terminar a captura.
Desta forma fica assegurado ao sistema que a porta lptn está atribuida e pode ser usada.

O código pode ser melhorado por favor contribuam.
Imagem

Código: Selecionar todos

#include "hbcompat.ch"
******************************************************************************
FUNCTION iCaptura(cLpt)
*----------------------------------------------------------------------------*
* Finalidade: Atribuir uma impressora de rede (novell) a uma porta LPTn (1-9)* 
* Exemplo   : iCaptura("LPT1")                                               * 
*             SET CONSOLE OFF                                                *
*             SET DEVICE TO PRINTER                                          * 
*             SET PRINTER TO LPT1                                            *
*             SetPrc(0,0)                                                    *
*             ? "TESTE COM CAPTURA DE PORTA USANDO ICAPTURE DA NOVELL"       *  
*             ?                                                              *
*             EJECT                                                          *
*             SET PRINTER TO                                                 *
*             SET PRINT OFF                                                  * 
*             SET DEVICE TO SCREEN                                           * 
*             SET CONSOLE ON                                                 *
******************************************************************************
LOCAL lOk:=.T., cPrinter:=WIN_PrinterGetDefault(), nLi
LOCAL aPrn:=WIN_PrinterList(.T.,.F.)
LOCAL cPath, cFileName, cFileExt, cExecFile:="", cPorta:="", nIdle:=3
DEFAULT cLpt TO "LPT1"

   FOR nLi:=1 TO Len(aPrn)
      IF aPrn[nLi,1]==cPrinter
          cPorta:=aPrn[nLi,2] //Porta onde a impressora est  ligada
          EXIT
      ENDIF
   NEXT

   IF !Empty(cPorta)
      
      cExecFile:="iCapture "+cLpt+" P="+cPorta
      
      HB_FNameSplit( cExecFile, @cPath, @cFileName, @cFileExt )

      lOk:=MyRun( cExecFile )
      
      HB_IDLESLEEP( nIdle ) 

   ELSE
      Alert("Não há impressora instalada.")
      lOk:=.F.
   ENDIF
   
RETURN lOk


FUNCTION MYRUN( cComando )
LOCAL oShell, lOk:=.T.
   TRY
      oShell:=CreateObject( "WScript.Shell" )
   CATCH
      TRY
         oShell:=CreateObject( "WScript.Shell" )
      CATCH
         lOk:=.F.
      END
   END
   IF lOk
      TRY
        oShell:Run( "%comspec% /c " + cComando, 0, .T. )
        oShell:Refresh()
      CATCH
         lOk:=.F.
      END
      oShell:=Nil
   ENDIF
RETURN lOk