Solved

Remote screen monitoring

Posted on 1998-11-16
12
204 Views
Last Modified: 2010-04-04
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/
0
Comment
Question by:brentlin
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1347075
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.
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1347076
You might check Ben Zieglers homepage, there is a Remote Control program written in Delphi with full source..
http://www.radix.net/~bziegler/Delphi/
0
 

Author Comment

by:brentlin
ID: 1347077
Thanks for the input. Ill check out Ben's page and let you know.
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 1

Expert Comment

by:zac
ID: 1347078
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

0
 

Author Comment

by:brentlin
ID: 1347079
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.

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1347080
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...
0
 

Author Comment

by:brentlin
ID: 1347081
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.
0
 
LVL 1

Accepted Solution

by:
zac earned 200 total points
ID: 1347082
Brentlin,

Well I'll answer the question again then if you rejected it by mistake... :-)

By the way the BPP should be bits per pixel not bytes! :-)

In answer to your question:

>Server: [row 0 of bitmap]<cr><lf>
>  .
>Server: [Final row of bitmap]<cr><lf>

These lines represent the raw data of the bitmap image.  For instance assume that BPP is 8 (ie 0ne byte per pixel).

For instance the data could look like this (as ASCII)..

AAABBB<cr><lf>


Which would represent decimal pixel values of 65,65,65,66,66,66

The simplest way to send that data would be thus

const
  crlf = #10#13

for nCount := 0 to smallBmp.Height-1 do
begin
  mySocket.Send(smallBmp.ScanLine[nCount], smallBmp.Width);
  mySocket.SendStr(crlf);
  Application.ProcessMessages;
end;


The send command sends a raw stream of data (in this case the raw DIB data) and the SendStr send the <cr><lf> command termination characters.

I call application.processmessages as all winsock communication is performed using windows messages - we need to give it a chance!  In the long run you may want to wait longer between sending subsequent rows of the image as before the data is sent, it is just stored in a buffer, and hence taking up loads of ram....

What you could do is use the OnDataSent event to set a flag that is checked by a wait function that simply calls application.processmessages until the flag is cleared - hence it would wait until one row of data is fully sent before attempting to send the next row.

Whether you use the above technique or not depends on the focus of your application, ie speed of transmission, user responsiveness etc etc...

I hope this answers your question.

Good luck,


Zac

0
 
LVL 1

Expert Comment

by:zac
ID: 1347083
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
0
 

Author Comment

by:brentlin
ID: 1347084
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
0
 
LVL 1

Expert Comment

by:zac
ID: 1347085
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
0
 

Author Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

832 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