Screen capture?

B

Ben Dilts

Under VB6, it was fairly straightforward to get a
screenshot. For instance, the following code:

Public Function ScreenshotBits(hWnd As Long, Optional
compress As Boolean = True) As Byte()
Dim bitmap_info As BITMAPINFO
Dim pixels() As Byte
Dim Size As Long

Dim dc As Long
dc = GetDC(hWnd)

Dim memDC As Long
memDC = CreateCompatibleDC(dc)

Dim r As RECT
GetClientRect hWnd, r

' Prepare the bitmap description.
With bitmap_info.bmiHeader
.biSize = 40
.biWidth = r.Right - r.Left
' Use negative height to scan top-down.
.biHeight = r.Top - r.Bottom
.biPlanes = 1
.biBitCount = 32
.biCompression = BI_RGB
End With

Dim bm As Long
Dim ptr As Long
bm = CreateDIBSection(dc, bitmap_info, DIB_PAL_COLORS,
ptr, 0, 0)

Dim oldbm As Long
oldbm = SelectObject(memDC, bm)

BitBlt memDC, 0, 0, r.Right - r.Left, r.Bottom -
r.Top, dc, 0, 0, SRCCOPY

' Copy the bitmap's data.
Size = (r.Right - r.Left) * (r.Bottom - r.Top) * 4
ReDim pixels(0 To Size - 1)

GetDIBits dc, bm, 0, r.Bottom - r.Top, pixels(0),
bitmap_info, DIB_PAL_COLORS

If compress Then
Dim z As New clsZLib
z.CompressByte pixels
End If

SelectObject memDC, oldbm
DeleteObject memDC
DeleteObject bm
ScreenshotBits = pixels
End Function

How do I duplicate this functionality in VB.NET? That is,
I could import all the API calls and do almost the exact
same code, but the .NET framwork abstracts tons of things
that were previously the realm of API calls. Is there
a .NET way to do this?



~BenDilts( void );
 

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