Jump to content
Fivewin Brasil

Ajuda na escolha das Impressoras


Pedro Alcântara

Recommended Posts

  • 19 years later...

Amiguinhos,

FUNCTION GetListPrinters()
   LOCAL aPrinter
   LOCAL cPrinter
   LOCAL nError, hSubKey, nBufSize, nCount
   LOCAL HKEY_CURRENT_USER   := 2147483649
   LOCAL HKEY_LOCAL_MACHINE  := 2147483650
   LOCAL HKEY_CURRENT_CONFIG := 2147483653
   LOCAL KEY_ALL_ACCESS      := 983139
   LOCAL ERROR_SUCCESS       := 0

   aPrinter := {}
   cPrinter := Space(256)
   hSubKey  := 0
   nBufSize := 256
   nCount   := 0
   nError   := -1
   nError   := RegOpenKeyEx(HKEY_CURRENT_CONFIG,;
                          "System\CurrentControlSet\Control\Print\Printers",;
                          0, KEY_ALL_ACCESS, @hSubKey)
   IF nError != 0
      return "Erro abrindo RegOpenKeyEx"
   ENDIF
   DO WHILE (nError := RegEnumKeyEx(hSubKey, nCount++, @cPrinter, @nBufSize)) == 0
      Aadd(aPrinter, Left(cPrinter, nBufSize))
      cPrinter := Space(256)
      nBufSize := 256
   ENDDO
   RegCloseKey(hSubKey)
RETURN aPrinter

Inclua a função acima em seus .PRGs

No ponto em que deseja escolher a impressora coloque:

   aPortPRN := GetPrinters()
   for iPortPRN = 1 to len( aPortPRN )
       aPortPRN[iPortPRN] := substr( aPortPRN[iPortPRN], 1, at(",",aPortPRN[iPortPRN])-1 )
   next
   //
   aPortPRNCoz := { "-NENHUMA-" }
   for iPortPRN = 1 to len( aPortPRN )
       aadd( aPrintModel, aPortPRN[iPortPRN] )
       aadd( aPortPRNCoz, aPortPRN[iPortPRN] )
   next

Em um controle combo faça uso da escolha da impressora:

            REDEFINE COMBOBOX oCbx VAR cPrintModel ITEMS aPrintModel ID 100 OF oDlg

Faça o uso do motor de impressão que quiser com as escolhas desejadas:

...  
              cPRNcFile   := "C:\TEMP\TEXTO.TXT"
              cEmiteMotor := "TYPE"
              case cEmiteMotor = "TYPE"
			       WaitRun( "type " + cPRNcFile + " > " + cPrintModel + " " , 0 )
              case cEmiteMotor = "PRINTRAW"
                   WaitRun( "printraw.exe " + cPRNcFile + " " + cPrintModel, 0 ) 
              case cEmiteMotor = "PRINT"
                   WaitRun( "print.exe /D:" + cPrintModel + " " + cPRNcFile, 0 ) 
              case cEmiteMotor = "COPY" .or. cEmiteMotor = "COPYFILE"
                   __CopyFile( cPRNcFile, cPrintModel )
              case cEmiteMotor = "COMMAND" .or. cEmiteMotor = "COMMAND.COM" 
                   WaitRun( "command.com /c copy /b " + cPRNcFile + " " + cPrintModel + "" , 0 )
...  

Onde lê-se GetPrinters troque por GetListPrinters

Link to comment
Share on other sites

Em 27/11/2021 at 10:37, kapiaba disse:

Fala meu baixinho querido. Quantos anos estais agora, 24 anos?

kkkkk, pensei que nesta linguagem só tinha os tios como no forum internacional e eu também que sou da época do pc 500, do disquete de 8 polegadas que carregava o SO no PC 500 e quando chegou o XT, era o Deus dos pcs e os mainframes ainda eram com fitas.
Particulamente me alegro desse forum porque aprendi dBase III e é por isso assim como o corinthiano Kapi, não largo esta minha esposa (linguagem) mas claro, dando umas traídas nela de vez em quando kkkkkkk

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...