Hallo alle Zusammen,
Ich erstelle mir mit folgender Funktion einen Screenshot von einer 3D Anwendung:
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
Public Sub Snapshot(oForm As Form, objPicture As PictureBox, _
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
With objPicture
.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
.Refresh
'DC wieder freigeben
ReleaseDC hwnd, nDC
End With
End Sub Diese Funktion Funktioniert auch wunderbar wenn ich diese im Entwicklungsmodus aufrufe ... die größe etc wird alles angepasst.
Wenn ich jedoch jetzt meine Anwendung erstelle und diesen Code als Exe ausführe, wird die größe nicht richtig angepasst (Höhe ist meistens zuviel und Breite meistens viel zu wenig) oder manchmal wird der Screenshot fehlerhaft erstellt Ich kann mir einfach nicht erklären woran es liegt, da es im Entwicklungsmodus 1A Funktioniert. Hat jmd vll. einen Tipp?
Per Simulierten Tasten möchte ich den Screenshot jedoch nicht erstellen  |