Code-Beispiel
Screenshot erstellen und in ein Grafikimage packen
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | jakidomi | 05.11.2008 |
#include once "windows.bi"
#include once "file.bi"
Function CaptureWindow( ByVal hwndSrc As HWND) As Any Ptr
SetForegroundWindow(hWndSrc)
Sleep 30 'SetForegroundWindow etwas Zeit geben
Dim As RECT r
GetWindowRect(hWndSrc, @r) 'Fenstergroesse feststellen
Dim As Integer b = r.right - r.left
Dim As Integer h = r.bottom - r.top
Dim As Any Ptr img = ImageCreate(b, h)
b = (b+3) and -4 'Bildbreite glatt durch 4 teilbar
Dim As HDC hdcSrc = GetWindowDC(hWndSrc)
Dim As HDC hdcMem = CreateCompatibleDC(hdcSrc)
Dim As HBITMAP hBmp = CreateCompatibleBitmap(hdcSrc, b, h)
SelectObject(hdcMem, hBmp)
BitBlt(hdcMem, 0, 0, b, h, hdcSrc, 0, 0, SRCCOPY)
Dim As BITMAPINFO bmi
With bmi.bmiHeader
.biSize = SizeOf(BITMAPINFOHEADER)
.biWidth = b 'breite
.biHeight = -h '-hoehe (sonst Kopfstand)
.biPlanes = 1
.biCompression = BI_RGB
.biBitCount = 32
End With
If (img) Then 'Bilddaten in das Image kopieren
GetDIBits(hdcMem, hBmp, 0, h, img + 32, @bmi, DIB_RGB_COLORS)
End If
DeleteObject(hBmp)
DeleteDC(hdcMem)
ReleaseDC(hWndSrc, hdcSrc)
Return img
IMAGEDESTROY img
End Function
function screenshot (byval file as string="",byref im as any ptr) as integer
dim as HWND hw
hw=20
im=CaptureWindow(hw)
if not im=0 then
if not file="" then
bsave file,im,6400
if fileexists(file) then
return 1
else
return 0
endif
else
return 1
endif
else
return -1
endif
end function
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|