background color

This is a discussion on background color within the Tech Board forums, part of the Community Boards category; i am looking for a program that will report to me the background color of any pixel on the screen, ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    background color

    i am looking for a program that will report to me the background color of any pixel on the screen, so like if i was hovering my mouse over a picture it would tell me the color of the pixel that the mouse was currently sitting over...

    anyone know of such a program? i have seen one before, but dont know where to get it
    My Website

    "Circular logic is good because it is."

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,904
    whee, you need the code for it?

    Check out my runescape miner program in my portfolio:
    http://thejefffiles.com/portfolios.php?name=jverkoey
    direct link:
    http://thejefffiles.com/downloadfile...ScapeMiner.zip

    the code is in editmain.cpp in the source code

    here's the code so you don't have to search for it
    Code:
        // Grab the display's rendering context
        HDC hDC;
        hDC = CreateDC("DISPLAY",0,0,0);
        // Cursor position, wheee
        POINT Cursor;
        GetCursorPos(&Cursor);
        // It's stored as RGB or BGR or something, slipping my mind right now
        COLORREF color;
        color=GetPixel(hDC,Cursor.x,Cursor.y);
        // Clean up, yaay!
        DeleteDC(hDC);
        
        
        // Outputting junk for the win32 box...
        char Text[128];
        sprintf(Text,"#%x",color);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELCOLORHEX), Text);
        
        sprintf(Text,"%d",color>>16);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELCOLORB), Text);
        
        sprintf(Text,"%d",(color>>8)&0xFF);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELCOLORG), Text);
        
        sprintf(Text,"%d",(color)&0xFF);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELCOLORR), Text);
        
        sprintf(Text,"%d",Cursor.x);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELX), Text);
        
        sprintf(Text,"%d",Cursor.y);
        SetWindowText(GetDlgItem(hwnd,IDC_PIXELY), Text);
    Have fun dissecting that, it's not too tough, really all you need is the first block of code

    -edit-
    yah, it's stored as BGR in the hex value
    Last edited by jverkoey; 07-21-2004 at 01:57 AM. Reason: damn WYSIWYG lied to me, AGAIN!!

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    #include <windows.h>
    #pragma comment(lib, "gdi32.lib")
    #pragma comment(lib, "user32.lib")
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE reserved, LPSTR lpCommand, INT nCmdShow)
    {
    	MSG      msg         = { 0 };
    	HWND     hwndEdit;
    	POINT    pt;
    	HDC      hdc;
    	COLORREF clr, clrOld = RGB(1,1,1);
    	TCHAR    buf[100];
    
    	if (!(hdc = GetDC(NULL))) return -1;
    
    	if (!(hwndEdit = CreateWindowEx(0, TEXT("EDIT"), TEXT("ColorHack"),
    	                                WS_OVERLAPPEDWINDOW | WS_VISIBLE | ES_READONLY,
    	                                0, 0, 200, 90,
    	                                NULL, NULL, hInstance, NULL))) return -1;
    
    	SetWindowPos(hwndEdit, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    	SetWindowText(hwndEdit, TEXT("Hold down H to activate!"));
    
    	while (TRUE)
    	{
    		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    
    		if (!IsWindow(hwndEdit))
    		{
    			break;
    		}
    
    		if ((GetAsyncKeyState('H') & 0x8000) && GetCursorPos(&pt))
    		{
    			if ((clr = GetPixel(hdc, pt.x, pt.y)) != CLR_INVALID &&
    			    clr != clrOld)
    			{
    				clrOld = clr;
    				wsprintf(buf, TEXT("%02x%02x%02x"), 
    				                GetRValue(clr), GetGValue(clr), GetBValue(clr));
    				SetWindowText(hwndEdit, buf);
    			}
    		}
    
    		Sleep(20);
    	}
    
    	return 0;
    }
    Attached Files Attached Files

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try out Pixie.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 07:23 PM
  2. Windows background color
    By Exile in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2005, 07:55 AM
  3. Setting the background color of my main window
    By Garfield in forum Windows Programming
    Replies: 5
    Last Post: 07-07-2002, 12:25 AM
  4. Text and background Color
    By Goof Program in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-29-2002, 06:59 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21