Page 1 of 1

using DrawText to display an int?

PostPosted: Feb 20, 2004 @ 7:40am
by Volte6

PostPosted: Feb 20, 2004 @ 8:29am
by Johan

PostPosted: Feb 20, 2004 @ 2:21pm
by Layre5150
You could use "sprintf" or _stprintf (for TCHARs). Something like:

TCHAR sString[64];
_stprintf( sString, _T("FPS=%i"), iFramesPerSecond );

or for floats:

_stprintf( sString, _T("FPS=%.2f"), fFramesPerSecond );

There are also functions such as _fcvt (which converts a floating point to a string) and _itoa() which converts an integer to a string.

PostPosted: Feb 20, 2004 @ 4:43pm
by mlepage

PostPosted: Feb 20, 2004 @ 5:26pm
by Volte6

PostPosted: Feb 20, 2004 @ 6:03pm
by fzammetti
Strings actually bugged me a bit when I started C as well. Here's four things to remember that will probably make your life easier... they are things that have either bitten me at one time or another or that I've seen asked a number of times...


(1) You will want to use TCHAR's for PocketPC development most of the time because of it's unicode nature, and the functions that operate on these begin with _tcs (there could be a couple of exceptions, but this is a good starting point when your looking through the docs). The nice thing about this is that, assuming you use the TEXT("") macro (or _T I think is the same), your code will compile on the desktop and PocketPC without any problems.

(2) Remember that a TCHAR, or any other string for that matter, is just an array of some data type underneath it all. You can always do things like:

TCHAR myStr[25] = TEXT("My String");
someVar = myStr[5];

(3) ALWAYS remember to terminate your strings properly with \0! My understanding is that most if not all of the _tcs functions do this for you, which means you'll have to remember it when you size your strings, but if there's any doubt, do it yourself! You'd be surprised how many times this will save you hours of debugging, especially if your accessing the strings as an array in loops and such,

(4) Most of the time when you are calling on a function that accepts a TCHAR as an argument, you usually just pass the variable like so:

TCHAR myStr[25] = TEXT("My String");
someFunction(myStr);

But sometimes you'll find that won't compile. If it won't, try this:

someFunction(&myStr[0]);

That may save you some time one day when something isn't compiling properly, it's happened to me a number of times.


Hope this all helps!

PostPosted: Feb 20, 2004 @ 9:16pm
by mlepage
Or, forget everything fzammetti just said and use the tstring typedef above. It's a std::string that uses _TCHAR as its character. It avoids all of the C-string hassles and works on PC and Pocket PC.

PostPosted: Feb 20, 2004 @ 9:20pm
by fzammetti

PostPosted: Feb 20, 2004 @ 9:20pm
by Volte6