Solved

Remote Screen

Posted on 2003-10-26
9
302 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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