1. get rectangulars from screenshot

What you can say about this code? I'm not a system programmer, so I'm afraid of any memory leaks and other subtle bugs. Maybe you recommend some tricks?

include win32lib/win32lib.ew 
 
constant WIDTH = 1024, HEIGHT = 768 
constant pmap = createEx(Pixmap, "", 0, 0, 0, WIDTH, HEIGHT, 0 ,0) 
 
export procedure shotScreen(integer x, integer y) 
	atom desktopDC = w32Func( xGetWindowDC, {0} ) 
	atom pixmapDC = getDC( pmap ) 
	  
	VOID = w32Func( xBitBlt, { 
	        pixmapDC, 0, 0, 
	        WIDTH, HEIGHT, 
	        desktopDC, 
	        x, y, 
	        SRCCOPY} ) 
 
	releaseDC( pixmapDC ) 
	VOID = w32Func( xReleaseDC, {0, desktopDC} ) 
end procedure 
 
export function getRectangle(integer x, integer y, integer w, integer h) 
	sequence Rectangle = {} 
	atom pixmapDC = getDC( pmap ) 
	x -= 1 
	y -= 1 
	for i = 1 to w do 
		for j = 1 to h do 
			Rectangle &= w32Func( xGetPixel, {pixmapDC, x+i, y+j} ) 
		end for 
	end for 
	releaseDC( pixmapDC ) 
	return Rectangle 
end function 
 
-- Usage: 
-- shotScreen(x, y) - capture area 1024x768, that begins in the point(x,y) 
-- getRectangle(x1, y1, width1, height1) - get rectangular area from the screenshot 
-- getRectangle(x2, y2, width2, height2) - get other rectangular area from same screenshot 
-- getRectangle(x3, y3, width3, height3) - column by column (not line by line) written to a one-dimensional sequence 
-- shotScreen(x, y) - capture next screenshot... and so on.

Thank you in advance. This is a very important part of my program. I even wanted to move this functionality in an external library, but changed my mind.

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu