Quote:
I'll have to read up on this, but I think you are correct. All I know is that without the DeleteDC commands, it stops working after a while (running out of GDI resources imo). What you say rings a bell - but it is >3 years since I did any C++ Win32-GDI coding, so I need to check. I *think* DeleteDC does enough to free the resources - but it certainly can't hurt to ReleaseDC too.
I don't use DeleteDC on the device handle at all (That returned from the GetDC call). It is my understanding that you only delete things you create, therefore you are not suppose to delete 'device', but as the 'context' and 'pixels' are created, those must be deleted.
Quote:
Another thisn - not mentioned above, but in your email - about the PrintWindow options:
Either the documentation or the function is backwards
The documentation never specified what the values are, but 0 works whereas 1 doesn't so I use 0
Quote:
You can be sur using these functions it is using the PrintWindow method - so if it all continues to work without noticable difference - sweet
Only noticeable difference was after benchmarking the two OCR methods (screen reading and print window), the print window method was 5x faster
There seems to be quite a bottleneck somewhere in getting each pixel from the screen.
Quote:
You don't use ity in the above functions, but there MUST be a better way of adding a +/- for "Shades of variation" than my crapola method of SetFormat -> StringMid -> add/subtract ->recombine Hex - SetFormat, which I'm sure is horrific but works.
I guess The Binary / BitShift operators, but hose confuse me no end
You are correct. Here is the function I use:
<font class="small">Code:</font><hr /><pre>Display_CompareColors(ByRef bgr1, ByRef bgr2, ByRef variation) {
c1 := bgr1 & 0xff
c2 := bgr2 & 0xff
if (abs(c1 - c2) > variation)
return false
c1 := (bgr1 >> 8) & 0xff
c2 := (bgr2 >> 8) & 0xff
if (abs(c1 - c2) > variation)
return false
c1 := (bgr1 >> 16) & 0xff
c2 := (bgr2 >> 16) & 0xff
if (abs(c1 - c2) > variation)
return false
return true
}</pre><hr />
Just ignore the fact that the parameters say bgr1 and bgr2, as RGB format works just as well. The bgr names are just an artifact from screen reading which returns the values in BGR format.
Also, besides the Display_ReadArea function, I also made the following pixel search function:
<font class="small">Code:</font><hr /><pre>/* Usage:
* Searches for the specifed color in the given rectangle of a window capture created from Display_CreateWindowCapture
* Parameters:
* id: either a window id or the letter c followed by the device context handle as given by Display_CreateWindowCapture
* x, y, w, h: the rectangle parameters
* color: the color in RGB format
* variation: the allowed variation from the specified color
* Return:
* Returns true if the specified color/variation is found within the given area, false otherwise.
*/
Display_PixelSearch(x, y, w, h, color, variation, ByRef id = "") {
if !id
Display_CreateWindowCapture(device, context, pixels)
else if (SubStr(id, 1, 1) = "c")
context := SubStr(id, 2)
else
Display_CreateWindowCapture(device, context, pixels, id)
Loop, %w% {
j := y
Loop, %h% {
rgb := Display_GetPixel(context, x, j++)
if Display_CompareColors(rgb, color, variation) {
if device
Display_DeleteWindowCapture(device, context, pixels)
return true
}
}
x++
}
if device
Display_DeleteWindowCapture(device, context, pixels)
return false
}</pre><hr />