As you have found, GetPixel is slow and calling it multiple times is not desperately efficient. You can, however, use BitBlt to copy information from the desktop DC to a DC under your control where you can read the pixel data much more quickly (in .NET the same functionality is offered by Graphics.CopyFromScreen()).
Hey guys, I need a function designed to return a const char* from a string designed by the user. Rough example:


Code:

const char *bufit(std::string str) {
  return str.c_str();
}


Essentially, i need to convert something like this:

Code:
"(" .. PLoc[0].Loc.x .. "," .. PLoc[0].Loc.y .. ")"

in a line like this:

Code:
SetDlgItemText( hWnd, 1011, (LPCWSTR) bufit(coordinate_line));

PLoc = Pixel Location
.Loc = point (x and y integers)
.Now = RGB (3 integers) representing the current color
.Was = RGB (3 integers) representing the previous color

SetDlgItemText() is a c++ Win32 API command to alter the text of a child window (in this case, the button marked with 1011, or the button used to change the coordinates via mouse location)

(LPCWSTR) is the conversion method necessary to send the const char pointer to a WIDE child window (the button we made)

If i were using an std::string, i could convert it by coordinate_line.c_str(), but I'm trying to figure out if there's a cleaner way to do this.

If i use the char[] the way i know how, there's room for error when the coordinates are shorter (<1000) than assumed, and empty spaces are added at the end... don't want that XD

Just figured there would HAVE to be some way to make the function convert the bits of code without much hassle, and with 100% accuracy?
Casting to LPCWSTR does not perform any string "conversion" (it's a basic C-style cast), it just casts from one pointer type to another (the string data being pointed to doesn't change).

Are you sure you know what the difference between "wide" (Unicode) and ANSI strings are?

If you're going to use the "wide" SetDlgItemText (which I would recommend) when use a std::wstring ("wide" string) instead of std::string. To pass wide string data to a function that expects a pointer to NUL-terminated character data (a "C string") use its c_str member. As you would be explicitly using wide strings in your code I would then recommend using SetDlgItemTextW explicitly, too.

As for actually building a string up from component parts goes, if you're using C++ you may as well use wstringstream:


Code:
// Coordinates:
int x = 12, y = 34;

// Use a wstringstream to build up the desired string.
std::wstringstream coordinates;
coordinates << L"(" << x << L"," << y << L")";

// Printing the resulting wstring (C++)
std::wcout << coordinates.str() << std::endl;

// Using the .c_str() method to retrieve a "C-style" string for use with printf.
wprintf_s(L"%s\r\n", coordinates.str().c_str());


Disclaimer: I'm not a C++ programmer, but I'm just looking through the documentation on MSDN. Someone feel free to correct me. Wink
Here's the complete code:

http://cemetech.pastebin.com/BRCZ28wN

line 148: if (Running) { Cycle(); }

I need a better place for this code, it doesn't update fast enough >.<

update: I've tried several different locations under several different circumstances. It appears to me that it has to be around where its at. If it isn't in that while-loop, it doesn't execute EVER... But if it is, it only updates when the program receives a msg (event).

So the question at hand is, how do i get the program to run a main loop continuously without locking up the application (run loop based on frame or seconds?). In VB this would be cured by making a TIMER object.

update: Got it... You have to draw a timer in the WM_CREATE case using
Code:
 SetTimer(hWnd, 1, 100, NULL);
and then create a WM_TIMER case for the loop function :3 YAY...

Next I'll be trying to generalize the RGB color and output a name so instead of asking if it changes, i can ask it if its blue, black, or etc... Shouldn't be more than dividing the 255 to get fewer color variations, then mapping out the remaining combination's as colors... not hard, keeping an ear out for an easier method.

----
Decided to check the color of the bar and inspect the blue color value closely... then count how much of the bar's blue value is higher than 40, and how much is darker, then retrieve a % value... Problem is, the text in the center is white, and sometimes a tool-tip box will cover the xp bar making it darker than 40 (grey).. both of these combined throw the % off by about 1%... that's not that bad at first, but combined with the Time Till you Level formula, it just constantly stays at like, 5 minutes till level, when in reality, it took about 45 minutes... Now I need to either strip the % directly out of text, or find a 100% accurate way of registering the experience bar.
Progress update!!!
I decided to make a COLORREF double array in a header to pre-define what each number looks like, then run a color-comparison with coordinates based off of the decimal location.

full screen shot: http://img600.imageshack.us/i/shiayass.png/

assuming the window is [800,600] + window size (8, 34) get the decimal found at 187, 624
* window size adjusts for people playing on alternate OS's or alternate themes and is automatically obtained by GetWindowRect()
* the % is written Left Justified, so any percent >= 10, decimal is at (187,624), and < 10, decimal is at (194,624)

then record the numbers necessary

now match to predefined sprites in a header, decide best match by color difference - sqrt( (r2-r1)^2 + (g2-g1)^2 + (b2-b1)^2 ) - and then we have a number for each value in the %, simple math turns this into TO.D (22.1)

Right now I'm trying to configure the program... People like playing in different resolutions. The font of the % is always left justified and always the same sprites used (they don't get bigger or smaller). I need to figure out the location of these decimals... I have thought about looking for (255,255,255) pixel with non-greyscale colors touching around the approximate area... but its not quite working out =.= Any help on this would be greatly appreciated!

The formula was stripped, fixed, and put back in. the numbers dealing with the %'s are now floats, rather than ints, allowing for decimals (yay), it records 10 numbers spanning over 2.5 minutes (every 15 seconds) and then decides how quickly (or slowly) your actually leveling. This is accurate only as long as you make kills every 2 minutes, running around for mobs for 2.5 minutes will result in the meter determining "infinite" time required to level, or only gaining 0.1% will likely result in ">1 days" to level, but generally it splits it into hours or minutes.

With this formula, i need to figure out the best time-frame and a modified formula... Right now, it starts by registering the last non-nil value, tracks how many 0s it took to modify how much time were recording, and get the difference in exp from oldest recorded, to current exp, toss it through the formula to get % per minute, then minutes to level. It doesn't account for the ability to "lose" exp when dieing, or resetting when leveling (although 2.5 minutes into the new exp and it doesn't matter) But i find that some cases, i only kill 3 rather large mobs every 15 minutes, that's 1 per 5 =.= the estimated preferred time is 7 minutes, so I'll need to have this fixed before i can upgrade it.

ToDo:
> knowing the resolution, how do i find the decimal coordinates without pre-defining all of them?
> how do I account for loss of exp
> how do I register a level up to reset the stored values

Current source (expires March 02, 2011)
http://pastebin.com/1Yc9b2Hw
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement