Re: PokerPad - AHK hotkey script
@Dave
OK, here are the functions for creating a window capture, getting pixels from the window capture and deleting the window capture:
<font class="small">Code:</font><hr /><pre>/* Usage:
* Creates an offscreen capture of a window. The window cannot be minimized but may be invisible.
* Parameters:
* id: The window's id of which to create a capture
* device, context, pixels: Blank variables, see Releasing Memory below.
* Releasing Memory:
* After the capture is no longer needed, it's memory must be freed by calling Display_DeleteWindowCapture(device, context, pixels)
* where the 3 parameters are those that was passed to create the window capture.
*/
Display_CreateWindowCapture(ByRef device, ByRef context, ByRef pixels, ByRef id = "") {
if !id
WinGet, id, ID
device := DllCall("GetDC", UInt, id)
context := DllCall("gdi32.dll\CreateCompatibleDC", UInt, device)
WinGetPos, , , w, h, ahk_id %id%
pixels := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt, device, Int, w, Int, h)
DllCall("gdi32.dll\SelectObject", UInt, context, UInt, pixels)
DllCall("PrintWindow", "UInt", id, UInt, context, UInt, 0)
; TODO: error checking, return true if succeeded
}
Display_DeleteWindowCapture(ByRef device, ByRef context, ByRef pixels) {
DllCall("gdi32.dll\ReleaseDC", UInt, device)
DllCall("gdi32.dll\DeleteDC", UInt, context)
DllCall("gdi32.dll\DeleteObject", UInt, pixels)
}
/* Usage:
* Gets the pixel from a window capture created from Display_CreateWindowCapture
* Parameters:
* context: the device context as given by Display_CreateWindowCapture
* x, y: the coordinate parameters
* Return:
* The pixel in RGB format.
*/
Display_GetPixel(ByRef context, x, y) {
return DllCall("GetPixel", UInt, context, Int, x, Int, y)
}</pre><hr />
They are now in a file called Display.ahk hence the Display_ prefix on each function name.
The only major changes I've made is restricting the size of the buffer to the size of the window (as opposed to the monitor size - it may even be possible to have a window larger than the monitor size and I don't know what kinds of fun that could pop up...) And also the use of ReleaseDC instead of DeleteDC. From what I've read, you are suppose to call ReleaseDC after you are finished with what is returned from the GetDC call (which I believe is the screen display device context hence my calling it "device"). I hope this is correct.
I have converted everything in PokerPad 0.1.5 (not yet released) to use these functions instead of reading from the screen and everything seems to work as before (This usually scares me into thinking I really didn't change anything! Usually something gets screwed up and nothing works anymore LOL).
|