Fórum Duvida de Endereçamento de Impressora em rede ???? #228977

30/04/2004

0

Estou trabalhando com uma comutadora o codigo de entrada e saida eu ja consegui identificar as portas da comutadora,o problema eo seguinte em vez de passar a LPT1 eu queria identificar as outras impressoras atraves de rede, se alguem puder me passar o comando ou uma dica eu fiquerei muito grato


Poman

Poman

Responder

Posts

02/05/2004

Mmtoor

unit uPrnPadrao;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Printers, ExtCtrls, Buttons;

type
TfPrnPadrao = class(TForm)
PrinterSetupDialog1: TPrinterSetupDialog;
ListBox1: TListBox;
Button1: TBitBtn;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
fPrnPadrao: TfPrnPadrao;

implementation
Const
ScreenWidth: LongInt = 800;
ScreenHeight: LongInt = 600;
{$R *.DFM}

function PrinterOnLine : Boolean;
const
PrnStInt : Byte = $17;
StRq : Byte = $02;
PrnNum : Word=0;{0 para LPT1, 1 para LPT2}
var
nResult : byte;
begin
asm
mov ah,StRq;
mov dx,PrnNum;
Int $17;
mov nResult,ah;
end;
PrinterOnLine := (nResult and $80) = $80;
end;


procedure TfPrnPadrao.FormShow(Sender: TObject);
begin
ListBox1.Items.Assign(Printer.Printers);
ListBox1.ItemIndex := Printer.PrinterIndex;
end;
procedure FazPrnAtualVirarDefault;
var
Res : DWord;
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port : array[0..255] of char;
WindowsStr: array[0..255] of char;
hDeviceMode: THandle;
begin
// Pega dados da impressora atual
Printer.GetPrinter(Device,Driver,Port,hDeviceMode);
//Monta String exigida pela API do Windows
StrCat(Device,´,´);
StrCat(Device,Driver);
StrCat(Device,´,´);
StrCat(Device,Port);
StrPCopy(WindowsStr,´Windows´);
//Torna a impressora a atual
WriteProfileString(WindowsStr,´device´,Device);
SendMessageTimeout(HWND_BROADCAST,WM_WININICHANGE,0,DWORD(@WindowsStr),SMTO_NORMAL,1000,Res);
end;

procedure TfPrnPadrao.Button1Click(Sender: TObject);
begin
button1.Enabled := false;
try
//verifica se o listbox tem algo selecionado
if ListBox1.ItemIndex >= 0 then
begin
//Ajusta a impressora atual do programa
Printer.PrinterIndex := ListBox1.ItemIndex;
//faz a atual virar default
FazPrnAtualvirarDefault;
end;
finally
Button1.Enabled := True;
Messagedlg(´Impressora Padrão Alterada´,mtinformation,[mbok],0);
end;
end;

procedure TfPrnPadrao.BitBtn2Click(Sender: TObject);
begin
PrinterSetupDialog1.Execute;
end;

procedure TfPrnPadrao.FormCreate(Sender: TObject);
begin
Scaled:= True;
If (Screen.Width <> ScreenWidth) Then
Begin
Height:= LongInt(Height) * LongInt(Screen.Height) DIV ScreenHeight;
Width:= LongInt(Width) * LongInt(Screen.Width) DIV ScreenWidth;
ScaleBy(Screen.Width, ScreenWidth);
end;
end;

end.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar