Help with win32 TextOut

Started by
2 comments, last by deadimp 19 years, 3 months ago
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.
-Goten
Advertisement
itoa with a radix of 10 will convert the int to a decimal number.
Ra
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 charactersint num1, num2; //two integersnum1 = 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, thenafter the string ("...") put in the integer variables, in orderas 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
the_moo
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 )
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement