?
Solved

VB Capturing Screen with Mouse and sending over Winsock

Posted on 2003-03-04
15
Medium Priority
?
381 Views
Last Modified: 2013-11-13
Hi!

I'm trying to create a program in which will capture the screen *with* the mouse, and then send it over winsock from host to client.  I know the basics of winsock, how to connect/listen, etc.  This could be done straight from the clipboard or be saved to a file.

Thanks in advance to your responses!

-Jeff
0
Comment
Question by:FCouples
[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
15 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8069773
Example:

Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
 ByVal bScan As Byte, _
 ByVal dwFlags As Long, _
 ByVal dwExtraInfo As Long)

keybd_event vbKeySnapshot, 1, 0&, 0&

Picture1.Cls
Picture1.Picture = Clipboard.GetData(vbCFBitmap)

tmp = "c:\abc.bmp"
SavePicture Picture1.Picture, tmp
0
 

Expert Comment

by:tWiZtEr_RX
ID: 8069863
with mouse yo.
0
 
LVL 1

Author Comment

by:FCouples
ID: 8069864
Thanks for your quick response!

I tried that, and yes it did capture the screen, but I want the mouse pointer to be included and make winsock send it from client to host, not quite sure how to do that either.  Thank you very much for a response!

- Jeff
0
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!

 
LVL 1

Author Comment

by:FCouples
ID: 8069894
Thanks for your quick response!

I tried that, and yes it did capture the screen, but I want the mouse pointer to be included and make winsock send it from client to host, not quite sure how to do that either.  Thank you very much for a response!

- Jeff
0
 
LVL 1

Author Comment

by:FCouples
ID: 8069895
whoops accidentally hit refresh :S
0
 

Expert Comment

by:zfiexpert
ID: 8076311
I can only assume you intend to be able to remotely see the desktop of another computer so you will want it to be quick. Here is an API way of doing it.

(Before you start, if you have never used BitBlt before, bear with the confusion at first. It is an immensly useful tool for all graphics applications.

In a module declare the following:

Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Global Const SRCCOPY = &HCC7000

Dim DeskhWnd As Long, DeskDC As Long

In your Form.Load sub routine:

DeskhWnd = GetDesktopWindow()
DeskDC = GetDC(DeskhWnd)

Do
Call BitBlt(PicBox.Hdc, 0, 0, Screen.Width, Screen.Height, DeskDC, 0, 0, SRCCOPY)
PicBox.Refresh
Call SavePicture(PicBox.Image, "c:\tester.bmp")
Doevents
Loop

Now create a Picturebox called PicBox (for simplicity). Change it properties to:

AutoRedraw=True
Visible=False
AutoSize=True
ScaleMode=Pixel

The DO LOOP routine in your Form.Load Sub is constantly updating the screen to the PicBox. Unfortunatly sending an image of desktop size would take a while. I would suggest running the sending computer in 640x480 resolution.

Simplify.

-Shane
ZFi Enterprises


0
 

Expert Comment

by:zfiexpert
ID: 8076383
<Adding the mouse pointer>

Make another PictureBox called MousePic and give it the same properties as PicBox.

Give MousePic a pointer graphic from the VB graphics files. If you cant find one then make one in paintbrush (size does not matter as long as the pointy part of the pointer is at 0,0 or close). Make sure the background for the pointer is white. Don't worry about color, its going to turn out all black.

Now comes the tricky part, and I hope I am giving you proper instructions.

Add to the module:

Global Const SRCAND = &H8800C6
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Type POINTAPI
     X As Long
     Y As Long
End Type

Add to your Form declarations:

Dim Mouse As POINTAPI

Now insert this line right after the Call BitBlt.... command.

Call BitBlt(PicBox.Hdc, Mouse.X, Mouse.Y, MousePic.ScaleWidth, MousePic.ScaleHeight, MousePic.Hdc, 0, 0, SRCAND)

I know its complicated, but its one of the only ways to get that mouse to look right. I'll bet theres a special SHOWMOUSE command or something, but this is what I know and what i've used for similar projects.
The WinSock commands and such are not something that I have looked into yet, but I'm sure theres another expert with an easy way to send a file across the phone line.

Good Luck to you.

Simplify.

-Shane
ZFi Enterprises
0
 
LVL 1

Author Comment

by:FCouples
ID: 8076415
Yes you are right in that I am trying to remotely see the desktop from a different computer.  That does take a snap shot of the screen, but it doesn't include the mouse and how to send it through winsock.

Thanks for the suggestion though

-Jeff
0
 

Expert Comment

by:zfiexpert
ID: 8076418
When I said "don't worry about the color" I meant don't worry about the mouse pointer color. The background on the picturebox itself should be changed to white.

Also - Change the borderstyle on both pictureboxes to 0 - None.
0
 
LVL 1

Author Comment

by:FCouples
ID: 8076434
whoops didn't refresh in time, i'll take a look at adding the mouse 1 sec, but i still need to know how to transfer it through winsock
0
 

Expert Comment

by:zfiexpert
ID: 8076436
http://www.developer.com/net/vb/article.php/10926_1540141_7

Heres a link to something I found. I havent gone through it, but the cover looked hopeful.
0
 
LVL 1

Author Comment

by:FCouples
ID: 8076516
still not it, but definatelly closer.

An outline of the mouse is appearing in the picture, but it just sits in the corner.  I have uploaded the output of the code you gave me here.  I changed it to jpg format for file size matters:

http://home.attbi.com/~jeffdbrown/tester.jpg

I also added:

PicBox.Height = Screen.Height
PicBox.Width = Screen.Width

Just to make it the right height/width, it wasn't resizing correctly.

Thanks!

-Jeff
0
 
LVL 1

Author Comment

by:FCouples
ID: 8076535
*it also isn't changing the mouse to white, it's transparent and i'm using the regular mouse from vb graphics
0
 

Accepted Solution

by:
zfiexpert earned 200 total points
ID: 8079086
Lets see,

I forgot  a very important part of this. (What I need to do is create the code in VB first. Jeeze.)

Put this in the DO LOOP:

Call GetCursorPos(Mouse)

That will call mouse X, Y coordinates to the Mouse Type that we made. To get that mouse cursor to appear just get an all black mouse picture. If the mouse pointer is black and the background is white it should appear black.

Unfortunatly this will show the regular mouse over all controls including text, wait, and drag modes. There will be no text cursor or hourglass cursor. To do this you would have to find another API that gives you the current status of the cursor type. Then we would have to change the BitBlt to display it. I will look into it a little.

0
 
LVL 1

Author Comment

by:FCouples
ID: 8945557
Thanks that worked great :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

770 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