Link to home
Start Free TrialLog in
Avatar of FCouples
FCouples

asked on

VB Capturing Screen with Mouse and sending over Winsock

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
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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
Avatar of tWiZtEr_RX
tWiZtEr_RX

with mouse yo.
Avatar of FCouples

ASKER

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
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
whoops accidentally hit refresh :S
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


<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
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
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.
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
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.
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
*it also isn't changing the mouse to white, it's transparent and i'm using the regular mouse from vb graphics
ASKER CERTIFIED SOLUTION
Avatar of zfiexpert
zfiexpert

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
Thanks that worked great :)