Solved

Remote screen monitoring

Posted on 1998-11-16
12
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

632 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