tags:

views:

200

answers:

1

I'm trying to read the pixel color of a given window. The window is not mine. The window may not have focus or be at foreground. I don't know if it matters, does it? I have the window handle, so I do:

  HDC hdc = GetDC(m_window);
  if (hdc) 
  {
    COLORREF color = GetPixel(hdc,x,y);

    if(color == CLR_INVALID)
    {
      wxLogDebug("COLOR DATA INVALID");        
    }
    else
    {
      wxLogDebug("COLOR DATA 0x%x", color);
    }

x and y are screen coordinates that lie inside the window. Don't know why this is not working. Any ideas?

+2  A: 

You should convert x, y into client coordinates with ScreenToClient Function.

Nick D
This sounds right. I know GetPixel returns `CLR_INVALID` if the pixel is clipped. If you've got the wrong coordinates, you're likely outside the clipping region for the window's client area.
Adrian McCarthy