Jump to content
  • Advertisement
Sign in to follow this  

Help with win32 TextOut

This topic is 5046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can you output an integer with TextOut? It takes in char* but I dont know how to convert an int to a char. I tried messing with itoa but i couldn't get it to print out a straight int it wants a radix to make it like hex and all that crap.

Share this post

Link to post
Share on other sites
hey, i should be able to help.
as far as i know, you have to format the string in a way that it will recognize the integers. to do this you need a string variable (char array), and integer variable(s).
to get the string to have integers in it, you must call sprintf (i'm sure there are other functions as well but this is what i have used).
here's how:

//assume HDC hdc, int x, y have all been declared...
char str[35]; //a string of 10 characters
int num1, num2; //two integers

num1 = 5; //set num1 to = 5...
num2 = 20; //set num2 to = 20...

//this is the important part:
sprintf(str,"Integer 1= %d, Integer 2= %d", num1, num2);
/*basically, when you want to put an int in, place %d, then
after the string ("...") put in the integer variables, in order
as they would appear in the string (num1 will go where the first
%d is, num2 at the second %d...*/

TextOut(hdc,x,y,str,strlen(str)); //output the text wherever like normal

ok, that's it. that should work for you :)
later, the_moo

Share this post

Link to post
Share on other sites
The radix is just the base of a number. To put out binary, the radix would be two, for decimal (as Goten explained) the radix would be 10, for hexadecimal, the radix would be 16, etc. Example
char chrOut[10];
TextOut(hdc, x, y, itoa(intSomething, &chrOut, 10) ); //Remember, itoa returns the pointer to the output buffer
And you can change text color and all of that with the other GDI functions on Microsoft MSDN
( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_9r77.asp )

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!