My Aim:
- I'd like to have the ability to retrieve the colour on the screen including the cursor, from certain coordinates.
- In other words, I suppose you could say I'd like to retrieve the colour of the cursor (or at least, a certain point/pixel on the cursor).
My Difficulty:
- I have some code already to retrieve the colour on the screen from certain coordinates, however I believe it does not include the cursor. I believe this to be because the method I'm using takes a screenshot (without the cursor), and reads colour from that.
My Current Code:
public static Color RetrieveColour(Point Coordinates)
{
//Use this 'image' to create a Graphics class.
using (Graphics Destination = Graphics.FromImage(ScreenPixel))
{
//Creates a graphic from the specified handler to a window.
//In this case, it uses a handler which has been initialised to zero.
using (Graphics Source = Graphics.FromHwnd(IntPtr.Zero))
{
//Handler from the source device context.
IntPtr HandlerSourceDC = Source.GetHdc();
//Handler to the destination device context.
IntPtr HandlerDC = Destination.GetHdc();
//BitBlt is responsible for doing the copying.
//Returns a non-zero value for upon success.
int retval = BitBlt(HandlerDC, 0, 0, 1, 1, HandlerSourceDC, Coordinates.X, Coordinates.Y, (int)CopyPixelOperation.SourceCopy);
//Release the handlers.
Destination.ReleaseHdc();
Source.ReleaseHdc();
}
}
//Retrieve the colour of the pixel at the specified coordinates.
return ScreenPixel.GetPixel(0, 0);
}
I should probably add, it should work with non-Windows cursors. By this I mean custom cursors from other applications (if that has any bearing on future answers).