Hi,
'Benötigte API-Deklarationen für MakeScreenshot()
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
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 GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect _
As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect _
As RECT) As Long
Public Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Public Sub MakeScreenshot(ByVal bActiveWindow As Boolean, picBox As PictureBox)
Dim hWnd As Long
Dim SnapClientArea As Long
Dim hdc As Long, R As RECT
Dim DiffX As Long, DiffY As Long
'Hotkeys entladen
Unload frmEndHotkey
'Markiertes Fenster oder Ganzer Bildschirm?
If bActiveWindow Then
'Markiertes Fenster
hWnd = GetForegroundWindow
SnapClientArea = False
Else
'Ganzer Bildschirm
hWnd = GetDesktopWindow
SnapClientArea = True
End If
If SnapClientArea Then
'DC für den Client-Bereich
hdc = GetDC(hWnd)
'Größe des Client-Bereiches komfortabel ermitteln
GetClientRect hWnd, R
Else
hdc = GetWindowDC(hWnd)
'Größe und Position ermitteln
GetWindowRect hWnd, R
'Werte umrechnen in relative
R.Right = R.Right - R.Left
R.Bottom = R.Bottom - R.Top
R.Left = 0
R.Top = 0
End If
'Autosize
On Error Resume Next
DiffX = picBox.Width - picBox.ScaleX(picBox.ScaleWidth, picBox.ScaleMode, _
picBox.Parent.ScaleMode)
DiffY = picBox.Height - picBox.ScaleY(picBox.ScaleHeight, picBox.ScaleMode, _
picBox.Parent.ScaleMode)
If Err Then
Err.Clear
DiffX = picBox.Width - picBox.ScaleX(picBox.ScaleWidth, _
picBox.ScaleMode, vbTwips)
DiffY = picBox.Height - picBox.ScaleY(picBox.ScaleHeight, _
picBox.ScaleMode, vbTwips)
picBox.Width = DiffX + picBox.ScaleX(R.Right, vbPixels, vbTwips)
picBox.Height = DiffY + picBox.ScaleY(R.Bottom, vbPixels, vbTwips)
Else
picBox.Width = DiffX + picBox.ScaleX(R.Right, vbPixels, _
picBox.Parent.ScaleMode)
picBox.Height = DiffY + picBox.ScaleY(R.Bottom, vbPixels, _
picBox.Parent.ScaleMode)
End If
On Error GoTo 0
BitBlt picBox.hdc, 0, 0, R.Right, R.Bottom, hdc, 0, 0, vbSrcCopy
End Sub Mit dieser Prozedur erstelle ich einen Screenshot, ohne ihn in die Zwischenablage zu legen. Ich habe viele andere verschiedene Tipps probiert, aber diese hat sich jetzt bewährt. Das einzig dumme daran ist, dass dies anscheinend unter Windows NT 4 nicht funktioniert. Es erscheint immer folgende Fehlermeldung:
--------------------------
Laufzeitfehler '453':
DLL-Einsprungspunkt CreateToolhelp32Snapshot in Kernel32 nicht gefunden
--------------------------
Das liegt wahrscheinlich daran, dass eine/einige der benötigten API-Deklarationen (siehe oben im Code) nicht bei diesen NT-System vorhanden sind, oder? Welche? Gibt es einen gleichwertigen Ersatz, der bei allen Windows-Systemen funktioniert?
Vielen Dank im Voraus,
Levis |