Solved

thai language characters in MS VC++ application

Posted on 2012-03-30
9
753 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

16 Experts available now in Live!

Get 1:1 Help Now