Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

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
0
FCouples
Asked:
FCouples
1 Solution
 
Ryan ChongCommented:
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
 
tWiZtEr_RXCommented:
with mouse yo.
0
 
FCouplesAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
FCouplesAuthor Commented:
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
 
FCouplesAuthor Commented:
whoops accidentally hit refresh :S
0
 
zfiexpertCommented:
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
 
zfiexpertCommented:
<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
 
FCouplesAuthor Commented:
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
 
zfiexpertCommented:
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
 
FCouplesAuthor Commented:
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
 
zfiexpertCommented:
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
 
FCouplesAuthor Commented:
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
 
FCouplesAuthor Commented:
*it also isn't changing the mouse to white, it's transparent and i'm using the regular mouse from vb graphics
0
 
zfiexpertCommented:
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
 
FCouplesAuthor Commented:
Thanks that worked great :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now