如何获取当前的屏幕信息并传送到远程的计算机上显示?(200分)

  • 主题发起人 主题发起人 夏敏
  • 开始时间 开始时间

夏敏

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在想监控远端的学生机,想获取远端的学生机当前的屏幕信息在教师机上显示,是否可以通过API和winsock实现?
 
http://www.delphiok.com/bcjq/all/115.htm
里面有个用流操作的例子。
 
将远程屏幕转化成流文件,通过WINSOCKET发送,接收到后在转换成JPG文件,再转化成BMP文件。以下是具体代码:
服务器端:
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, jpeg, StdCtrls;

type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
Memo1: TMemo;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
m1: TMemoryStream;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
try
ServerSocket1.Close;
ServerSocket1.Port := StrToInt(edit1.Text);
ServerSocket1.Active := true;
memo1.Clear;
finally
end;
end;

procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode := 0;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
s,s1: String;
bitmap: TBitmap;
jpg: TJpegImage;
desk: TCanvas;
memos: string;
begin
s := socket.ReceiveText;

if s = 'gets' then
begin
memos := s;
memo1.Lines.Add(memos);
bitmap := TBitmap.Create;
jpg := TJpegImage.Create;
desk := TCanvas.Create;
desk.Handle := getdc(hwnd_desktop);
m1 := TmemoryStream.Create;
with bitmap do
begin
width := screen.Width;
height := screen.Height;
bitmap.Canvas.CopyRect(canvas.ClipRect,desk,desk.ClipRect);
end;
jpg.Assign(bitmap);
jpg.SaveToStream(m1);
jpg.Free;
m1.Position := 0;
s1 := intTostr(m1.Size);
socket.SendText(s1);
end;

if s = 'okok' then
begin
memo1.Lines.Add(s);
m1.Position := 0;
socket.SendStream(m1);
end;
end;

end.
客户端:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, ExtCtrls, jpeg;

type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Image1: TImage;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
Edit2: TEdit;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
c: LongInt;
m: TMemoryStream;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if ClientSocket1.Socket.Connected then
ClientSocket1.Socket.SendText('gets');
image1.Refresh;
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode := 0;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
buffer: array[0..10000] of byte;
len: Integer;
l1: String;
b: TBitmap;
j: TJpegImage;
begin
if c = 0 then
begin
l1 := socket.ReceiveText;
c := strToInt(l1);
socket.SendText('okok');
end else
begin
Len := socket.ReceiveLength;
socket.ReceiveBuf(buffer,len);
m.WriteBuffer(buffer,len);
if m.Size >= c then
begin
m.Position := 0;
b := TBitmap.Create;
j := TJpegImage.Create;
try
j.LoadFromStream(m);
b.Assign(j);
image1.Picture.Bitmap.Assign(b);
finally
b.Free;
j.Free;
// ClientSocket1.Active := false;
m.Clear;
c := 0;
end;
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
m := TmemoryStream.Create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
m.Free;
ClientSocket1.Close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
clientsocket1.Close;
ClientSocket1.Address := edit1.Text;
ClientSocket1.Port := strToInt(edit2.Text);
ClientSOCket1.Active := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if ClientSocket1.Socket.Connected then
form1.Caption := 'ok'
else
form1.Caption := 'false';
end;

end.
轻松搞定!
 
请问高手,
我用TNMUDP控件写了一相C/S的程序在局域网测试,发送的数据大于254就出现非法操作!
(我发送的全是字符。。。),是该控件不支持大于此数值吗?
我可以如何解决此问题!谢谢!
 
先定义发送的缓冲区。
 
用不着这么麻烦,用冰河就行了
 
我以前远程监控程序,有类似的功能,取得客户端的屏幕,支持远程鼠标操作,就像本地操作一样,但速度方面不是特别好,http://homeofkch.bak.cn有源码.
 
后退
顶部