Thread: Need a little help with GetPixel()

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Need a little help with GetPixel()

    Hi I am trying to experiment with GetPixel() to see if I can get a color output. So far this is my code:

    Code:
    #include <iostream>
    #include <Windows.h>
    
    using namespace std;
    
    int main()
    {
        COLORREF lcolor = 0;
        int lx = 653, ly = 347;
    
        HWND hwnd = FindWindow(0, L"Hearts");
        HDC hdc = GetWindowDC(hwnd); 
    
        Sleep(5000); 
    
        lcolor=GetPixel(hdc,lx,ly);
    
        int r = GetRValue ( lcolor );
        int g = GetGValue ( lcolor );
        int b = GetBValue ( lcolor );
    
        cout << r << endl;
        cout << g << endl;
        cout << b << endl;
    
        return 0;
    }
    Need a little help with GetPixel()-screen-jpg

    As you can see I am trying to get different color values from the Hearts game included in Windows 7. However, whenever I run my program, I always get RGB values such as 255 255 255 for red, green, and blue respectively. With the coordinates x = 653, y = 347, certainly it would be very hard to miss the large mass of green in the background.

    What am I doing wrong? Thank you for your time.

    NOTE: The 5 seconds delay is to give me time to switch to the Hearts program in full screen.

    IDE used is Visual Studio 2010. OS is Windows 7.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Looking at the the docs, sounds like you're getting CLR_INVALID. It sounds like there could be a couple things (need to be in a clipping region, need to be in a bitmap).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetPixel tolerance
    By JordanCason in forum C++ Programming
    Replies: 8
    Last Post: 12-06-2007, 11:47 PM
  2. Need Help With GetPixel
    By Anddos in forum Windows Programming
    Replies: 1
    Last Post: 08-19-2006, 05:08 PM
  3. GetPixel()
    By thedoofus in forum C Programming
    Replies: 1
    Last Post: 04-30-2006, 08:40 PM
  4. SDL getPixel
    By Nova_Collision in forum Game Programming
    Replies: 1
    Last Post: 02-10-2003, 11:34 PM
  5. GetPixel return value
    By Garfield in forum Windows Programming
    Replies: 7
    Last Post: 11-14-2001, 01:18 AM