Skip to content

Instantly share code, notes, and snippets.

@J2TEAM
Forked from turbo/readcolor.au3
Created December 22, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J2TEAM/924ea793d7ccb86e4f90 to your computer and use it in GitHub Desktop.
Save J2TEAM/924ea793d7ccb86e4f90 to your computer and use it in GitHub Desktop.
Read pixel from hidden window
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
Local $hCompDC = _WinAPI_CreateCompatibleDC(0)
Local $tBMI = DllStructCreate($tagBITMAPINFO)
DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4) ; size of struct
DllStructSetData($tBMI, 2, 400) ; width
DllStructSetData($tBMI, 3, 400) ; height
DllStructSetData($tBMI, 4, 1)
DllStructSetData($tBMI, 5, 32) ; bits per pixel
$aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
$hGDIObj = $aDIB[0]
$hPtr = $aDIB[4]
_WinAPI_SelectObject($hCompDC, $hGDIObj)
$hPixelStruct = DllStructCreate("dword[160000]", $hPtr)
$hWnd = WinGetHandle("Paint")
$hWndDC = _WinAPI_GetDC($hWnd)
Local $iX = 20
Local $iY = 20
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "ptr", $hCompDC, "int", 0)
$iColor = MsgBox(0, "Color", '0x' & Hex(DllStructGetData($hPixelStruct, 1, $iY * 400 + $iX + 1), 6))
_WinAPI_ReleaseDC(0, $hCompDC)
_WinAPI_ReleaseDC($hWnd, $hWndDC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment