DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: C++ Help  (Read 6,602 times)

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
C++ Help
« on: February 13, 2010, 02:30 AM »
Alright so here it goes... I've been experimenting with creating macros based on pixel color changes... I'm not understanding why GetPixel() is returning 0 constantly when I have the target game open... I can see the cursor coordinates, but not the color value... What am I doing wrong? I need to find the color of the pixel underneath the cursor while in a full screen game window.

Here is my example I wrote in a couple minutes to output coordinates and color:

Code: (c++)
//------------------------------------------------------------------------------
#include <windows.h>
#include <iostream>
//------------------------------------------------------------------------------
using namespace std;
//------------------------------------------------------------------------------
int main(void)
{
	HWND wowHandle = FindWindow(NULL, "World of Warcraft");
	if(!wowHandle)
	{
		cout << "WoW is not open atm..." << endl;
		system("pause");
		return 0;
	}
	else
	{
		cout << "WoW is OPEN..." << endl;
		ShowWindow(wowHandle, SW_SHOWNORMAL);
		SetForegroundWindow(wowHandle);	
		
		while(1)
		{
			POINT cursorPoint;
			GetCursorPos(&cursorPoint);
			COLORREF color = GetPixel(GetDC(wowHandle), cursorPoint.x, cursorPoint.y);
			system("cls");
			cout << "(" << cursorPoint.x << ", " << cursorPoint.y << ")" << endl;
			cout << "COLOR: " << color;
		}	
	}
	
}
//------------------------------------------------------------------------------

it's probably sloppy... don't hate on the 5 minute "im at work and in a hurry on my break" coding...
CodeByter.com - http://www.codebyter.com

Codebyte

  • "Premature Optimization is the root of all evil."
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 160
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Plugin Coding Medal
Re: C++ Help
« Reply #1 on: February 13, 2010, 02:53 AM »
nevermind... after doing some research I figured out that gameguard blocks the API calls and filters what is returned... this would make sense as to why its returning 0 for a color call...
CodeByter.com - http://www.codebyter.com

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: C++ Help
« Reply #2 on: February 13, 2010, 04:47 AM »
nevermind... after doing some research I figured out that gameguard blocks the API calls and filters what is returned... this would make sense as to why its returning 0 for a color call...
I'd be a bit surprised if GetPixel worked, GameGuard/whatever or not, as soon as you're dealing with Direct3D (and possibly even DirectDraw) accelerated games.
- carpe noctem

Original address: https://www.donationcoder.com/forum/index.php?topic=21721.0