views:

49

answers:

1

I'm looking to developing something for my Win32 system that can find and respond to particular screen events. For instance, when bitmap range (100,100) to (130,130) of my screen (a 30x30 pixel portion of the screen) matches a provided 30x30 pixel baseline, then do a certain action.

Can anyone get me started with this? Perhaps there's a framework that will make this easier? Or a package I can use? Or even perhaps a 3rd party utility?

+1  A: 

You can try getting the desktop window (GetDesktopWindow) and then getting a device context for it (GetWindowDC), then create a compatible in-memory device context (CreateCompatibleDC), create a compatible bitmap from the desktop dc (CreateCompatibleBitmap), select it in the in-memory dc (SelectObject) and then do bit-blitting fo the region you are interested from the desktop dc into the in-memory dc(BitBlt). Don't forget to cleanup after all this.

Oh, and if you are doing this in managed code, you can find all these APIs on PInvoke.net. You'll also need to use Imaging.CreateBitmapSourceFromHBitmap to copy the bitmap from the native bitmap into the managed bitmap.

I am writing all this from memory; it used to work on XP, but I have not tried it on Vista or Win7.

EDIT: A quick search on the web for ".Net screen capture" returns couple of hits, including this one with sample code in C# and VB.Net.

Franci Penov
Any examples? This would be on XP, so that would be perfect if I could see it in action, maybe some demo code. I would used managed code.
Ray
Umh, sorry, I don't have a working code right now. Plus, the above should only give you the bitmap of the screen; you'll have to deal with the analysis.
Franci Penov