Jump to content
  • Advertisement
Sign in to follow this  
mrtie_dye

DrawText

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

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

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!