Jump to content
  • Advertisement
Sign in to follow this  
vinb

How can I output the arrow characters using TextOut() ?

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

I would think this is a simple thing, but after an hour of searching Google, I haven't turned up anything. I made a snake game where the user presses the arrow keys to move the snake. I thought it would be nice to TextOut() the message: "Press the arrow keys to move the snake" and I wanted to display the 4 arrows. As I said, that was over an hour ago! It's a little thing, but it's really bugging me. Any help would be greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Why not just write up, down, left, right? If thats not what your looking for your going to make images of each key or all keys and draw them directly to the screen.

Share this post


Link to post
Share on other sites
Right. I understand there's a lot of alternatives. I guess I'm just being stubborn. Is there a unicode representation of the arrow characters?

Share this post


Link to post
Share on other sites
A lot, however, it depends on your specified font. I'll take the most popular font in Windows - Arial. Take a look at character map, the arrow characters are represented in 25B2, 25BA, 25BC, 25C4 Unicode.
I also remember in original DOS code page there're arrow characters.

Btw, are ^ v < > sufficient :) ?

Share this post


Link to post
Share on other sites
Very strange. I would expect the following code to print "!" to the screen, but it doesn't


char buffer[80];

sprintf(buffer,"\0x21"); // unicode for "!"

int len = (int)strlen(buffer) ;
int x = (WINDOW_WIDTH /2) - (len * 4);
int y = WINDOW_HEIGHT/3;
TextOut(hdc,x,y,buffer,len);


Instead it prints nothing. What am I missing?

Share this post


Link to post
Share on other sites
Both of the following strings work in one of my programs:

tempString += L'ø';
tempString += 0xF8;

For the first, I just copied the ø character into my source code from Windows' character map. Note that the second line is a piece of data, not a string - try removing the quotes around 0x21 in your code.

Share this post


Link to post
Share on other sites
I started this day feeling fairly intelligent. That feeling has long passed. The first method of copying and pasting the special character worked, but TextOut requires a const char* and 0xF8 apparently is an int. I tried various things to beat it into submission but to no avail. Could I trouble you for a more complete code example? An example printing the arrow characters would be even better.

Thanks for the responses.

Share this post


Link to post
Share on other sites
Quote:
Original post by vinb
Very strange. I would expect the following code to print "!" to the screen, but it doesn't

*** Source Snippet Removed ***
Instead it prints nothing. What am I missing?


Your escape sequence isn't correct. \0 evaluates to a NUL (character value 0), which represents the end of a string in C-style strings and C++ string literals. So the x21 is in the string, but it's interpreted as actual "x21" characters, and it's after the null terminator, so it will never appear.

The escape sequence should be \x21 - \x indicates a hex representation of a literal character value.

Share this post


Link to post
Share on other sites
Aha! It works. But I fear I'm not going to be able to do what I originally set out to do, which was print the arrow characters. I would like to print \x206D (the up arrow) and I'm getting this error:

error C2022: '8301' : too big for character

Is there some conversion function that I can use to feed sprintf()?


Share this post


Link to post
Share on other sites
Unicode requires two bytes per character, unlike ASCII which uses one byte. 0x206d is larger than 0xff (255) which is the highest possible value you can store in one byte.

What you need (to print multi-byte characters, anyways) is a wide string, which means the bulk of your program will have to be modified to use Unicode. That's a bit extreme.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!