Nachfolgende Funktion erstellt ein Screenshot eines festlegbaren Bildschirmausschnitts und speichert das Bild dann als Bitmap in die angegebene Datei. Option Explicit ' Benötigte API-Deklarationen Private 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 Private Declare Function GetDC Lib "user32" ( _ ByVal hWnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" ( _ ByVal hWnd As Long, _ ByVal hdc As Long) As Long Private Declare Function GetDesktopWindow Lib "user32" () As Long ' Screenshot eines bestimmten Bildschirmausschnitts erstellen ' und als Bitmap in einer Datei abspeichern Public Sub Snapshot(oForm As Form, ByVal sFile As String, _ Optional ByVal x As Variant, _ Optional ByVal y As Variant, _ Optional ByVal nWidth As Variant, _ Optional ByVal nHeight As Variant) Dim hWnd As Long Dim nDC As Long Dim oPicBox As Control ' Handle des Windows-Desktop hWnd = GetDesktopWindow() ' Zugang zum Device-Context nDC = GetDC(hWnd) ' Position und Größe des Bildschirmausschnitts If IsMissing(x) Then x = 0 If IsMissing(y) Then y = 0 If IsMissing(nWidth) Then nWidth = Screen.Width / Screen.TwipsPerPixelX If IsMissing(nHeight) Then nHeight = Screen.Height / Screen.TwipsPerPixelY ' temporäre PictureBox erstellen Set oPicBox = oForm.Controls.Add("VB.PictureBox", "myPicTemp") With oPicBox .ScaleMode = vbPixels .Width = oForm.ScaleX(nWidth, vbPixels, oForm.ScaleMode) .Height = oForm.ScaleY(nHeight, vbPixels, oForm.ScaleMode) ' Snapshot in PictureBox blitten .AutoRedraw = True BitBlt .hDC, 0, 0, nWidth, nHeight, nDC, x, y, vbSrcCopy ' Bild abspeichern SavePicture .Image, sFile ' DC wieder freigeben ReleaseDC hWnd, nDC End With ' Control wieder entfernen oForm.Controls.Remove "myPicTemp" End Sub Achtung! Die Angabe der Position und Größe des Bildschirmausschnitts erfolgt in Pixel! Beispiele für den Aufruf: ' gesamten Bildschirmbereich speichern Snapshot Me, "d:\bild.bmp" ' Bildschirmausschnitt 100,100 - 500,500 speichern Snapshot Me, "d:\bild.bmp", 100, 100, 400, 400 Dieser Tipp wurde bereits 25.777 mal aufgerufen.
Anzeige
![]() ![]() ![]() (einschl. Beispielprojekt!) Ein absolutes Muss - Geballtes Wissen aus mehr als 8 Jahren vb@rchiv! - nahezu alle Tipps & Tricks und Workshops mit Beispielprojekten - Symbol-Galerie mit mehr als 3.200 Icons im modernen Look Weitere Infos - 4 Entwickler-Vollversionen (u.a. sevFTP für .NET), Online-Update-Funktion u.v.m. |
sevZIP40 Pro DLL ![]() Zippen und Unzippen wie die Profis! Mit nur wenigen Zeilen Code statten Sie Ihre Anwendungen ab sofort mit schnellen Zip- und Unzip-Funktionen aus. Hierbei lassen sich entweder einzelnen Dateien oder auch gesamte Ordner zippen bzw. entpacken. Tipp des Monats TOP Entwickler-Paket ![]() TOP-Preis!! Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1866.50 EUR... |
||||||||||||||||
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein. |