To do this you’ll need to get busy with the Windows GDI API and a couple of other functions. I’m just going to throw the function names at you here - you’ll need to look up the details in the Platform SDK. Explaining in more detail would take much too long.
First, you need to identify the window of the application you’re interested in. The EnumWindows function is a callback type enumeration - you provide a pointer to a routine that accepts specific parameters and it’ll get called once for every open top-level window (if you’re on NT then the list will be limited to the ones on the desktop to which the UI of your application is bound).
This callback sends you application the window handle (hWnd) of each window. You can then use either GetWindowText or GetClassName if you know the class name. This will allow you to identify and store the hWnd of the window you’re interested in.
Now, to get the window’s display you need to start with the GDI. Windows draws graphics on things called Device Contexts (DC). Inside each Window DC will be various GDI objects, among them a Bitmap which should contain the graphical display of the user interface. I’ve had problems accessing the DC of Windows directly, so as an alternate method I usually get the DC of the desktop window (hWnd=0) which allows me to access the entire screen display.
Once you have a handle to the desktop DC (using GetDC) you can use the GetPixel function to return the colour of pixels at given coordinates. In order to know which corrdinates to examine you should call GetWindowRect or, probably more usefully, GetWindowPlacement. Both of these APIs gives you access to a RECT structure that describes the bounds of the window’s rectangle.
With this information you can start examining pixels within the window’s display and make decisions based on this. If you need to do more processing of the image, particularly processing that’ll change the image (edge-detect filters using boolean operations etc) then you’ll need to go a bit further and create your own copy of the window’s UI.
To do this you’ll need to build your own DC and Bitmap object. Use CreateCompatibleDC, [b/CreateCompatibleBitmap** and SelectObject. Remember to retain references to the objects selected out of the DC you create and destroy them properly when you’re done or you’ll leak memory. When you’ve built your private DC you can use BitBlt to copy rectangles of graphics around from DC to DC. Once you’ve copied the display to your private DC then you can do what you like to it without affecting the on-screen display.
All this is certainly possible in C++ and VB (v6 and, I think, v5). .NET languages provide a different way to do this via the System framework. Java, I’m not sure about. It probably can but I’ve not done any for seven or eight years, so I’m a bit rusty.
Hope this helps point you in the right direction.