; клиентские координаты интересующих пикселей
x1 := 1000, y1 := 10
x2 := 1000, y2 := 20
hWnd := WinExist("A") ; идентификация окна
WinPos := WinGetP(hWnd) ; координаты клиентской области окна
;=====================================================
hDC := Window_CreateCapture(hWnd) ; снимок окна
pix1 := Client_GetPixel(hDC, x1, y1, WinPos)
pix2 := Client_GetPixel(hDC, x2, y2, WinPos)
Window_DeleteWindowCapture(hWnd, hDC) ; удаление снимка
;=====================================================
MsgBox % Format("{:#0x}", pix1) " " Format("{:#0x}", pix2) ; формат BGR hex
Return
Window_CreateCapture(hwnd) {
Return DllCall("user32.dll\GetDCEx", "UInt", hwnd, "UInt", 0, "UInt", 1|2)
} ; 1|2|8|16 — флаги ставим по документации GetDCEx на msdn
Client_GetPixel(hDC, x, y, WinPos) {
Return DllCall("gdi32.dll\GetPixel", "UInt", hDC, "Int", x+WinPos.Client2Win.x, "Int", y+WinPos.Client2Win.y, "UInt")
}
Window_DeleteWindowCapture(hwnd, hDC) {
Return DllCall("user32.dll\ReleaseDC", "UInt", hwnd, "UInt", hDC)
}
WinGetP(hwnd) {
WinGetPos, x_W, y_W, w_W, h_W, % "ahk_id " hWnd
VarSetCapacity(pt, 16)
NumPut(x, pt, 0) || NumPut(y, pt, 4) || NumPut(w, pt, 8) || NumPut(h, pt, 12)
if !DllCall("GetClientRect", UInt, hWnd, UInt, &pt)
Return
if !DllCall("ClientToScreen", UInt, hWnd, UInt, &pt)
Return
x := NumGet(pt, 0, Int), y := NumGet(pt, 4, Int)
w := NumGet(pt, 8, Int), h := NumGet(pt, 12, Int)
Client := {x:x, y:y, w:w, h:h}, Client2Win := {x:x-x_W, y:y-y_W, w:w, h:h}
Return WinP := {x:x_W, y:y_W, w:w_W, h:h_W, Client2Win:Client2Win, Client:Client}
}