Mit Hilfe dieser Klasse können Screenshots erstellt werden.
folgende Möglichkeiten bestehen:
- vollständiger Desktop
- aktives Fenster
- benutzerdefinierter Bereich
- anhand des Handels des Fensters
benötigte Namespaces:
System
System.Runtime.InteropServices
System.Drawing
System.Windows.Forms
''' <summary>
''' Klasse zum erzeugen beliebiger Screenshots
''' </summary>
Public Class Screenshot
Public Sub New()
End Sub
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
<DllImport("user32.dll")> _
Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As _
RECT) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function GetForegroundWindow() As Integer
End Function
''' <summary>
''' Erzeugt ein Screenshot vom gesamten Desktop.
''' </summary>
''' <returns>Bitmap</returns>
Public Function WholeDesktop() As Bitmap
Return CreateScreenshot(0, 0, Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height)
End Function
''' <summary>
''' Erzeugt ein Screenshot vom übergebenen Bereich.
''' </summary>
''' <param name="topleft">Punkt des Bereich oben - links</param>
''' <param name="bottomRight">Punkt des Bereich unten - rechts</param>
''' <returns>Bitmap</returns>
Public Function UserDefined(ByVal topleft As Point, ByVal bottomRight As _
Point) As Bitmap
Return CreateScreenshot(topleft.X, topleft.Y, bottomRight.X, _
bottomRight.Y)
End Function
''' <summary>
''' Erzeugt ein Screenshot vom Fenster des übergebenen Handels
''' </summary>
''' <param name="windowhandle"></param>
''' <returns>Bitmap</returns>
Public Function UserDefinedWindowHandle(ByVal windowhandle As IntPtr) As _
Bitmap
Return CreateScreenshot(windowhandle)
End Function
''' <summary>
''' Erzeugt ein Screenshot vom aktiven Fenster.
''' </summary>
''' <returns>Bitmap</returns>
Public Function ActiveWindow() As Bitmap
Return CreateScreenshot(DirectCast(GetForegroundWindow(), _
System.IntPtr))
End Function
Private Function CreateScreenshot(ByVal left As Integer, ByVal top As _
Integer, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim bmp As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(left, top, 0, 0, New Size(width, height))
g.Dispose()
Return bmp
End Function
Private Function CreateScreenshot(ByVal windowhandle As IntPtr) As Bitmap
Dim windowRectangle As RECT
GetWindowRect(windowhandle, windowRectangle)
Return CreateScreenshot(windowRectangle.Left, windowRectangle.Top, _
windowRectangle.Right - windowRectangle.Left, windowRectangle.Bottom - _
windowRectangle.Top)
End Function
End Class Gruss
VIVAX
}
}
}
1:0 für Visual Basic.NET
|