在计算机世界网站上有截取远程屏幕的代码,这是我改写的 :
unit SvrUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, NMUDP;
type
TServer = class(TForm)
Image1: TImage;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
SUDP: TNMUDP;
BitBtn2: TBitBtn;
procedure ServerCreate(Sender: TObject);
procedure ServerDestroy(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure SUDPDataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Server: TServer;
implementation
const
BufSize=2048;
var
RsltStream,TmpStream:TMemoryStream;
{$R *.DFM}
procedure TServer.ServerCreate(Sender: TObject);
begin
RsltStream:=TMemoryStream.Create;
TmpStream:=TMemoryStream.Create;
end;
procedure TServer.ServerDestroy(Sender: TObject);
begin
RsltStream.Free;
TmpStream.Free;
end;
procedure TServer.BitBtn1Click(Sender: TObject);
var
ReqCode:array[0..29] of char;
ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
TmpStream.Clear;
RsltStream.Clear;
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;
procedure TServer.SUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
ReqCode:array[0..29] of char;ReqCodeStr:string;
begin
ReqCodeStr:='show'+Edit1.text;
StrpCopy(ReqCode,ReqCodeStr);
SUDP.ReadStream(TmpStream);
RsltStream.CopyFrom(TmpStream,NumberBytes);
if NumberBytes< BufSize then { 数据已读完 }
begin
RsltStream.Position:=0;
Image1.Picture.Bitmap.LoadFromStream(RsltStream);
TmpStream.Clear;
RsltStream.Clear;
end else
begin
TmpStream.Clear;ReqCode:='show';
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;
end;
end.