I have this piece of code
// some function
int px;
void SomeFunction( void *dummy )
{
...
RECT rect;
GetWindowRect(hWnd, &rect);
px = ((rect.right - rect.left) / 2) - 60;
...
// Terminate thread
_endthread();
}
And my problem is px doesn't get assigned.. it stays 0.. although in the debugger I can see all the values inside rect..
please help me
What about if you change px from int to long? Does that give you any differemt results?
The thing to take note of here is that px is currently declared as an int. Whereas rect.right and rect.left are both LONG/long variables.
Therefore if the result of your calculation is less than 1.0 (e.g. something like 0.43455664), then because px is an int, the calculated value will be truncated to 0.
Whereas if you alter px to be long, you'll get the actual calculated value (in my example 0.4345564).
I could be wrong, but that looks like the most obvious explanation to me!
oh, hang on.....Looking at that code, another thing strikes me as odd....
px is declared outside of the function, but used inside it..
That's probably your problem right there!
The px used in the function and the px outside of the function might not be the same variable, they might have different scope.
If you could post some more code, we might be able to determine whether or not this is the case!
Cheers for now,
Jas.