Anyone have some code to tell what is the pixel color under the cursor?
Printable View
Anyone have some code to tell what is the pixel color under the cursor?
Hi,
You can do the following to know what is the pixel color under the mouse cursor.
1.Get the cursor location using API GetCursorPos. Remember this is in screen coordinates. You need to convert it to client window coordinates using API ScreenToClient
2.Get a handle to the device context for this window which has the cursor contained in it. (you can use WindowFromPoint ChildWindowFromPoint for this)
3.Get a handle to a device context, and then use the API GetPixel
I think this should solve the problem.
Regards
Saurabh
POINT pt;
GetCursorPos( &pt );
HDC sdc = GetDC( 0 );
COLORREF color = GetPixel( sdc, pt.x, pt.y );
ReleaseDC( 0, sdc );