Solved

Remote Screen

Posted on 2003-10-26
9
299 Views
Last Modified: 2010-04-05
Hello, I need a client and server program where you can see the desktop of where the server is running.
I need an example.

Thx Karamja

{ Note: I will give upto 735 points but dew to limit I can only put 500, I will give you the rest of the points in a diff question }
0
Comment
Question by:Karamja
  • 4
  • 3
  • 2
9 Comments
 
LVL 2

Accepted Solution

by:
alsantos earned 500 total points
ID: 9622742
Hi Karamja, I think you can try this code and the file will be saved at c:\test.jpg

unit Unit1;

interface

uses
  Windows, Jpeg, Forms, Graphics, IdTCPServer, SysUtils, IdComponent,
  IdTCPConnection, IdTCPClient, IdBaseComponent, StdCtrls,
  Classes, Controls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    IdClient: TIdTCPClient;
    IdTCPServer1: TIdTCPServer;
    procedure Button1Click(Sender: TObject);
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function CaptureScreen: TJPEGImage;
var
  DC : HDC;
  ABitmap:TBitmap;
  Jpg: TJPEGImage;
begin
  DC := GetDC (GetDesktopWindow);
  ABitmap:=TBitmap.Create;
  try
    ABitmap.Width  := GetDeviceCaps (DC, HORZRES);
    ABitmap.Height := GetDeviceCaps (DC, VERTRES);
    BitBlt(ABitmap.Canvas.Handle, 0, 0, ABitmap.Width,
           ABitmap.Height,DC, 0, 0, SRCCOPY);
    Jpg := TJPEGImage.Create;
    with Jpg do
    begin
      PixelFormat := jf24Bit;
      Assign(ABitmap);
      Compress;
    end;
    Result := Jpg;
  finally
    ABitmap.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  msSend: TMemoryStream;
  Jpeg: TJPEGImage;
begin
  idClient.Port:=9090;
  idClient.Host:='127.0.0.1';
  idTCpServer1.DefaultPort:=9090;
  idTcpServer1.Active:=True;
  idClient.Connect;
  Jpeg := CaptureScreen;
  msSend := TMemoryStream.Create;
  Jpeg.SaveToStream(msSend);
  if idClient.Connected then
  begin
    idClient.WriteLn(IntToStr(msSend.Size));
    idClient.WriteStream(msSend);
  end;
  msSend.Free;
  idClient.Disconnect;
end;


procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  mS: TMemoryStream;
  S: String;
begin
  with AThread.Connection do
  begin
    S := ReadLn;
    mS := TMemoryStream.Create;
    try
      ReadStream(mS, StrToInt(S));
      mS.SaveToFile('c:\test.jpg');
    finally
      mS.Free;
    end;
  end;
end;

end.

alsantos
0
 

Author Comment

by:Karamja
ID: 9622883
Hello, Can you upload this project for me to download
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9622963
0
 

Author Comment

by:Karamja
ID: 9622979
That url dont work? lol, Could you e-mail it to webmaster@express-hosting.co.uk
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Karamja
ID: 9623076
Thx, Sorry about the uploading and e-mail stuff
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9623085
Thanks too. :)

alsantos
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9623294
hmm, there is a memory-leak i guess
-> the result of the captureScreen-function is never freed
0
 
LVL 2

Expert Comment

by:alsantos
ID: 9623314
Yes.... sorry... put "Jpeg.Free;" after the savetostream

procedure TForm1.Button1Click(Sender: TObject);
var
  msSend: TMemoryStream;
  Jpeg: TJPEGImage;
begin
  idClient.Port:=9090;
  idClient.Host:='127.0.0.1';
  idTCpServer1.DefaultPort:=9090;
  idTcpServer1.Active:=True;
  idClient.Connect;
  Jpeg := CaptureScreen;
  msSend := TMemoryStream.Create;
  Jpeg.SaveToStream(msSend); // jpeg.free after the savetostream
  Jpeg.Free; // here
  if idClient.Connected then
  begin
    idClient.WriteLn(IntToStr(msSend.Size));
    idClient.WriteStream(msSend);
  end;
  msSend.Free;
  idClient.Disconnect;
end;

:)

alsantos
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9623322
Yep, better :-))
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now