Unicode in MessageBoxW

Started by
6 comments, last by taby 15 years, 9 months ago
I'm trying to do localization stuff, I pull a unicode string (currently in Russian) out of a file, and I try to do something with it:

const wchar_t * theString = TextManager.Get("ERROR_MSG");

MessageBoxW(gHWND, theString, theString, MB_OK);
The message box that comes up has a series of boxes in it (signifying unrecognized characters). I have russian installed on my machine, and I can type in russian into the text database files. The strings will display in-game with the text-renderer, and if I copy-paste the hex into a word document it displays correctly. Sadly I need this to work outside the renderer because the message may be 'We could not create the renderer' (equivalent). I suspect I'm missing something obvious.
Geordi
George D. Filiotis
Advertisement
Is russian supported by whichever font MessageBox uses? (Which is the default Windows font, I guess)
That strikes me as very likely, I assume that on a target machine which is actually operating in russian, I can expect that the Cyrillic character set would be present.

Any idea how I can install the extra characters on my local machine as a sanity check?
Geordi
George D. Filiotis
If you have Russian installed as one of the Regional and Language Options, and not just a Russian Font, it should just work if you're using unicode.

The only other thing I can think of is if you didn't actually save the actual C++ file in a Unicode format. Or, if you don't have the actual program supporting Unicode. That would pretty much revert to ASCII, causing the boxes.

I'd suggest keeping with MessageBox, rather than using MessageBoxW, as it should wrap the correct function according to the character set supported by your program.
As Nytegard said you shouldn't need to use MessageBoxW() you should just use MessageBox() and with _UNICODE and UNICODE preprocessor defines it will chose the correct one. That also ensures your program is unicode.
But he's using wchar_t rather than TCHAR.

If you want to be able to toggle Unicode on and off, you're right, he should use MessageBox() (and TCHAR).
But if he just wants to use Unicode, period, he might as well be explicit about it, and use wchar_t (as he does) and MessageBoxW().
It looks like your using c++. With the MessageBox function I have always seen it set to NULL, I guess you could probably using zero(0) too. I'm talking about the first parameter of MessageBox, so something like this
MessageBox(NULL, theString, theString, MB_OK);


I think the NULL is used to represent the desktop window.
** boolean010 **
Quote:Original post by boolean010
I think the NULL is used to represent the desktop window.


Coincidentally, yes. From winuser.h:

#define HWND_DESKTOP ((HWND)0)

This topic is closed to new replies.

Advertisement