Thread: Finding the color of any pixel on screen

  1. #1
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105

    Finding the color of any pixel on screen

    I need to find the color of any/all pixel/s on the screen. The code I got so far seems to do that but it doesn't get the pixel of my game window (another program, direct draw window app).

    Here is the code...

    Code:
    POINT pt;
    GetCursorPos(&pt);		
    		
    HDC hdc = GetDC(0);
    	
    COLORREF pixel = GetPixel(hdc, pt.x, pt.y);
    
    ReleaseDC(0, hdc);
    
    cout << " red: " << (int)GetRValue(pixel)
           << " green: " << (int)GetGValue(pixel) 
           << " blue : " << (int)GetBValue(pixel) << '\n';
    The idea of the program is to place the cursor over some color and the program will show you the values for that color.
    Last edited by Kirdra; 11-09-2007 at 01:18 PM. Reason: fixed something

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    HWND 0 is the desktop window, every program has its own seperate window(s) handle(s). You will have to use the HWND of your programs window.

  3. #3
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    Quote Originally Posted by abachler View Post
    HWND 0 is the desktop window, every program has its own seperate window(s) handle(s). You will have to use the HWND of your programs window.
    I want to get the pixels from the entire screen not just a window.

    edit:

    I've discoverd that if i check the same spot hundreds of times sometimes it will show the color, so i guess it must have something to do with the game erasing with frame with black.
    Last edited by Kirdra; 11-09-2007 at 01:50 PM. Reason: adding on

  4. #4
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Yes, thats an outdated method but still in common use. Personally I 'erase' the window with the new picture. Improves performance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. finding the screen coordinates of a pixel
    By ShadowBeast in forum C# Programming
    Replies: 7
    Last Post: 04-27-2007, 05:42 AM
  2. Getting Pixel Colour Screen
    By god_of_war in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2006, 01:17 PM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM