Discussion:
DDX_Control and Japanese
(too old to reply)
Frank
2011-05-05 14:49:36 UTC
Permalink
Dear people,

I'm writing an application consisting mainly from
dialogs which also supports Japanese and for
which I have a translation of the resources in a
separate .RC file. Now in one dialog box,
only one of the static texts appears in Japanese,
all others are question marks. The reason turned
out to be that I'm subclassing all texts except
the one with DDX_Control. If I omit the subclassing,
everything is in Japanese. What does DDX_Control
that prevents the correct characters from appearing?
David Webber
2011-05-05 15:25:09 UTC
Permalink
Post by Frank
I'm writing an application consisting mainly from
dialogs which also supports Japanese and for
which I have a translation of the resources in a
separate .RC file. Now in one dialog box,
only one of the static texts appears in Japanese,
all others are question marks. The reason turned
out to be that I'm subclassing all texts except
the one with DDX_Control. If I omit the subclassing,
everything is in Japanese. What does DDX_Control
that prevents the correct characters from appearing? <


If you do it right it should work fine - mine does with Chinese, Czech, and
other non-ASCII character sets.

So ...

How are you setting the text in the controls?

Do you have a Unicode application?

Are you using wide character strings?

Are you using a font which has the Japanese characters?

The answer should be somewhere in the answers to those questions.

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Frank
2011-05-05 16:11:49 UTC
Permalink
Post by David Webber
If you do it right it should work fine - mine does with Chinese, Czech, and
other non-ASCII character sets.
So ...
How are you setting the text in the controls?
I don't. They are just CTEXT statements in the
.RC file and remain unchanged.
Post by David Webber
Do you have a Unicode application?
No.
Post by David Webber
Are you using wide character strings?
I don't use strings at all - it's just the
template. But the strange thing is: If I
don't use DDX_Control, everything works.
Post by David Webber
Are you using a font which has the Japanese characters?
I use Verdana but if it was the font that's
the problem it wouldn't disappear when I omit the
DDX_Control, right? After all, DDX_Control doesn't
set a font.
David Webber
2011-05-05 17:21:03 UTC
Permalink
Post by Frank
Post by David Webber
How are you setting the text in the controls?
I don't. They are just CTEXT statements in the
.RC file and remain unchanged.<

So is the rc file a wide character file? Or how are you defining the
Japanese text?
Post by Frank
Post by David Webber
Do you have a Unicode application?
No.
Post by David Webber
Are you using wide character strings?
I don't use strings at all - it's just the
template. But the strange thing is: If I
don't use DDX_Control, everything works.<

I haven't looked at the details of the data exchange process - life is too
short - but a quick glance tells me that it uses a CDataExchange class, and
that the CDataExchange contains a CWnd * and CWnd * has lots of methods
involving LPCTSTR. If any of these are invoked (which seems likely if the
control contains text) then you are not using Unicode text, and I can
imagine that almost anything could go wrong.

Using Japanese text, without using Unicode (which was designed to handle
these things) seems to be asking for trouble. I suspect the easiest way
out is to convert to Unicode.

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Frank
2011-05-06 06:42:08 UTC
Permalink
Post by David Webber
Post by Frank
Post by David Webber
How are you setting the text in the controls?
I don't. They are just CTEXT statements in the
.RC file and remain unchanged.<
So is the rc file a wide character file?   Or how are you defining the
Japanese text?
This is the beginning of the .RC file:

---------- snip ----------

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(932)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END


---------- snip ----------

And this is the text definition:

---------- snip ----------

IDDCONDITIONS DIALOGEX 0, 0, 208, 191
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "‘ª’èðŒ"
FONT 11, "Verdana", 400, 0, 0x0
BEGIN
CTEXT "ƒTƒ“ƒvƒ‹‰·“x\n (‹C)",IDCTEMPERATURE,4,6,45,25


---------- snip ----------
Post by David Webber
I haven't looked at the details of the data exchange process - life is too
short - but a quick glance tells me that it uses a CDataExchange class, and
that the CDataExchange contains a CWnd * and CWnd * has lots of methods
involving LPCTSTR.   If any of these are invoked (which seems likely if the
control contains text) then you are not using Unicode text, and I can
imagine that almost anything could go wrong.
CDataExchange holds just a pointer to the control
but you could be right anyway. DDX_Control does a
SubclassWindow which is the reason for the problem:
If one omits it, everything's working.
Post by David Webber
Using Japanese text, without using Unicode (which was designed to handle
these things) seems to be asking for trouble.   I suspect the easiest way
out is to convert to Unicode.
Yes, maybe we should try that. I've read somewhere
that it is possible without Unicode but
can't find the reference anymore.
David Webber
2011-05-06 16:02:06 UTC
Permalink
Post by Frank
...
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(932)
...
CTEXT "ƒTƒ“ƒvƒ‹‰·“x\n (‹C)",IDCTEMPERATURE,4,6,45,25
This is a directive to use code page 932 (Japanese) and the CTEXT bytes are
interpreted by the program as being characters from that code page.

This was the old 'Multibyte character set' (MBCS) way of doing things,
which has now been totally superseded by Unicode. I'd heard so much about
problems using code pages other than 1252 (Western European) that I ducked
the idea of doing very much with them, and avoided 'exotic' languages (ie
those using code pages other than 1252) until I switched to Unicode.

In Unicode all characters have their own unique 'code point': there are no
more separate code pages for managing different languages, and it works very
smoothly.

The only downside (if it is one) is that it is difficult to support Windows
98/ME with a Unicode app: but if NT4, Win2000, XP, Vista, 7 are OK for you
then Unicode is the way to go.

Basically you're struggling with superseded technology, which was superseded
(decades ago) because so many people were struggling with it. :-(

[In my own app, I now have options to use English, French, Spanish,...
(which would formerly have used code page 1252), Czech (which used another
one), Chinese (simplified) which used another one and needed multi-byte
characters, and Welsh, which has one character (w with a ^ on it) which
existed in no known code page and, as far as I can see, could not be written
at all in Windows before Unicode came along. Unicode is definitely the
answer.]

Dave
-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
David Webber
2011-05-06 16:10:32 UTC
Permalink
PS - just in case news group technology handles it these days, here are a
couple of chunks of my (Unicode) Chinese module rc file:

LANGUAGE LANG_CHINESE_SIMPLIFIED, SUBLANG_CHINESE_SIMPLIFIED

IDR_MAINFRAME MENU
BEGIN
POPUP "文件 (&F)"
BEGIN
MENUITEM "新建... (&N)", ID_FILE_NEW
MENUITEM "打开... (&O)", ID_FILE_OPEN
MENUITEM SEPARATOR
POPUP "导入 (&I)"
BEGIN
MENUITEM "打开剪贴板 (&B)", ID_OPENCLIPBOARD
MENUITEM SEPARATOR
MENUITEM "在新乐谱中播放... (&P)", ID_PLAYNEWPIECE
MENUITEM "重导入正在播放的乐谱... (&R)", ID_PLAYREIMPORT

[The text after POPOUP and MENUITEM should be Chinese characters if it comes
across properly.]

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Joseph M. Newcomer
2011-05-07 23:48:05 UTC
Permalink
Take David's advice: convert to Unicode. Seriously. I've converted 100K lines from ANSI
to Unicode in about three days of intense editing, but having a powerful text editor that
makes regular-expression pattern replacement easy is a big plus (spend the time to learn
how to do this in VS!) Double check every place you use sizeof() and strlen() to make
sure you have the correct value:
char buffer[SOMESIZE];
... sizeof(buffer)...
becomes
TCHAR buffer[SOMESIZE];
...(sizeof(buffer) / sizeof(TCHAR)) ....
or
TCHAR buffer[SOMESIZE];
... _countof(buffer)...

(Any version of VS >= 2005 has _countof defined). Similarly

WriteFile(buffer, strlen(buffer) ...
becomes
WriteFile(buffer, _tcslen(buffer) * sizeof(TCHAR), ...

and all literals become _T() literals. All str...functions become tcs... functions.

This will get you 99% of the way. It usually takes me about a day to find the obscure
problems.
joe
Post by Frank
Post by David Webber
Post by Frank
Post by David Webber
How are you setting the text in the controls?
I don't. They are just CTEXT statements in the
.RC file and remain unchanged.<
So is the rc file a wide character file?   Or how are you defining the
Japanese text?
---------- snip ----------
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
#pragma code_page(932)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
---------- snip ----------
---------- snip ----------
IDDCONDITIONS DIALOGEX 0, 0, 208, 191
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "‘ª’è?ðŒ?"
FONT 11, "Verdana", 400, 0, 0x0
BEGIN
CTEXT "ƒTƒ“ƒvƒ‹‰·“x\n (?‹C)",IDCTEMPERATURE,4,6,45,25
---------- snip ----------
Post by David Webber
I haven't looked at the details of the data exchange process - life is too
short - but a quick glance tells me that it uses a CDataExchange class, and
that the CDataExchange contains a CWnd * and CWnd * has lots of methods
involving LPCTSTR.   If any of these are invoked (which seems likely if the
control contains text) then you are not using Unicode text, and I can
imagine that almost anything could go wrong.
CDataExchange holds just a pointer to the control
but you could be right anyway. DDX_Control does a
If one omits it, everything's working.
Post by David Webber
Using Japanese text, without using Unicode (which was designed to handle
these things) seems to be asking for trouble.   I suspect the easiest way
out is to convert to Unicode.
Yes, maybe we should try that. I've read somewhere
that it is possible without Unicode but
can't find the reference anymore.
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
David Webber
2011-05-08 12:11:49 UTC
Permalink
From: Joseph M. Newcomer
Post by Joseph M. Newcomer
Take David's advice: convert to Unicode. Seriously. I've converted 100K lines from ANSI
to Unicode in about three days of intense editing,...<

It took me about a year to do something similar (ending with a day of
intense editing <g>) BUT ...

I made the decision that my (then) next version would not have to run on
Windows 98, and I did it in a leisurely fashion, just converting stuff when
I came across it. All my char's became TCHAR or WCHAR (=wchar_t) or were
left as char as appropriate. The ones left as char, I replaced by CHAR
(upper case) as a signal that I had considered it, and decided it really was
a 1-byte object. [Then on D-day, I changed the project settings to
Unicode, and then came the picking up of the (relatively few) things I had
missed.]

In the process:

Anything to be saved in a file became WCHAR as it was important to me that
the file format would be the same if I did a Unicode and a non-Unicode
build. (In the event I have never needed a non-Unicode build and I doubt
now that I ever shall.)

Most of the instances of CHAR were just where I wanted to have a 1-byte
integer, but there are also one or two places where single byte characters
are needed:

For some reason ::GetProcAddress() takes an old fashioned const char *
string argument for the function name. (I guess function names in Arabic
script are not a good idea <g>.)

And I explicitly use the ASCII version ::GetGlyphOutlineA(), because the
character number it takes is different for symbol fonts than that of the
wide character version ::GetGlyphOutlineW(), which needs Unicode code point
in the user symbols range. Had I just used GetGlyphOutline(), it would have
involved a different argument for a Unicode and non-Unicode build.

But these exceptions are pretty few and far between. (Most folk never have
to use GetProcAddress, and GetGlyphOutline is definitely one of those
routines you save for Sunday best <g>.) Mostly it's just a case of making
sure you use TCHAR almost everywhere, and WCHAR or CHAR where you need them,
and checking that anything which takes a string argument is compatible
(strlen, vs _tcslen, vs wcslen etc ), and (as Joe points out) that any
sizeof operations are done correctly.

After that you need to make sure you have Unicode settings defined in the
project, and that your rc file is a Unicode text file with the proper
Japanese text in it.

Dave

David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
David Lowndes
2011-05-08 14:06:16 UTC
Permalink
Post by David Webber
Post by Joseph M. Newcomer
Take David's advice: convert to Unicode. Seriously. I've converted 100K lines from ANSI
to Unicode in about three days of intense editing,...<
It took me about a year to do something similar (ending with a day of
intense editing <g>) BUT ...
Indeed, it can take a very variable amount of time depending on the
nature of the application.

A straightforward GUI with little vagueness around what should remain
single-byte and what should be Unicode, could be converted in a few
days or even hours. On the other hand, if your application is dealing
with things that are inherently single byte (like historical email
applications in my experience), then it's more likely to be at least
several weeks of work, especially of you're not familiar with what
ought to be single byte/Unicode characters in the code base.

Dave
Joseph M. Newcomer
2011-05-09 02:23:39 UTC
Permalink
When you have the leisure, it is much easier; I once spent a year converting a Win16 app
to Win32, so when we finally bit the bullet to go to Win32, it took two more days of
detailed debugging (mostly fixing compiler-detected errors, some of which were due to
stricter compiler syntax checking) and we were there.

For the Unicode conversions, for code I haven't written I rarely have the leisure; in
fact, the assignment is often "Can you convert this to Unicode as quickly as possible?"
usually followed by a request to have the Korean, Japanese or Chinese version deliverable
in less than a month. I tell them that getting the resources translated is their problem,
but I'll give them an app that can be converted. I haven't taken longer than a week to do
a conversion (but that was all I did for that week).

Note that I point out that other localization issues (such as number formatting, date
formatting, time formatting, etc.) are beyond the scope of that estimate and will cost
extra; they usually go for that, which usually adds another couple days. And yes, on a
rush job there are often a couple remaining glitches (bugs) that show up in final
acceptance testing, but most of these are trivial. One that was not took several days of
editing and a LOT of consulting back and forth as to what the "right" decision was. It
was not an easy change in that case.

Fortunately, I have not had to deal with legacy data (such as an email system), but often
deal with "mixed mode" (ANSI and Unicode) apps, where the 8-bit characters are often going
from/to some embedded system. In one case, we did UTF-8 encoding to the target system,
with its ensuing pain (the system accepted 20-byte text fields, which meant that the worst
case was 5 characters of localized text; but this would have required massive changes in
their embedded code; the average was about 7 characters of localized text, encoded as
UTF-8. but of course if the customer used 7-bit-realizable characters, they could get the
whole 20 in. European customers got unhappy because accented characters now too two
bytes, and therefore they had compatibility problems, but the customer had decided to live
with this).

Mostly, it's a lot of tedious editing and a lot of really careful reading of the code. But
it pays well, which is why I do it. Haven't done one in about two years.
joe
Post by David Webber
From: Joseph M. Newcomer
Post by Joseph M. Newcomer
Take David's advice: convert to Unicode. Seriously. I've converted 100K lines from ANSI
to Unicode in about three days of intense editing,...<
It took me about a year to do something similar (ending with a day of
intense editing <g>) BUT ...
I made the decision that my (then) next version would not have to run on
Windows 98, and I did it in a leisurely fashion, just converting stuff when
I came across it. All my char's became TCHAR or WCHAR (=wchar_t) or were
left as char as appropriate. The ones left as char, I replaced by CHAR
(upper case) as a signal that I had considered it, and decided it really was
a 1-byte object. [Then on D-day, I changed the project settings to
Unicode, and then came the picking up of the (relatively few) things I had
missed.]
Anything to be saved in a file became WCHAR as it was important to me that
the file format would be the same if I did a Unicode and a non-Unicode
build. (In the event I have never needed a non-Unicode build and I doubt
now that I ever shall.)
Most of the instances of CHAR were just where I wanted to have a 1-byte
integer, but there are also one or two places where single byte characters
For some reason ::GetProcAddress() takes an old fashioned const char *
string argument for the function name. (I guess function names in Arabic
script are not a good idea <g>.)
And I explicitly use the ASCII version ::GetGlyphOutlineA(), because the
character number it takes is different for symbol fonts than that of the
wide character version ::GetGlyphOutlineW(), which needs Unicode code point
in the user symbols range. Had I just used GetGlyphOutline(), it would have
involved a different argument for a Unicode and non-Unicode build.
But these exceptions are pretty few and far between. (Most folk never have
to use GetProcAddress, and GetGlyphOutline is definitely one of those
routines you save for Sunday best <g>.) Mostly it's just a case of making
sure you use TCHAR almost everywhere, and WCHAR or CHAR where you need them,
and checking that anything which takes a string argument is compatible
(strlen, vs _tcslen, vs wcslen etc ), and (as Joe points out) that any
sizeof operations are done correctly.
After that you need to make sure you have Unicode settings defined in the
project, and that your rc file is a Unicode text file with the proper
Japanese text in it.
Dave
David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
i***@fomine.com
2014-07-03 17:18:00 UTC
Permalink
Hi Frank,

I ran into the exact same problem. Did you find what any solution (except unicode)?
i***@fomine.com
2014-07-04 19:20:26 UTC
Permalink
Here is info for someone who will come to this thread by same issue (DDX_Control, localization, umlaut).

1) Setting a correct system language for non-unicode program helped to fix the issue.
http://www.7tutorials.com/changing-display-language-used-non-unicode-programs

2) GetACP() function returns current code page. It is better to check wherever language is compatible with system code page.
Continue reading on narkive:
Loading...