hwnd := WinExist("A") ; указать нужный хэндл
pToken := Gdip_Startup()
MsgBox, % pBitmap := Gdip_BitmapFromHWND(hwnd) ; адрес Bitmap
; здесь нужные действия с Bitmap
; для поиска пикселя можно воспользоваться Gdip_GetPixel(pBitmap, x, y)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
return
Gdip_Startup()
{
if !DllCall("GetModuleHandle", "str", "gdiplus", "ptr")
DllCall("LoadLibrary", "str", "gdiplus")
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "uptr*", pToken, "ptr", &si, "ptr", 0)
return pToken
}
Gdip_BitmapFromHWND(hwnd)
{
WinGetPos,,, Width, Height, ahk_id %hwnd%
hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
PrintWindow(hwnd, hdc)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
return pBitmap
}
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
{
hdc2 := hdc ? hdc : GetDC()
VarSetCapacity(bi, 40, 0)
NumPut(w, bi, 4, "uint"), NumPut(h, bi, 8, "uint"), NumPut(40, bi, 0, "uint")
, NumPut(1, bi, 12, "ushort"), NumPut(0, bi, 16), NumPut(bpp, bi, 14, "ushort")
hbm := DllCall("CreateDIBSection", "ptr" , hdc2, "ptr" , &bi, "uint" , 0, "ptr*", ppvBits, "ptr" , 0, "uint" , 0, "ptr")
if !hdc
ReleaseDC(hdc2)
return hbm
}
GetDC(hwnd=0)
{
return DllCall("GetDC", "ptr", hwnd, "ptr")
}
ReleaseDC(hdc, hwnd=0)
{
return DllCall("ReleaseDC", "ptr", hwnd, "ptr", hdc)
}
CreateCompatibleDC(hdc=0)
{
return DllCall("CreateCompatibleDC", "ptr", hdc, "ptr")
}
SelectObject(hdc, hgdiobj)
{
return DllCall("SelectObject", "ptr", hdc, "ptr", hgdiobj, "ptr")
}
PrintWindow(hwnd, hdc, Flags=0)
{
return DllCall("PrintWindow", "ptr", hwnd, "ptr", hdc, "uint", Flags)
}
Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
{
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "ptr", hBitmap, "ptr", Palette, "ptr*", pBitmap)
return pBitmap
}
Gdip_GetPixel(pBitmap, x, y)
{
DllCall("gdiplus\GdipBitmapGetPixel", "ptr", pBitmap, "int", x, "int", y, "uint*", ARGB)
return ARGB
}
DeleteObject(hObject)
{
return DllCall("DeleteObject", "ptr", hObject)
}
DeleteDC(hdc)
{
return DllCall("DeleteDC", "ptr", hdc)
}
Gdip_DisposeImage(pBitmap)
{
return DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap)
}
Gdip_Shutdown(pToken)
{
DllCall("gdiplus\GdiplusShutdown", "uptr", pToken)
if hModule := DllCall("GetModuleHandle", "str", "gdiplus", "ptr")
DllCall("FreeLibrary", "ptr", hModule)
return 0
}