Solved

thai language characters in MS VC++ application

Posted on 2012-03-30
9
757 Views
Last Modified: 2012-03-31
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
Comment
Question by:tullhead
  • 6
  • 3
9 Comments
 
LVL 12

Accepted Solution

by:
satsumo earned 500 total points
ID: 37790990
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
 

Author Comment

by:tullhead
ID: 37791250
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
 
LVL 12

Expert Comment

by:satsumo
ID: 37791451
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 12

Expert Comment

by:satsumo
ID: 37791461
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
 

Author Closing Comment

by:tullhead
ID: 37791472
Thanks for your help --
0
 
LVL 12

Expert Comment

by:satsumo
ID: 37791476
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
 
LVL 12

Expert Comment

by:satsumo
ID: 37791482
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
 
LVL 12

Expert Comment

by:satsumo
ID: 37791497
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
 

Author Comment

by:tullhead
ID: 37791509
I must have done something wrong -- I had to go back and pick your solution.  OK now!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question