Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find a color or image in an accessible object
#1
Member function Acc.FindColor. Create it using menu File -> New -> New Member Function. The second function also is needed for this function.
Code:
Copy      Help
function# color [RECT&foundLocation] [scanFlags] [RECT&margins]

;Finds color within the accessible object.
;Uses <help "::/Functions/IDP_SCAN.html">scan</help>, which finds a single-pixel image created from the color.
;Returns 1 if found, 0 if not found, or throws error thrown by <color "0xff0000">scan</color> or Acc.Location.
;To get color value from screen, you can use <help "::/Functions/IDP_PIXEL.html">pixel</help> or the Wait dialog from the floating toolbar.


;color - color in 0xBBGGRR format.
;foundLocation - optional RECT variable that will receive screen coordinates of the color. Use 0 if not needed. Note that it is not used to limit the search area. It only receives results.
;scanFlags - same as flags argument of <color "0xff0000">scan</color>.
;margins - optional RECT variable that contains search area margins. For example, if margins.left is 20, the function will not search in first 20 pixels in the left of the object. Or, if margins.left is -30, the function also will search in 30 pixels to the left from the object.


;See also: <ColorFromRGB>.

;EXAMPLE
;Acc a=acc("Notification Area" "TOOLBAR" win("" "Shell_TrayWnd") "ToolbarWindow32" "" 0x1001)
;if(!a.FindColor(ColorFromRGB(0 0 255) 0 0x3)) ret
;out "found"



;create memory dc and 1x1 bitmap
int dcs=GetDC(0)
int dc=CreateCompatibleDC(0)
int bm=CreateCompatibleBitmap(dcs 1 1)
int oldbm=SelectObject(dc bm)

SetPixel(dc 0 0 color)

int e ok=this.FindImage(0 foundLocation scanFlags bm margins)
err e=1

;release memory
ReleaseDC(0 dcs)
SelectObject(dc oldbm)
DeleteObject(dc)
DeleteObject(bm)

if(e) end _error
ret ok

Member function Acc.FindImage. Create it using menu File -> New -> New Member Function.
Code:
Copy      Help
function# $bmpFile [RECT&foundLocation] [scanFlags] [handle] [RECT&margins]

;Finds image within the accessible object.
;Uses <help "::/Functions/IDP_SCAN.html">scan</help>.
;Returns 1 if found, 0 if not found, or throws error thrown by <color "0xff0000">scan</color> or Acc.Location.
;To capture the image and get values for other arguments you can use the 'Find Image' dialog from the floating toolbar.


;bmpFile - bitmap or icon file that contains image to find. Same as with <color "0xff0000">scan</color>, except that handle cannot be used.
;foundLocation - optional RECT variable that will receive screen coordinates of the image. Use 0 if not needed. Note that it is not used to limit the search area. It only receives results.
;scanFlags - same as flags argument of <color "0xff0000">scan</color>.
;handle - bitmap or icon handle to be used instead of bmpFile.
;margins - optional RECT variable that contains search area margins. For example, if margins.left is 20, the function will not search in first 20 pixels in the left of the object. Or, if margins.left is -30, the function also will search in 30 pixels to the left from the object.


;EXAMPLE
;Acc a=acc("Notification Area" "TOOLBAR" win("" "Shell_TrayWnd") "ToolbarWindow32" "" 0x1001)
;if(!a.FindImage("Macro517.bmp" 0 0x3)) ret
;out "found"



RECT r
this.Location(r.left r.top r.right r.bottom)
r.right+r.left; r.bottom+r.top
if(&margins)
,r.left+margins.left; r.top+margins.top; r.right-margins.right; r.bottom-margins.bottom
,if(r.left>=r.right or r.top>=r.bottom) ret

int ok
if(handle) ok=scan(handle 0 r scanFlags)
else ok=scan(bmpFile 0 r scanFlags)
if(!ok) ret
if(&foundLocation) foundLocation=r
ret 1

err+ end _error


To capture accessible object and insert Acc... code, use the 'Find accessible object' dialog from the floating toolbar.


Forum Jump:


Users browsing this thread: 1 Guest(s)