Link to home
Start Free TrialLog in
Avatar of hpchong7
hpchong7

asked on

display chinese caption on cbutton

Dear all,

    My computer system locale is Western English, and I want to display Chinese caption on the CButton as follows, however, it didn't work, do you know what's the problem?( I defined _UNICODE & UNICODE inside my project, and my resource file are already in CHINESE (PRC) format)


LPTSTR s_strRemarks=(LPTSTR)malloc((255)*sizeof(TCHAR));
s_strRemarks[0]=0x5c0f;  //Chinese character 1
s_strRemarks[1]=0x8003; //Chinese character 2
s_strRemarks[2]=0x8a66; //Chinese character 3
s_strRemarks[3]=0;

AfxMessageBox(s_strRemarks); //can display chinese character here inside the messagebox

///////////////Extra code for font///////////////
CFont m_font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 10;    
lf.lfCharSet = CHINESEBIG5_CHARSET;
_tcscpy(lf.lfFaceName, _T("PMingLiU")); //chinese font
m_font.CreateFontIndirect(&lf);  
m_TestButton.SetFont(&m_font);
////////////

m_TestButton.SetWindowText(s_strRemarks);   //display garbage here no matter I have the "Extra code for font" or not.

delete[] s_strRemarks;
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Don't mix malloc and delete!!!! This will cause trouble eventually. Use free if you used malloc, and use delete if you used new.
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is your OS? Are those Chinese characters in Unicode?
Avatar of hpchong7
hpchong7

ASKER

Khkremer, your solution is great!However, I have further problems:

1.) MS shell Dlg 2 is only available after win2k. If my application need to run from win98 to winxp, what should I use? (add 20 pts more for solving this question)
2.)I've to apply activeskin on my project, after I applied it, the Chinese characters become ??? again, so how should I solve it? (add 50 pts more for solving this question)

Thanks!
On an English system MS Shell Dlg 2 is very likely mapped to Tahoma, so you could try to use Tahoma instead of MS Shell Dlg 2. This may work on Win98 as well.

I don't know activeskin, so I have no idea what it does to the font selection. Sorry.
thanks!
Try this:
if Win32Platform = VER_PLATFORM_WIN32_NT ->'MS Shell Dlg 2'
otherwise -> 'MS Shell Dlg 2'.