Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PixelChecksum. Wait until something changes on screen.
How can I do a function to Wait until something (pixels) changes in the region 0,0 to 50,50 ?
Is the image known before? If yes, use scan. If no, also can be used scan but at first needs to capture the image at run time. I have a function for this, if you need.
Can you post the function?
Function CaptureImageOnScreen
Copy      Help
function# x y wid hei [$saveToBmpFile] [&getHbitmap]

;Captures a rectangle region on the screen.
;Can save the captured image to a bmp file, or get bitmap handle, or store to the clipboard.
;If saveToBmpFile and getHbitmap not used, stores to the clipboard.
;Returns 1 on success, 0 on failure.

;x, y, wid, hei - rectangle coordinates.
;saveToBmpFile - will save to this bmp file. Use "" if don't want to save.
;getHbitmap - int variable that receives bitmap handle. Use 0 if not needed. Later call DeleteObject.

;CaptureImageOnScreen 100 100 200 200

int dcs=GetDC(0) ;;get screen device context
int dc=CreateCompatibleDC(0) ;;create memory device context
int bm=CreateCompatibleBitmap(dcs wid hei) ;;create bitmap
int oldbm=SelectObject(dc bm) ;;select it into the memory dc
BitBlt(dc 0 0 wid hei dcs x y SRCCOPY) ;;copy from screen dc to memory dc

int r(1) action

if(len(saveToBmpFile)) ;;save
,r=SaveBitmap(bm saveToBmpFile)
if(&getHbitmap and r) ;;get HBITMAP
if(!action) ;;store to the clipboard
,,r=SetClipboardData(CF_BITMAP bm)!0

;release memory
ReleaseDC(0 dcs)
SelectObject(dc oldbm)
if(action&2=0) DeleteObject(bm)

ret r
Ok. Thanks.
Function WaitForRectImageChange
Copy      Help
function ^wt RECT&r

;Waits until something changes in the specified rectangle on the screen.

;wt - max wait time, s. Error on timeout. Use 0 to wait forever.
;r - variable that contains screen coordinates of the rectangle.

;r.left=100;; r.right=r.left+100;
;WaitForRectImageChange 0 r
;mes "changed"

GdiObject bm
if(!CaptureImageOnScreen(r.left r.right-r.left "" bm)) end ES_FAILED
int t1=GetTickCount
,if(!scan(bm 0 r 0)) break
,if(wt and GetTickCount-t1>=wt*1000) end "wait timeout"
Thanks again.

This is what I was looking for.

Forum Jump:

Users browsing this thread: 1 Guest(s)