Link to home
Start Free TrialLog in
Avatar of brentlin
brentlin

asked on

Remote screen monitoring

Basically I want to write a program that can establish a
PC to PC network connection and transmit screen dumps
between one another for remote viewing.

I found the folling code (thanks to Craig Francisco)which, dumps a screen image to a form's canvas.

procedure TScrnFrm.GrabScreen;
 var
    DeskTopDC: HDc;
    DeskTopCanvas: TCanvas;
    DeskTopRect: TRect;
 begin
     DeskTopDC := GetWindowDC(GetDeskTopWindow);
     DeskTopCanvas := TCanvas.Create;
     DeskTopCanvas.Handle := DeskTopDC;
     DeskTopRect := Rect(0,0,Screen.Width,Screen.Height);
     ScrnForm.Canvas.CopyRect(DeskTopRect,
                              DeskTopCanvas,DeskTopRect);
     ReleaseDC(GetDeskTopWindow,DeskTopDC);
  end;

i know it works (though id like to have the ability to somehow scale the canvas down to a more easily viewable area)

anyways I can establish some basic communications between the apps thanks to François PIETTE's networking components,
but im just not sure how to go about tieing it all together.

any help would be much appreciated.
Mike

  brentlin@purdue.edu
  http://expert.cc.purdue.edu/~brentlin/
Avatar of Stuart_Johnson
Stuart_Johnson

Using Francois' WSocket control you can send a stream of data across a network using UDP.  I have seen an application which was writen in Delphi using his controls and it worked beautifully.  However, I am stil to work out how.  I will keep you posted, because this is one of my assigned tasks at work.

Good luck working it out,


Stuart.
You might check Ben Zieglers homepage, there is a Remote Control program written in Delphi with full source..
http://www.radix.net/~bziegler/Delphi/
Avatar of brentlin

ASKER

Thanks for the input. Ill check out Ben's page and let you know.
Brentlin,

I will give you the outline of the solution if you require further details on any particular points, then please let me know.

Firstly the scaling of the Bitmap can be accomplished by copying the Screen to a bitmap ie (from your example):

myBmp.Canvas.CopyRect(DeskTopRect, DeskTopCanvas,DeskTopRect);

Then you can perform a scale operation ie:

smallBmp.Canvas.stretchDraw(smallRect, myBmp);

This will then plot the full size image onto a smaller bitmap (that you have created already) the new size of the image will be specified by smallRect.  After this you can then free up myBmp.

The next stage is to transmit the data across the network.

Stuart mentions using UDP - I would suggest that it depends on the time you have to get the application working.  If time (and boredom) is not a factor then use UDP, it will be faster.  However with UDP you have to do all the error checking, delivery checking and almost everything else yourself.  Also remember that UDP packets can arrive in any order.  So you have to decide whether having to write code to support all of that is worth the performance enhancement it will bring.  The decision will also depend on whether you want to use this over a LAN or the internet etc.  The other solution is based upon TCP which provides error checking and guaranteed delivery as standard.

I will focus on a TCP implementation as a full UDP solution is probably beyond the scope of a single page......

I will also not provide any security features in this protocol.

I assume that you understand the basics of TCP sockets.  In this case one application will have a server socket (ie in "listen" mode) and one will have a standard socket.  The listener is in essence a server - for further examples of how to set up a server see François PIETTE's ICS demos.

Now we have to define a protocol for this I will assume that the machine that has an image to send is the server (listener).

In the protocol commands and data are delimited with cr/lf pairs.

Your client / remote viewer connects to the server on a predefined port (this number will form the part of your protocol).

After the client is connected you could perform some security, however in this case I will move straight on to the proposed commands:

I have outlined this below as a series of exchanges.

Client: GET SCREEN<cr><lf>
Server: BPP [Bytes per pixel (integer)]<cr><lf>  <- This is bytes per pixel
Server: HEIGHT [bitmap height (pixels)]<cr><lf>
Server: WIDTH [bitmap width (pixels)]<cr><lf>
Server: DATA<cr><lf>
Server: [row 0 of bitmap]<cr><lf>
  .
  .
  .
Server: [Final row of bitmap]<cr><lf>

Server Disconnects.

This is just an example of the protocol you could use - it depends on how often you want to send the data etc as to how the protocol would be formed.

The row data from the bitmap can be accessed by using:

smallBmp.ScanLine[0]

Which returns a pointer to the data - otherwise if speed isn't so important you can use the pixels property of TBitmap.

The important thing to remember is that there is nothing mystical about TCP - its just text - so define a "language" and as long as both client and server understand the same "language" you are fine.

Obviously you may want to specify a version number at the top of the protocol, and allow the server to return error codes.

I hope this has given you enough information to get you started, if you require some more info on specific areas, leave me a comment and I will dicuss it in detail.

Good luck

Zac

Blackman,
I went out and grabbed Ben Zieglers remote control app (which from reading his discription sounds like exactly what i want) but
when trying to load it the thing bombed out. i grabbed all of his
librarys that he said were needed though they gave me troubles
when installing the components (im using c/s V3 maybe thats killing me somehow.), once they were installed they repeatedly crashed delphi. any ideas?

ZAC,
From your explaination TCP does seem to be the way to go. As of now im not concerned w/ security, so thats no problem.

From your outline of the c/s communications the theory seems simple and makes sense, however im still sketchy over this part:

>Server: [row 0 of bitmap]<cr><lf>
>  .
>Server: [Final row of bitmap]<cr><lf>
>
>The row data from the bitmap can be accessed by using:
>
>smallBmp.ScanLine[0]
>
>Which returns a pointer to the data - otherwise if speed isn't >so important you can use the pixels property of TBitmap.

i guess im trying to say i dont understand the manner in which
the image is scanned line by line and in what form or using what proedure it is to be transmitted to the client.

i will do some experimentation and see what i can pull off. a little more help would be greatly appreciated though.
thanks.

You could try to email Ben, I have never tried the Remote Control thing, only his web-stuff, and he was very responsive and helpfull when I emailed him...
Blackman,
Ill give that a try then thanks

ZAC,
I think i rejected your answer when i ment to just add a comment hoping you would add some more info. I hope I didnt somehow make you unable to get points by doing so.
ASKER CERTIFIED SOLUTION
Avatar of zac
zac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Brentlin,  

If you have any further questions, just let me know.

By the way have you got it working?  - I'm just interested... :-)

Good luck


Zac
Zac,
I got the resizing of the desktop to a bitmap working after fighting it a bit (I didnt know you had to specify the size of the bitmap when you create it during runtime) but i did get it and it works pretty sweetly. Thanks again.

As for the transmission, I think I understand it fairly well, it seems pretty simple (I just didnt think of the image as transmittable in a text format). I should be able to get that working, the only trouble i may have is recreating the image on the recieve side (I assume there's some type of command like scanline that draws) Ill need to look around in delphi's help. Any clues as to where to start?

My only real problem is finding time to do it. College is a big killer of most of my free time :-)

Thanks again...
brentlin
Brentlin,

I'm glad you got the bitmap working....

To recreate the bitmap at the other end you can use the scanline property (providing you've already created a bitmap and given it the correct size and colour depth etc.)

Remeber scanline is just a pointer to some data, so all you have to do is just dereference the pointer and stream you recieved data in.

Good luck

Zac
Zac,
Ok. Ill give it a try and see what I come up with.
Thanks for the tip.
-brentlin