|
Option Strict On
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class mrCapture
Private Class GDI32
<DllImport("GDI32.dll")> _
Public Shared Function BitBlt(ByVal hdcDest As Integer, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As Integer, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Integer) As Boolean
End Function
<DllImport("GDI32.dll")> _
Public Shared Function CreateCompatibleBitmap(ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
End Function
<DllImport("GDI32.dll")> _
Public Shared Function CreateCompatibleDC(ByVal hdc As Integer) As Integer
End Function
<DllImport("GDI32.dll")> _
Public Shared Function DeleteDC(ByVal hdc As Integer) As Boolean
End Function
<DllImport("GDI32.dll")> _
Public Shared Function DeleteObject(ByVal hObject As Integer) As Boolean
End Function
<DllImport("GDI32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hdc As Integer, ByVal nIndex As Integer) As Integer
End Function
<DllImport("GDI32.dll")> _
Public Shared Function SelectObject(ByVal hdc As Integer, ByVal hgdiobj As Integer) As Integer
End Function
End Class
Private Class User32
<DllImport("User32.dll")> _
Public Shared Function GetDesktopWindow() As Integer
End Function
<DllImport("User32.dll")> _
Public Shared Function GetWindowDC(ByVal hWnd As Integer) As Integer
End Function
<DllImport("User32.dll")> _
Public Shared Function ReleaseDC(ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
End Function
End Class
Public Sub CaptureScr(ByVal fileName As String, ByVal imageFormat As ImageFormat)
Dim hdcSrc As Integer = User32.GetWindowDC(User32.GetDesktopWindow()), hdcDest As Integer = GDI32.CreateCompatibleDC(hdcSrc), hBitmap As Integer = GDI32.CreateCompatibleBitmap(hdcSrc, GDI32.GetDeviceCaps(hdcSrc, 8), GDI32.GetDeviceCaps(hdcSrc, 10))
GDI32.SelectObject(hdcDest, hBitmap)
GDI32.BitBlt(hdcDest, 0, 0, GDI32.GetDeviceCaps(hdcSrc, 8), GDI32.GetDeviceCaps(hdcSrc, 10), hdcSrc, 0, 0, 13369376)
SaveImageAs(hBitmap, fileName, imageFormat)
Cleanup(hBitmap, hdcSrc, hdcDest)
End Sub
Private Sub Cleanup(ByVal hBitmap As Integer, ByVal hdcSrc As Integer, ByVal hdcDest As Integer)
User32.ReleaseDC(User32.GetDesktopWindow(), hdcSrc)
GDI32.DeleteDC(hdcDest)
GDI32.DeleteObject(hBitmap)
End Sub
Private Sub SaveImageAs(ByVal hBitmap As Integer, ByVal fileName As String, ByVal imageFormat As ImageFormat)
Dim iImage As New Bitmap(Image.FromHbitmap(New IntPtr(hBitmap)), Image.FromHbitmap(New IntPtr(hBitmap)).Width, Image.FromHbitmap(New IntPtr(hBitmap)).Height)
iImage.Save(fileName, imageFormat)
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.