Solved

thai language characters in MS VC++ application

Posted on 2012-03-30
9
768 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

If your app took Google’s lash recently, here are the 5 most likely reasons.
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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