unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, JPEG, StdCtrls;
type
TForm1 =
class(TForm)
IdTCPServer1: TIdTCPServer;
ConsoleMemo: TMemo;
Button1: TButton;
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
procedure IdTCPServer1Disconnect(AThread: TIdPeerThread);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ScreenShot(FileName:
string): Boolean;
var
fBitmap: TBitmap;
DC: HDC;
Rect: TRect;
AImage: TJPEGImage;
AHandle: THandle;
CompressPercent: Byte;
begin
AImage := TJPEGImage.Create;
AHandle := GetDesktopWindow;
CompressPercent := 100;
Result := False;
if AImage =
nil then Exit;
DC := GetDC(AHandle);
if DC <> 0
then
try
fBitmap := TBitmap.Create;
try
if not GetClientRect(AHandle, Rect)
then Exit;
fBitmap.Width := Rect.Right - Rect.Left;
fBitmap.Height := Rect.Bottom - Rect.Top;
fBitmap.PixelFormat := pf32bit;
Result := BitBlt(fBitmap.Canvas.Handle, 0, 0, fBitmap.Width,
fBitmap.Height,
DC, 0, 0, SRCCOPY);
if not Result
then Exit;
AImage.Assign(fBitmap);
AImage.CompressionQuality := CompressPercent;
finally
fBitmap.Free;
end;
finally
ReleaseDC(AHandle,
DC);
end;
If FileExists(FileName)
Then DeleteFile(FileName);
AImage.SaveToFile(FileName);
AImage.Destroy;
end;
function GetFileSize(
const FileName:
string): Int64;
var
FileStream: TFileStream;
begin
FileStream := TFileStream.Create(FileName, fmOpenRead
or fmShareDenyNone);
try
try
Result := FileStream.Size;
except
Result := 0;
end;
finally
FileStream.Free;
end;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Path:
String;
fStream: TFileStream;
tBM: tBitmap;
begin
Try
If Copy(UpperCase(AThread.Connection.ReadLn), 1, 3) = '
SRN'
then
begin
ConsoleMemo.Lines.Add('
~> Sending picture ...');
ScreenShot('
C:\test.jpg');
Path := '
C:\test.jpg';
AThread.Connection.WriteLn('
SIZE:' + inttostr(GetFileSize('
C:\test.jpg')));
fStream := TFileStream.Create(Path, fmOpenRead + fmShareDenyNone);
AThread.Connection.OpenWriteBuffer;
AThread.Connection.WriteStream(fStream);
AThread.Connection.CloseWriteBuffer;
FreeAndNil(fStream);
ConsoleMemo.Lines.Add('
~> Picture sended.');
//AThread.Connection.Disconnect;
end;
Except
on E :
Exception do
ShowMessage(E.
Message);
end;
end;
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
ConsoleMemo.Lines.Add('
+> New connection ...');
end;
procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
ConsoleMemo.Lines.Add('
-> Connection lost!');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPServer1.Active := TRue;
end;
end.