This site is no longer active and is available for archival purposes only. Registration and login is disabled.

using DrawText to display an int?


using DrawText to display an int?

Postby Volte6 » Feb 20, 2004 @ 7:40am

User avatar
Volte6
pm Member
 
Posts: 77
Joined: Feb 16, 2004 @ 8:14pm


Postby Johan » Feb 20, 2004 @ 8:29am

Johan Sanneblad, M.Sc, Ph.D
GapiDraw Systems Architect
[]
User avatar
Johan
pm Member
 
Posts: 1843
Joined: Jan 12, 2002 @ 12:38pm
Location: Sweden


Postby Layre5150 » Feb 20, 2004 @ 2:21pm

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.
Layre5150
pm Member
 
Posts: 21
Joined: Feb 13, 2004 @ 5:17pm


Postby mlepage » Feb 20, 2004 @ 4:43pm

www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby Volte6 » Feb 20, 2004 @ 5:26pm

User avatar
Volte6
pm Member
 
Posts: 77
Joined: Feb 16, 2004 @ 8:14pm


Postby fzammetti » Feb 20, 2004 @ 6:03pm

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!
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby mlepage » Feb 20, 2004 @ 9:16pm

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.
www.scalenesoftware.com
Great games for your Palm and Pocket PC!
User avatar
mlepage
pm Insider
 
Posts: 1050
Joined: Aug 3, 2003 @ 4:47am
Location: Canada


Postby fzammetti » Feb 20, 2004 @ 9:20pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Volte6 » Feb 20, 2004 @ 9:20pm

User avatar
Volte6
pm Member
 
Posts: 77
Joined: Feb 16, 2004 @ 8:14pm


Return to GapiDraw


Sort


Forum Description

The Cross-platform Graphics SDK for Palms, Pocket PCs, Symbian Devices, and Stationary PCs.

Moderators:

sponge, Johan

Forum permissions

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 post attachments in this forum