- I use functions from the Gdip library in the script below, although I would also be interested in any other approaches, including using GDI functions instead of GDI+ (Gdip) functions.
- Also, I would be interested in creating a lossless png which is smaller than what Gdip_SaveBitmapToFile produces, e.g IrfanView produces small lossless png files. (Note: generally I do not need transparency information, only RGB values.)
Code: Select all
;[Gdip functions]
;GDI+ standard library 1.45 by tic - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=6517
q:: ;gdip - printscreen (no ToolTips, no cursor)
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen()
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return
w:: ;gdip - printscreen (show ToolTips, no cursor)
pToken := Gdip_Startup()
;CAPTUREBLT := 0x40000000 ;use CAPTUREBLT to get ToolTips
;SRCCOPY := 0x00CC0020
vRaster := 0x40000000 | 0x00CC0020
pBitmap := Gdip_BitmapFromScreen(0, vRaster)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return
;based on Gdip_BitmapFromScreen and CaptureCursor
e:: ;gdip - printscreen (show ToolTips, show cursor)
pToken := Gdip_Startup()
;vRaster := 0x00CC0020 ;the Gdip library BitBlt function uses this as the default
;CAPTUREBLT := 0x40000000 ;use CAPTUREBLT to get ToolTips
;SRCCOPY := 0x00CC0020
vRaster := 0x40000000 | 0x00CC0020
SysGet, vPosX, 76 ;SM_XVIRTUALSCREEN := 76
SysGet, vPosY, 77 ;SM_YVIRTUALSCREEN := 77
SysGet, vPosW, 78 ;SM_CXVIRTUALSCREEN := 78
SysGet, vPosH, 79 ;SM_CYVIRTUALSCREEN := 79
hDC1 := CreateCompatibleDC()
hBM := CreateDIBSection(vPosW, vPosH, hDC1)
hBMOld := SelectObject(hDC1, hBM)
hDC2 := GetDC()
BitBlt(hDC1, 0, 0, vPosW, vPosH, hDC2, vPosX, vPosY, vRaster)
VarSetCapacity(CURSORINFO, A_PtrSize=8?24:20, 0)
NumPut(A_PtrSize=8?24:20, &CURSORINFO, 0, "UInt")
DllCall("user32\GetCursorInfo", Ptr,&CURSORINFO)
vState := NumGet(&CURSORINFO, 4, "UInt") ;flags
hCursor := NumGet(&CURSORINFO, 8, "UInt") ;hCursor
vCurX := NumGet(&CURSORINFO, A_PtrSize=8?16:12, "Int") ;ptScreenPos ;x
vCurY := NumGet(&CURSORINFO, A_PtrSize=8?20:16, "Int") ;ptScreenPos ;y
if vState && (hCursor := DllCall("user32\CopyIcon", Ptr,hCursor, Ptr))
{
VarSetCapacity(ICONINFO, A_PtrSize=8?32:20, 0)
DllCall("user32\GetIconInfo", Ptr,hCursor, Ptr,&ICONINFO)
;vIsIcon := NumGet(&ICONINFO, 0, "Int") ;fIcon
vHotspotX := NumGet(&ICONINFO, 4, "UInt") ;xHotspot
vHotspotY := NumGet(&ICONINFO, 8, "UInt") ;yHotspot
hBMMask := NumGet(&ICONINFO, A_PtrSize=8?16:12, "Ptr") ;hbmMask
hBMColor := NumGet(&ICONINFO, A_PtrSize=8?24:16, "Ptr") ;hbmColor
DllCall("user32\DrawIcon", Ptr,hDC1, Int,vCurX-vHotspotX-vPosX, Int,vCurY-vHotspotY-vPosY, Ptr,hCursor)
DllCall("user32\DestroyIcon", Ptr,hCursor)
if hBMMask
DllCall("gdi32\DeleteObject", Ptr,hBMMask)
if hBMColor
DllCall("gdi32\DeleteObject", Ptr,hBMColor)
}
ReleaseDC(hDC2)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hBM)
SelectObject(hDC1, hBMOld)
DeleteObject(hBM)
DeleteDC(hDC2)
DeleteDC(hDC1)
Gdip_SetBitmapToClipboard(pBitmap)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return
[printscreens that include the cursor: CaptureCursor function used by CaptureScreen function]
Putting a screenshot from the clipboard onto a GUI - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45353
[printscreens that include ToolTips: use CAPTUREBLT]
c++ - How to capture the screen with the "Tool Tips"? - Stack Overflow
https://stackoverflow.com/questions/300 ... -tool-tips