Solved

thai language characters in MS VC++ application

Posted on 2012-03-30
9
745 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contact management 16 145
PDF File Shrinker 10 85
Donating Old Pc and laptop 7 78
Path to  STL Map header file 1 24
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now