DrawText
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?
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);
sprintf(text,"%d",xcord);
Is sprintf a console only function? When I put this line in my Win32 application, it crashes.
I am not that familiar with sprintf. Where does text come from? I just made a pointer to char called text to pass in.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement