'api functions from LB Workshop
'Alyce Watson, August 25, 2004
'feel free to use in your own programs
'please do not republish this demo
filedialog "Save Screenshot As","*.bmp",bmpfile$
if bmpfile$="" then end
print "Saving screenshot as ";bmpfile$
bmpfile$=lower$(bmpfile$)
'add bmp extension if necessary:
if right$(bmpfile$,4)<>".bmp" then bmpfile$=bmpfile$+".bmp"
hscreen=GetDC(0)
print "hscreen is ";hscreen
hmem=CreateCompatibleDC(hscreen)
print "hmem is ";hmem
hbitmap=CreateCompatibleBitmap(hscreen,DisplayWidth,DisplayHeight)
oldobject=SelectObject(hmem,hbitmap)
print "hbitmap is ";hbitmap
call BitBlt hmem,0,0,DisplayWidth,DisplayHeight,hscreen,0,0
call ReleaseDC 0,hscreen
call DeleteDC hmem
loadbmp "demo",hbitmap
bmpsave "demo",bmpfile$
call DeleteObject hbitmap
end
Sub BitBlt hDCdest,x,y,w,h,hDCsrc,x2,y2
CallDLL #gdi32, "BitBlt",hDCdest As uLong,_
x As Long,y As Long,w As Long,h As Long,_
hDCsrc As uLong,x2 As Long,y2 As Long,_
_SRCCOPY As Ulong,RESULT As Boolean
End Sub
Function SelectObject(hDC,hObject)
CallDLL #gdi32,"SelectObject",hDC As uLong,_
hObject As uLong,SelectObject As uLong
'returns previously selected object
End Function
Sub DeleteObject hObject
CallDLL #gdi32,"DeleteObject",hObject As uLong,r As Boolean
End Sub
Function CreateCompatibleBitmap(hDC,w,h )
CallDLL #gdi32, "CreateCompatibleBitmap", hDC As uLong,_
w As Long,h As Long, CreateCompatibleBitmap As uLong
End Function
Function GetDC(hWnd)
CallDLL #user32, "GetDC",hWnd As uLong,GetDC As uLong
End Function
Sub ReleaseDC hWnd, hDC
CallDLL#user32,"ReleaseDC",hWnd As uLong,_
hDC As uLong,result As Long
End Sub
Function CreateCompatibleDC(hDC)
CallDLL #gdi32,"CreateCompatibleDC",_
hDC As uLong, CreateCompatibleDC As uLong
End Function
Sub DeleteDC hDC
CallDLL #gdi32, "DeleteDC",hDC As uLong, r As Boolean
End Sub