DrawText

Started by
2 comments, last by CodeEnthusiast 19 years, 4 months ago
Is there a way to make this work, assuming that xcord is an integer value, and you want it to print that value, not it's character equlivent? DrawText(hdc, xcord, -1, &aRect, DT_SINGLELINE|DT_CENTER|DT_VCENTER); edit: Or, any other way to output a integer to the screen in a win32 app?
Marriage is the #1 cause of divorce
Advertisement
If you're trying to print an integer to the screen through DrawText, you could simply use the sprintf function to look something like this:
sprintf(text,"%d",xcord);
Is sprintf a console only function? When I put this line in my Win32 application, it crashes.

Quote:
sprintf(text,"%d",xcord);


I am not that familiar with sprintf. Where does text come from? I just made a pointer to char called text to pass in.
Marriage is the #1 cause of divorce
The reason it crashes is because you're probably using LPSTR (or a pointer to a char). You could, however, use char text[100] for example. I'm not sure this is the best solution, but it works for me. It'd look something like:

char text[100];
int xcord = 5;
sprintf(text, "%d", xcord);
DrawText(hdc, text, -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

That's how I do it, but I just kinda started windows programming not to long ago, so I don't know if there is an alternate solution or not.

Also, make sure you include the string header file.
Quote:
so I don't know if there is an alternate solution or not


Doesn't matter. This works fine for what I need for. Just testing some values. I will remove this code later. Thanks so much. This was extremely helpful.
Marriage is the #1 cause of divorce

This topic is closed to new replies.

Advertisement