I have the following code which simply do the following:
By Pressing F2, it copy FullScreen Screenshot to my Clipboard.
The problem i have is the following:
I want to SKIP the save to file at A_ScriptDir . "\Screenshot.bmp"
I want to just "take" the GDI_CaptureScreen( 0, 0, A_ScreenWidth, A_ScreenHeight ) and "copy" it to Clipboard.
I spend many hours, but i can not find a way to do it.
I will appreciate your help please. (Please note that for educational purposes, i want to use the following code - not other methods) - Thanks!
Code: Select all
F2:: ; get FullScreen Screenshot and save it to file and load it to clipboard
Clipboard := ; Clear the clipboard
DllCall( "DeleteObject", UInt,hBM )
hBM := ""
hBM := GDI_CaptureScreen( 0, 0, A_ScreenWidth, A_ScreenHeight )
GDI_SaveBitmap( hBM, A_ScriptDir . "\Screenshot.bmp" )
ImageToClipboard( A_ScriptDir . "\Screenshot.bmp")
Return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ImageToClipboard(Filename)
{
hbm := DllCall("LoadImage","uint",0,"str",Filename,"uint",0,"int",0,"int",0,"uint",0x10)
if !hbm
return
DllCall("OpenClipboard","uint",0)
DllCall("EmptyClipboard")
; Place the data on the clipboard. CF_BITMAP=0x2
if !DllCall("SetClipboardData","uint",0x2,"uint",hbm)
DllCall("DeleteObject","uint",hbm)
DllCall("CloseClipboard")
}
GDI_CaptureScreen( X, Y, W, H, ByRef Checksum="" ) {
tDC := DllCall( "CreateCompatibleDC", UInt,0 )
hBM := DllCall( "CopyImage", UInt,DllCall( "CreateBitmap", Int,W, Int,H, UInt,1, UInt,24
, UInt,0 ), UInt,0, Int,0, Int,0, UInt,0x2008, UInt )
oBM := DllCall( "SelectObject", UInt,tDC, UInt,hBM ), hDC := DllCall( "GetDC", UInt,0 )
DllCall( "BitBlt"
, UInt,tDC, UInt,0, UInt,0, Int,W, Int,H, UInt,hDC, UInt,X, UInt,Y, UInt,0x00CC0020 )
DllCall( "ReleaseDC", UInt,0, UInt,hDC ), DllCall( "SelectObject", UInt,tDC, UInt,oBM )
If ( Checksum <> "" )
VarSetCapacity( BM,24,0 ), DllCall( "GetObject", UInt,hBM, UInt,24, UInt,&BM )
, DllCall( "shlwapi\HashData", UInt,NumGet(BM,20), UInt,NumGet( BM,12 )*NumGet( BM,8 )
, Int64P,Checksum, UInt,7 )
Return hBM, DllCall( "DeleteDC", UInt,tDC )
}
GDI_SaveBitmap( hBM, File ) {
DllCall( "GetObject", Int,hBM, Int,VarSetCapacity($,84), UInt,NumPut(0,$,40,"Short")-42 )
Numput( VarSetCapacity(BFH,14,0)+40, Numput((NumGet($,44)+54),Numput(0x4D42,BFH)-2)+4 )
If ( hF := DllCall( "CreateFile", Str,File,UInt,2**30,UInt,2,Int,0,UInt,2,Int64,0 ) ) > 0
DllCall( "WriteFile", UInt,hF, UInt,&BFH, UInt,14, IntP,0,Int,0 ) ; BITMAPFILEHEADER
, DllCall( "WriteFile", UInt,hF, UInt,&$+24, UInt,40, IntP,0,Int,0 ) ; BITMAPINFOHEADER
, DllCall( "WriteFile", UInt,hF, UInt,NumGet($,20), UInt,NumGet($,44), UIntP,BW, Int,0 )
, DllCall( "CloseHandle", UInt,hF )
Return BW ? 54+BW : 0
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;