#include-once #include #include ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image file location or HBitmap to locate on the ; desktop or in the SpecIfied HBitmap ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image dIffer from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; $HBMP - optional hbitmap to search in. sending 0 will search the desktop. ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specIfy ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage,$resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0) return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP) EndFunc Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom, ByRef $x, ByRef $y, $tolerance,$HBMP=0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) If IsString($findImage) Then ;If $tolerance>0 Then $findImage = "*" & $tolerance & " " & $findImage If $HBMP = 0 Then $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage) Else $result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP) EndIf Else $result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "ptr",$findImage,"ptr",$HBMP) EndIf ; If error exit If IsArray($result) Then;heres the workaround.. If $result[0]="0" Then return 0 Else If $result="0" Then return 0 EndIf Local $iRows = UBound($result, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10. Local $iCols = UBound($result, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20. Local $iDimension = UBound($result, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional. MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _ $iRows & " row(s) & " & $iCols & " column(s).") ; Iterating the array to display the data. For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $result[$i][$j] = "Row: " & $i & " - Col: " & $j Next Next _ArrayDisplay($result) ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search $array = StringSplit($result[0],"|") $x=Int(Number($array[1])) $y=Int(Number($array[2])) If $resultPosition=1 Then $x=$x + Int(Number($array[4])/2) $y=$y + Int(Number($array[5])/2) endIf return 1 EndFunc