Solved

Remote Screen

Posted on 2003-10-26
9
303 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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