From: Mihai N. on

> Thanks. That does seem to be the case. I have managed to solve the problem
> by creating a new control using ::RegisterClassExW() and
>::CreateWindowExW(), and setting its text with ::SetWindowTextW(hwnd,
> mywidestring). I also attached it to a CWnd for convenience - it seems that
> ANSI messages are automatically converted to UNICODE messages so it seems
OK
> to just use generic CWnd function names rather than the W-prefixed ones
> which would not compile in an ANSI program.

That is the right way. Basically the windows should answer "true" to
IsWindowUnicode, and to get that you have to create it as Unicode
(with the W version of the API).
You might still have some problems because the message pump is not Unicode
(for GetMessage there is a GetMessageW and a GetMessageA, same for
DispatchMessage with DispatchMessageW and DispatchMessageA)

If you consider moving the whole thing to Unicode, you might give a try
to this: http://mihai-nita.net/2007/12/19/tounicode-automating-some-of-the-
steps-of-unicode-code-conversion-windows/



> The text to be displayed could in fact be in any language and there is no
> way of knowing what that is - the program would just get presented with a
> UTF8 string. So I would really need a high degree of confidence that the
> text in whatever language would be displayed correctly.
>
> How can I know what font should be loaded based simply on the contents of
> the UTF8 string?

Don't bother, just go with Tahoma and let the system do the font fallback.

In general you can't determine the right from from the string content.
The same codepoints can represent Chinese Simplified, Chinese Traditional,
Japanese, or Korean (CCJK).
Same way as Latin 1 text might be French or German :-)
But the fonts for CCJK should be different. Can't use a Traditional Chiese
font for Simplified Chinese text (any native user is able to see the
differences and will (rightfully) complain.
It's another thing if you have language information.


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

From: Steve Jones on

"Mihai N." <nmihai_year_2000(a)yahoo.com> wrote in message
news:Xns9D7C999AFC73MihaiN(a)207.46.248.16...
> You might still have some problems because the message pump is not Unicode
> (for GetMessage there is a GetMessageW and a GetMessageA, same for
> DispatchMessage with DispatchMessageW and DispatchMessageA)

The doc for IsWindowUnicode suggests that this ought not to be a problem:
"The system does automatic two-way translation (Unicode to ANSI) for window
messages. For example, if an ANSI window message is sent to a window that
uses the Unicode character set, the system translates that message into a
Unicode message before calling the window procedure. The system calls
IsWindowUnicode to determine whether to translate the message."

> If you consider moving the whole thing to Unicode, you might give a try
> to this:
> http://mihai-nita.net/2007/12/19/tounicode-automating-some-of-the-
> steps-of-unicode-code-conversion-windows/

Thanks. I'll give that a try when time permits.

>> How can I know what font should be loaded based simply on the contents of
>> the UTF8 string?
>
> Don't bother, just go with Tahoma and let the system do the font fallback.

So if I set a particular font "Myfont" into my control, and THEN call
SetWindowTextW() to assign a UNICODE string which contains characters not in
the font - does Windows automatically select-out Myfont and select-in a font
it considers suitable? And does this happen repeatedly if I later call
SetWindowTextW again?

From: Joseph M. Newcomer on
See below...
On Tue, 18 May 2010 11:29:18 +0100, "Steve Jones" <nospam(a)devnull.com> wrote:

>
>"Mihai N." <nmihai_year_2000(a)yahoo.com> wrote in message
>news:Xns9D7C999AFC73MihaiN(a)207.46.248.16...
>> You might still have some problems because the message pump is not Unicode
>> (for GetMessage there is a GetMessageW and a GetMessageA, same for
>> DispatchMessage with DispatchMessageW and DispatchMessageA)
>
>The doc for IsWindowUnicode suggests that this ought not to be a problem:
>"The system does automatic two-way translation (Unicode to ANSI) for window
>messages. For example, if an ANSI window message is sent to a window that
>uses the Unicode character set, the system translates that message into a
>Unicode message before calling the window procedure. The system calls
>IsWindowUnicode to determine whether to translate the message."
>
>> If you consider moving the whole thing to Unicode, you might give a try
>> to this:
>> http://mihai-nita.net/2007/12/19/tounicode-automating-some-of-the-
>> steps-of-unicode-code-conversion-windows/
>
>Thanks. I'll give that a try when time permits.
>
>>> How can I know what font should be loaded based simply on the contents of
>>> the UTF8 string?
>>
>> Don't bother, just go with Tahoma and let the system do the font fallback.
>
>So if I set a particular font "Myfont" into my control, and THEN call
>SetWindowTextW() to assign a UNICODE string which contains characters not in
>the font - does Windows automatically select-out Myfont and select-in a font
>it considers suitable? And does this happen repeatedly if I later call
>SetWindowTextW again?
****
No.

Mihai has, in some past threads, described how the text name of certain fonts maps to the
text name of other fonts (e.g., the dialog fonts), through some esoteric magic. But once
that font is selected into the window, it stays forever. If you want to change it, you
have to change it yourself. In my Locale Explorer, I select "Arial Unicode MS" [or a very
similar name] as my font into controls that are expected to display full Unicode. This
font comes with the latest versions of Office, and is also downloadable from the Microsoft
site.
joe
****
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Mihai N. on
> The doc for IsWindowUnicode suggests that this ought not to be a problem:
> "The system does automatic two-way translation (Unicode to ANSI) for window
> messages. For example, if an ANSI window message is sent to a window that
> uses the Unicode character set, the system translates that message into a
> Unicode message before calling the window procedure. The system calls
> IsWindowUnicode to determine whether to translate the message."

True. But then the Unicode answer from the window might get converted back
to ANSI (think WM_GETTEXT), and that might damage some text.
It is a two-way translation, right?


> So if I set a particular font "Myfont" into my control, and THEN call
> SetWindowTextW() to assign a UNICODE string which contains characters
> not in the font - does Windows automatically select-out Myfont and
> select-in a font it considers suitable? And does this happen
> repeatedly if I later call SetWindowTextW again?

Yes, but not with "myFont"
There are many things in place (font fallback, substitution, linking, etc.)
And they are all work better with normal Windows UI fonts
(Microsoft Sans Serif, Tahoma, Segoe UI).
So with one of these fonts you will get better results than with "myFont".


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