Sign in to follow this  

Help with win32 TextOut

This topic is 4736 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

This topic is 4736 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this