i cant get bluestack and imagesearch work please help
Global $MainScreenStart = @ScriptDir & "\Images\MainScreenStart.bmp"
_CaptureRegion()
Local $collx, $colly, $i = 0
If _ImageSearch($MainScreenStart, 1, $collx, $colly, 20) Then
SetLog("~~~~ ImageSearch Working~~~~")
EndIf
Func _CaptureRegion($iLeft = 0, $iTop = 0, $iRight = 900, $iBottom = 750, $ReturnBMP = False)
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBitmap)
Global $iW = Number($iRight) - Number($iLeft), $iH = Number($iBottom) - Number($iTop)
Local $hDC_Capture = _WinAPI_GetWindowDC(ControlGetHandle("BlueStacks App Player", "", "[CLASS:BlueStacksApp; INSTANCE:1]"))
Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
$hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iW, $iH)
Local $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
DllCall("user32.dll", "int", "PrintWindow", "hwnd", $HWnD, "handle", $hMemDC, "int", 0)
_WinAPI_SelectObject($hMemDC, $hHBitmap)
_WinAPI_BitBlt($hMemDC, 0, 0, $iW, $iH, $hDC_Capture, $iLeft, $iTop, 0x00CC0020)
Global $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_SelectObject($hMemDC, $hObjectOld)
_WinAPI_ReleaseDC($HWnD, $hDC_Capture)
EndFunc ;==>_CaptureRegion
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $Tolerance)
Return _ImageSearchArea($findImage, $resultPosition, 0, 0, 840, 720, $x, $y, $Tolerance)
EndFunc ;==>_ImageSearch
Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $Tolerance)
Global $HBMP = $hHBitmap
$HBMP = 0
$x1 += $BSPos[0]
$y1 += $BSPos[1]
$right += $BSPos[0]
$bottom += $BSPos[1]
;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
If IsString($findImage) Then
If $Tolerance > 0 Then $findImage = "*" & $Tolerance & " " & $findImage
If $HBMP = 0 Then
$result = DllCall($pImageLib, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
Else
$result = DllCall($pImageLib, "str", "ImageSearchEx", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP)
EndIf
Else
$result = DllCall($pImageLib, "str", "ImageSearchExt", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "int", $Tolerance, "ptr", $findImage, "ptr", $HBMP)
EndIf
If @error Then _logErrorDLLCall($pImageLib, @error)
; If error exit
If IsArray($result) Then
If $result[0] = "0" Then Return 0
Else
SetLog("Error: Image Search not working...")
Return 1
EndIf
SetLog("Error: Image Search not working...")
; 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], "|")
If (UBound($array) >= 4) Then
$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
EndIf
EndFunc ;==>_ImageSearchArea






