Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PixelChecksum. Wait until something changes on screen.
#4
Function CaptureImageOnScreen
Code:
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.


;EXAMPLE
;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
,action|1
,r=SaveBitmap(bm saveToBmpFile)
,
if(&getHbitmap and r) ;;get HBITMAP
,action|2
,getHbitmap=bm
,
if(!action) ;;store to the clipboard
,r=OpenClipboard(_hwndqm)
,if(r)
,,EmptyClipboard
,,r=SetClipboardData(CF_BITMAP bm)!0
,,CloseClipboard

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

ret r


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)