Cathing the Mouse in a Screen Capture in Vb.Net

G

gregory_may

http://www.geocities.com/krishnapg/screencap.html

This article gives a pretty good background on various ways to capture the
screen. I have some code to do it the GDI way below, but I cant figure out
how to get the Mouse in there. I am frustrated and looking at Direct X. I
am may have to try the Windows Media API , but know nothing about it.

Anyone have a way to get the mouse in my screen capture, any examples would
be great (GDI, DirectX, or Windows Media API)?



Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal
lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As
String, ByVal lpInitData As String) As Integer

Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As
Integer) As Integer

Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer

Private Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer

Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer,
ByVal hObject As Integer) As Integer

Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal
srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As
Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As
Integer, ByVal op As Integer) As Integer

Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As
Integer

Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As
Integer

Const SRCCOPY As Integer = &HCC0020

Private oBackground As System.Drawing.Bitmap

Private FW, FH As Integer



Public Sub CaptureScreen()

Dim hSDC, hMDC As Integer

Dim hBMP, hBMPOld As Integer

Dim r As Integer



hSDC = CreateDC("DISPLAY", "", "", "")

hMDC = CreateCompatibleDC(hSDC)

FW = GetDeviceCaps(hSDC, 8)

FH = GetDeviceCaps(hSDC, 10)

hBMP = CreateCompatibleBitmap(hSDC, FW, FH)

hBMPOld = SelectObject(hMDC, hBMP)

r = BitBlt(hMDC, 0, 0, FW, FH, hSDC, 0, 0, 13369376)

hBMP = SelectObject(hMDC, hBMPOld)

r = DeleteDC(hSDC)

r = DeleteDC(hMDC)

oBackground = System.Drawing.Image.FromHbitmap(New IntPtr(hBMP))

DeleteObject(hBMP)

DeleteObject(hBMPOld)
 
B

Bob

You may want to try sending the Alt-PrntScrn keystroke and copy from the
clipboard. I used to know how to do this in VB6 and I believe it can be done in
..Net as well.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top