Need help bg imagesearch autoit

03/28/2018 22:55 lenclstr746#1
MY FUNC
#include <WinAPISysWin.au3>
Func _imagesearchbg($hwnd, $findimage, $resultposition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $hbmp = 0)
If $tolerance > 0 Then $findimage = "*" & $tolerance & " " & $findimage
If IsString($findimage) Then
$result = DllCall("bg.dll", "str", "ImageSearch", "hwnd", $hwnd, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findimage)
Else
$result = DllCall("bg.dll", "str", "ImageSearch", "hwnd", $hwnd, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findimage)
EndIf
If $result[0] = "0" Then Return 0
$array = StringSplit($result[0], "|")
$x = Int(Number($array[2]))
$y = Int(Number($array[3]))
If $resultposition = 1 Then
$x = $x + Int(Number($array[4]) / 2)
$y = $y + Int(Number($array[5]) / 2)
EndIf
Return 1
EndFunc
$hwnd = WinGetHandle("Yeni Sekme - Google Chrome")
Global $x,$y
If _imagesearchbg($hwnd,"ara.png",0,0,0,_WinAPI_GetWi ndowWidth($hwnd),_WinAPI_GetWindowHeight($hwnd),$x ,$y,25) = 1 Then
MsgBox(0,$x,$y)
EndIf
But ı try and ı have a error "Subscript used on on-accessible variable"?
05/28/2018 12:54 imported_x_x#2
are you using windows 10? :wat:
09/10/2018 19:46 VitorCornelius#3
Quote:
Originally Posted by lenclstr746 View Post
MY FUNC
#include <WinAPISysWin.au3>
Func _imagesearchbg($hwnd, $findimage, $resultposition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $hbmp = 0)
If $tolerance > 0 Then $findimage = "*" & $tolerance & " " & $findimage
If IsString($findimage) Then
$result = DllCall("bg.dll", "str", "ImageSearch", "hwnd", $hwnd, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findimage)
Else
$result = DllCall("bg.dll", "str", "ImageSearch", "hwnd", $hwnd, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findimage)
EndIf
If $result[0] = "0" Then Return 0
$array = StringSplit($result[0], "|")
$x = Int(Number($array[2]))
$y = Int(Number($array[3]))
If $resultposition = 1 Then
$x = $x + Int(Number($array[4]) / 2)
$y = $y + Int(Number($array[5]) / 2)
EndIf
Return 1
EndFunc
$hwnd = WinGetHandle("Yeni Sekme - Google Chrome")
Global $x,$y
If _imagesearchbg($hwnd,"ara.png",0,0,0,_WinAPI_GetWi ndowWidth($hwnd),_WinAPI_GetWindowHeight($hwnd),$x ,$y,25) = 1 Then
MsgBox(0,$x,$y)
EndIf
But ı try and ı have a error "Subscript used on on-accessible variable"?
First of all, you have to import the imagesearchbg function, what u are useing in your script, or the "<WinAPISysWin.au3>" is that file?

_imagesearchbg($hwnd, $findimage, $resultposition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $hbmp = 0) Looks same as _ImageSearchArea function. But we do not know how the DLL work what you are useing. You should open the imagesearch function file what you are useing and then you will have the require help info for it if the owner provided it there.

You code is little bit chaotic. I can not test it, since i do not have the require files, but:

If _imagesearchbg($hwnd, "ara.png", 0, 0, 0, _WinAPI_GetWindowWidth($hwnd), _WinAPI_GetWindowHeight($hwnd), $x, $y, 25) = 1 Then
EndIf
MsgBox(0, $x, $y)

$x and $y variable have no value if the image is not found. you have to place the msgbox row between if / endif in your script like this:

If _imagesearchbg($hwnd, "ara.png", 0, 0, 0, _WinAPI_GetWindowWidth($hwnd), _WinAPI_GetWindowHeight($hwnd), $x, $y, 25) = 1 Then
MsgBox(0, $x, $y)
EndIf

msgbox title will be your X coordinate and the message on it will be the Y coord. If your imagesearch function work the same way as the _imagesearch.au3 then the X/Y coord what you found will be the image top left corner coordinate where it got found.

Other thing:
you are searching from 0,0 coordinate what is top left corner of your screen to the window size. It will work if the window is on the 0,0 coordinate. If you move the window then it will give you fals result. If the window is full screen, then you do not need to get the window size (WinGetClientSize also work). You can just use your screen size, or there is a function where you can grab your screen size (@DesktopHeight / @DesktopWidth).


BTW did you just copy + paste you code from several places, or you wrote it by yourself?