Code:
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>
WinWaitActive( "World of Warcraft" )
local $hWnd = WinGetHandle("World of Warcraft")
local $Color2 = DIB_GetPixelColor( $hWnd, 10, 10 )
;global $Color2 = 0x000095D9
;global $Color2 = 0x00D99500
MsgBox(0, "Color", '0x' & Hex($Color2, 6) )
Opt("PixelCoordMode",2)
$Color2 = PixelGetColor( 10, 10, $hWnd )
MsgBox(0, "Color", '0x' & Hex($Color2, 6) )
local $where = DIB_SearchPixelColor( $hWnd, $Color2 )
MsgBox(0, "Color", '0x' & Hex($Color2, 6) & " at " & $where[1] & " - " & $where[0])
local $where = DIB_SearchPixelColor2( $hWnd, $Color2 )
MsgBox(0, "Color", '0x' & Hex($Color2, 6) & " at " & $where[1] & " - " & $where[0])
Func DIB_GetPixelColor( $hWnd, $ClientX, $ClientY )
local $hWndDC = _WinAPI_GetDC($hWnd)
local $ret = _WinAPI_GetPixel( $hWndDC, $ClientX, $ClientY)
_WinAPI_ReleaseDC($hWnd, $hWndDC)
return $ret
EndFunc
Func DIB_SearchPixelColor2( $hWnd, $SearchForColor )
local $Size = WinGetPos ( $hWnd )
local $width = $Size[2]
local $height = $Size[3]
local $AbsolutX = $Size[0]
local $AbsolutY = $Size[1]
local $PixelCount = $width * $height
local $hWndDC = _WinAPI_GetDC($hWnd)
$SearchForColor = mod( $SearchForColor, 0x00FFFFFF )
For $iy=0 To $height Step 1
For $ix=0 To $width Step 1
local $DibY = $height - $iy - 1;
local $ic = _WinAPI_GetPixel( $hWndDC, $ix, $iy)
$ic = mod( $ic, 0x00FFFFFF )
if( $ic == $SearchForColor ) then
local $ret[4]
$ret[0] = $ix
$ret[1] = $iy
$ret[2] = $AbsolutX + $ix
$ret[3] = $AbsolutY + $iy;
_WinAPI_ReleaseDC($hWnd, $hWndDC)
return $ret
endif
next
next
MsgBox(0, "Color", 'nope')
SetError ( 1 );
_WinAPI_ReleaseDC($hWnd, $hWndDC)
endfunc
Func DIB_SearchPixelColor( $hWnd, $SearchForColor )
local $Size = WinGetPos ( $hWnd )
local $width = $Size[2]
local $height = $Size[3]
local $PixelCount = $width * $height
local $hWndDC = _WinAPI_GetDC($hWnd)
Local $hCompDC = _WinAPI_CreateCompatibleDC(0)
Local $tBMI = DllStructCreate($tagBITMAPINFO)
DllStructSetData($tBMI, 1, DllStructGetSize($tBMI) - 4) ; size of struct
DllStructSetData($tBMI, 2, $width) ; width
DllStructSetData($tBMI, 3, $height) ; height
DllStructSetData($tBMI, 4, 1)
DllStructSetData($tBMI, 5, 32) ; bits per pixel
local $aDIB = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBMI), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'uint', 0)
local $hGDIObj = $aDIB[0]
local $hPtr = $aDIB[4]
_WinAPI_SelectObject($hCompDC, $hGDIObj)
local $PixelMap = DllStructCreate("dword[" & $PixelCount & "]", $hPtr)
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "ptr", $hCompDC, "int", 0)
local $ret = DIB_SearchPixelColor_( $PixelMap, $width, $height, $SearchForColor, $Size[0], $Size[1] )
_WinAPI_ReleaseDC(0, $hCompDC)
_WinAPI_ReleaseDC($hWnd, $hWndDC)
return $ret
EndFunc
Func DIB_SearchPixelColor_( $PixelMap, $width, $height, $SearchForColor, $AbsolutX, $AbsolutY )
$SearchForColor = mod( $SearchForColor, 0x00FFFFFF )
For $iy=0 To $height Step 1
For $ix=0 To $width Step 1
local $DibY = $height - $iy - 1;
local $ic = DllStructGetData($PixelMap, 1, $DibY * $width + $iX + 1)
$ic = mod( $ic, 0x00FFFFFF )
if( $ic == $SearchForColor ) then
local $ret[4]
$ret[0] = $ix
$ret[1] = $iy
$ret[2] = $AbsolutX + $ix
$ret[3] = $AbsolutY + $iy;
return $ret
endif
next
next
MsgBox(0, "Color", 'nope')
SetError ( 1 );
Endfunc