Getting pixel colors from another application's window

Hi,

I need to be able to get the colors of pixels in another application's window. Currently i use the GetPixel API in my vb app and this works quite well. The problem is that GetPixel fails if the window your getting values from is minimised or covered etc. Does anybody know how i can get pixel color values from another window even if it is minimised? i have been searching for ages for a better way than Getpixel but no luck yet.

Thanks,
Redux
ReduxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ErglmopCommented:
Redux,

As you found out, GetPixel will only get the color of an on-screen pixel.  If an app is minimzed or hidden, it's not on-screen!   The application is responsible for repainting the window when it is restored or maximized, so there really isn't a pixel color on the window when it is not visible.

Don't know if this helps, but you could probably use the API GetDC() to get the device context for the window (I'm assuming you have the window's handle), then use GetBkColor() to get the background color for that context.  This will return the default background color for the device context, but if the app draws on top of the background, the pixel color is not guaranteed.  

I hate to ask why you need to get the color of a pixel on a hidden window...!

Erglmop
0
ReduxAuthor Commented:
Hi,
Thanks for your reply. Yes, I have the handle of the window, and i have been getting the DC using the GetWindowDC API. Unfortunately your suggestion of GetBkColor wont work, because I need to read quite a few pixel colors at different coordinates not just the background color.

As for why I need to do this it is because my program is designed to operate in the background whilst the user is doing other things (hence both my app and the app im getting pixel colors from will be minimised).
0
zzzzzoocCommented:
The device context is destroyed when not on-screen so getting it won't help either if it's minimized. A sloppy choice for you would be to set the window position to "on top", get the DC, copy it into a compatible bitmap/dc in your application then set the window back to it's original state. The showing/restoring should be only a flicker.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ReduxAuthor Commented:
Hi,
    The problem is I am getting calling GetPixel roughly 3 times a second as the pixel colors are changing every so often. So it might not be very pratical to constantly keep pulling the window to the top. Thanks for reply tho. Im increasing the points to 300 as it seems this is a very difficult question. Can anyone else think of a way to read individual pixels on minimised windows? If not I will award the points to zzzzzooc as he seems to have offered a possible solution that would work.
0
Hasan_KhanCommented:
Get the snap shot of the window before its minimized and then scan the pixels of the snap shot.

Google>VB+Source+Capture+Screen
0
ReduxAuthor Commented:
I'm sorry. I don't think i've explained this very well. The program im reading pixels from is displaying numbers on its window. My program uses getpixel to do a basic character recognition to find out what the numbers are and this works fine until the window is minimised or the areas im getpixelling from are covered. The numbers are also changing quite often which means i have to getpixel quite frequently. Obviously this means that i have to be able to getpixel (or some similar method which can retrieve pixel colors) lots of times, not just once. I notice that getpixel wont work on areas of windows that are not in the current clipping area (like obscured parts of the form, as windows just doesnt draw them). Could I maybe alter the clipping region so getpixel works on areas of the window hidden?
If what i'm trying to do isn't possible (get values of pixel colors not currently displayed) then please tell me.
0
zzzzzoocCommented:
Only other alternative i've encountered is with WM_PAINT (have never attempted it myself yet):

http://www.fengyuan.com/article/wmprint.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.