• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

thai language characters in MS VC++ application

I'm trying to get my app to work with Thai characters.  I've been sent a win7 laptop with thai language pack installed (in the task bar you can toggle between EN and TH to switch between THai and ENglish input).    Many things work.   In some controls Thai language is shown, but in others, when I type it in I see weird characters (western characters with umlauts, etc).  So, its like I'm not using the proper font in my app.   I made my app so I could switch its default font, then I tried using some like "Tahoma" and "Lucida Sans" for which it appears Thai exists.  But no luck.

Now, my app is NOT unicode -- so does that mean that I am out of luck?  Must I convert to unicode?  I think I know that for chinese, japanese, the answer is yes -- but for That, which I believe has a total of 44 characters, I was hoping I could do it without Unicode.  Again, some of the widgets in my app are showing Thai --- these seem to be ones related to the file system, so maybe its because they are windows common controls, or something -- not sure yet.

I will continue fumbling around, but is someone could give me a hint or two, it would be great.  Thanks!
0
tullhead
Asked:
tullhead
  • 6
  • 3
1 Solution
 
satsumoSoftware DeveloperCommented:
Any control that you want to show Thai will have to support Unicode.  If the control does not support Unicode it will not show Thai.   You're program will have to pass the strings into the control as unicode too.

It's not how many characters the range has, but where it is in the unicode set.  For Thai is 0xE00–0xE7F, outside of the single byte character set range.  You may not have to convert the whole program to unicode, you could consider using unicode functions explicitly, though it's probably simpler to just convert the project.

Also as you've noticed, no font supports the whole unicode character set (that would be a very big font).  In fact some fonts support a specific range, Mangal for example.  I believe Windows can substitute from these fonts if a string uses character which aren't in the current font.
0
 
tullheadAuthor Commented:
I'm using MS VC++ with MFC.  Can you give me an example or idea of what would be involved in having a certain control support Unicode and how to pass a string to it?  For example, I might typically have this:

CString foo = "Hello World!";
CWnd* pWnd = pDlg->GetDlgItem(IDC_MY_CONTROL);
pWnd->SetWindowText(foo);

What is the process to get that to work with Unicode?

As you suggest, I might best convert the whole project to Unicode, but I'd be curious how to do it on a small scale so I could consider that approach....
0
 
satsumoSoftware DeveloperCommented:
Since Windows 2000, there have been two version of pretty much the entire Windows API, the A and the W.  The A's are ANSI (8-bit characters) and W's are Unicode (16-bit 'wide' characters).  There's SendMessageA and SendMessageW, LOGFONTA and LOGFONTW, LPSTR and LPWSTR.

The headers contain macros that define SendMessage and LPSTR as the A or the W versions, if the project is set for ANSI or Unicode.  But you can bypass that by calling SendMessageA or SendMessageW explictly, no matter how the project is set.  When mixing string types you have to be careful to always use the correct functions with the correct string types.  Using a LPWSTR with wstrtock() not strtok() for example.

C++ configures it's string types in a similar way.  I don't use MFC but I'm pretty sure it will do the same.  Most controls support Unicode as far I can ascertain.  If you call SetWindowTextW on an edit control it knows that you are giving it Unicode text.

It's usually simpler to just configure the project for Unicode and let the compiler deal with it.  Unless you're working with a lot of text, limited memory or specific types of string data (HTML query strings, 8-bit strings from a database, for example).
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
satsumoSoftware DeveloperCommented:
An explicit version of you example code would be like this:
CStringW foo = "Hello World!";
CWnd* pWnd = pDlg->GetDlgItem(IDC_MY_CONTROL);
pWnd->SetWindowTextW(foo);

Open in new window

I'm guessing that CWnd has a specific SetWindowTextW method.
0
 
tullheadAuthor Commented:
Thanks for your help --
0
 
satsumoSoftware DeveloperCommented:
I appear to have answered this question, indeed the asker is thanking me for doing so.  Maybe the asker selected his own answer by mistake?  I was even thinking of adding it t0 the knowledge base, because its useful information in general.
0
 
satsumoSoftware DeveloperCommented:
Oops, some sort of bug with the site?  It told me that you'd chosen your own answer as the solution.  This page shows that you've picked mine.  Thanks.
0
 
satsumoSoftware DeveloperCommented:
One small change:
CStringW foo = L"Hello World!";
CWnd* pWnd = pDlg->GetDlgItem(IDC_MY_CONTROL);
pWnd->SetWindowTextW(foo);

Open in new window

In an 8-bit string setup you need the 'L' to tell the compiler that its a wide string.
0
 
tullheadAuthor Commented:
I must have done something wrong -- I had to go back and pick your solution.  OK now!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now