From: Steve Jones on
I've just inherited an MFC program which was created with MBCS project
setting.

There is now a requirement for a string provided from an external source in
UTF-8 format to be displayed by the program in a CStatic control. The string
may contain Japanese characters so these need to be displayed correctly.

How can I do this?

If one solution is to recompile the whole program with UNICODE support, I'd
rather avoid doing that in this case as I am still unfamiliar with the
source code and it's likely that lots of things will break.

From: David Wilkinson on
Steve Jones wrote:
> I've just inherited an MFC program which was created with MBCS project
> setting.
>
> There is now a requirement for a string provided from an external source
> in UTF-8 format to be displayed by the program in a CStatic control. The
> string may contain Japanese characters so these need to be displayed
> correctly.
>
> How can I do this?
>
> If one solution is to recompile the whole program with UNICODE support,
> I'd rather avoid doing that in this case as I am still unfamiliar with
> the source code and it's likely that lots of things will break.

Steve:

Just use MultiByteToWideChar() to convert from UTF-8 to UTF-16, and then use
SetWindowTextW(). You will need a font that is capable of displaying Japanese
characters.

--
David Wilkinson
Visual C++ MVP
From: Steve Jones on

"David Wilkinson" <no-reply(a)effisols.com> wrote in message
news:%23dm1oxD9KHA.3276(a)TK2MSFTNGP02.phx.gbl...
> Just use MultiByteToWideChar() to convert from UTF-8 to UTF-16, and then
> use SetWindowTextW(). You will need a font that is capable of displaying
> Japanese characters.

Thanks David. So I guess I would specify CP_UTF8 as the codepage in the
MultiByteToWideChar() call.

The CStatic in question does not seem to have any font assigned to it in the
program, so I assume it is using the Windows default (isn't that something
like MS Sans or Segoe?). Is the windows default font able to display all of
the unicode characters? Or do some countries get different default fonts
which only contain a subset of all the unicode characters - and if so what
would get displayed if the characater was not available in the current
county's default font?

From: David Lowndes on
>Thanks David. So I guess I would specify CP_UTF8 as the codepage in the
>MultiByteToWideChar() call.

Yes.

You may find the CA2WEX wrapper makes the code easier - and you can
specify the code page with that.

>The CStatic in question does not seem to have any font assigned to it in the
>program, so I assume it is using the Windows default

I think it'll be whatever is the default system font.

>Is the windows default font able to display all of
>the unicode characters?

I doubt it.

>Or do some countries get different default fonts
>which only contain a subset of all the unicode characters

I believe so.

>and if so what
>would get displayed if the characater was not available in the current
>county's default font?

I think it depends on the version of the OS. I believe newer versions
of Windows jump through hoops to try to use a font that would display
the characters.

Dave Lowndes
From: Mihai N. on

> I think it depends on the version of the OS. I believe newer versions
> of Windows jump through hoops to try to use a font that would display
> the characters.

This is indeed the case.
It is more and more difficult to get "squares" (missing glyph)
Still possible, but for Japanese you should be safe :-)


--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email