CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    pixel under cursor?

    Anyone have some code to tell what is the pixel color under the cursor?


  2. #2
    Join Date
    May 1999
    Posts
    12

    Re: pixel under 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




  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: pixel under cursor?

    POINT pt;
    GetCursorPos( &pt );
    HDC sdc = GetDC( 0 );
    COLORREF color = GetPixel( sdc, pt.x, pt.y );
    ReleaseDC( 0, sdc );


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured