So what's wrong with remembering where you last drew the pixel, rather than trying to find it again sometime later.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Once of the biggest problems you are going to face... is how yellow is yellow? From this site alone I pulled up 7 different values of "yellow". So how yellow is your slider bar's yellow.... is it pure 255, 255, 0? I've got some basic code that will retrieve the pixel color under the mouse, which needs to modified to include a for loop for your x coordinate, a modified number for the y coordinate, and a pretty good value for yellow. You could certainly make it scan for a range of "yellow values" say between 170 to 255 red, 170 to 255 green and 0 to like 100 blue, but with ranges like that you start to significantly increase your possibility of false positives.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
> It's a slider that the user slides
But this doesn't happen by magic.
Somewhere along the line, the mouse/key press has to be interpreted by some software into drawing the slider in the new position. Chances are, your software was involved.
If this is some kind of GUI tool, then for sure it will have a method called "getPosition" which you can use to find out what the user did, without you having to go grubbing around in the pixels.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
You might need to modify the constants a little, because the color you gave me isn't yellow at all.... it seems more like diarrhea orange (sorry for that). Anyway, this code works for me on windows XP Sp2, Code::Blocks IDE wth Mingw. It is overly commented for your sake, and a little untidy... but I'm sure you can handle it.
#include <iostream>
#include <cstdio>
#include <windows.h>
using namespace std;
int main(int argc, char **argv)
{
// Device Context, Point Struct, and Color Struct
HDC hDC = GetDC(HWND_DESKTOP);
POINT pt;
COLORREF rgb;
// Numbers To Compare Against
const int CMP_R = 214;
const int CMP_G = 186;
const int CMP_B = 99;
// Values As byte
BYTE rVal;
BYTE gVal;
BYTE bVal;
// Same Values As Integers
int red;
int green;
int blue;
// Set This To Your Known Y Coord.
// Pretty Sure 0,0 Is Top Left
// Corner Of The Monitor.
pt.y = 100;
// Loop To 3000... Adjust For Higher
// Resolution (Really?)
for (int i=0; i < 3000; i++) {
pt.x = i; // Next Pixel
// Moving From The Left To The Right,
// Get The Pixel
rgb = GetPixel(hDC, pt.x, pt.y);
// Save Pixel Color In Byte Values
// This Step Might Not Be Necessary..
// Coult Probably Get It As An Int
rVal = GetRValue(rgb);
gVal = GetGValue(rgb);
bVal = GetBValue(rgb);
// Save Pixel Color As Decimal
red = (int)rVal;
green = (int)gVal;
blue = (int)bVal;
// Do All The Colors Match Our Control
// Constants?
if (red == CMP_R && green == CMP_G && blue == CMP_B) {
cout << "Found At: " << endl;
cout << "X: " << pt.x << " Y: " << pt.y << endl;
}
}
return 0;
}
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Don't use GunBound's handle. What I've found is that as long as the window is active on the screen HWND_DESKTOP will work for sub-windows too. In fact, to test it (the code as posted), I opened ms paint, drew a box and colored it with the paint fill thing. Then I moved the window so that it was at YPos 100, and run the app. It found it at the appropriate position. Have you tried it just as it is?
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215