IonicWind Software

IWBasic => General Questions => Topic started by: forte on October 10, 2009, 10:13:32 AM

Title: Displaying Chinese Characters in GUI
Post by: forte on October 10, 2009, 10:13:32 AM
It may be a stupid question, but could anyone please tell me how can I set the text of controls to Chinese characters?

I've tried the following 2 methods but they do not seem to work
1. Setting the title to Chinese characters directly
CONTROL w,@BUTTON,L"中文",56,100,50,20,0, 1

2.Using the setcontroltextw
SETCONTROLTEXTW w1, 1 ,L"中文"

BTW:I've also tried to set the charaset of the font to CHINESEBIG5_CHARSET but still not working

Thanks in advance
Title: Re: Displaying Chinese Characters in GUI
Post by: yujinwunz on October 10, 2009, 09:44:30 PM
I've done that with strings after I input chinese into a textbox, then get the value into the strings. I would then display that with "writetext" in direct x, but never tried with windows. Meanwhile, I don't think the IDE is able to read those chinese characters.

Title: Re: Displaying Chinese Characters in GUI
Post by: LarryMc on October 11, 2009, 05:21:13 AM
I don't know much about fonts but would have to ask do you have chinese fonts installed on your computer?

There are some chinese fonts for download at: http://www.sino.uni-heidelberg.de/edv/sinopc/chinese_fonts.htm

Maybe that's what you need.

Larry
Title: Re: Displaying Chinese Characters in GUI
Post by: forte on October 11, 2009, 06:39:40 AM
Quote from: Larry McCaughn on October 11, 2009, 05:21:13 AM
I don't know much about fonts but would have to ask do you have chinese fonts installed on your computer?

There are some chinese fonts for download at: http://www.sino.uni-heidelberg.de/edv/sinopc/chinese_fonts.htm

Maybe that's what you need.

Larry
Yes, I'm actually running EBASIC on my pc, which runs Windows XP SP3 Traditional Chinese version.
There are many Chinese fonts pre-installed.

Also, the EBASIC IDE is able to read Chinese characters with some problems, for example, if you want to delete the Chinese characters, you have to hit the 'DEL' or 'BACKSPACE' key twice.
Title: Re: Displaying Chinese Characters in GUI
Post by: yujinwunz on October 12, 2009, 01:28:09 AM
I meant the compiler, but now it is nonsense as I can display chinese in direct x from chinese written in the code.

I then also displayed it in a window.

is your language for non-unicode programs chinese?

if not, any you have vista,
contol panel> clock Region & languages> region & language options> administrative>change system locale.


if something else, find out how to get to region & language options.

Title: Re: Displaying Chinese Characters in GUI
Post by: sapero on November 19, 2009, 05:53:30 AM
Forte, the editor has some support for Japanese, Chinese and Korean DBCS. To enable it, the host process should use the SCI_SETCODEPAGE message.
Current Ebasic has no such option yet, so we can code it. I have created a dll for you, it uses single thread windows hook to change the code page. To make it simple, the dll is named "scilexer.dll" - it is loaded when ebasic is starting up.

To install it, close Ebasic, and open ebasic/bin directory. Rename the existing scilexer.dll to scilexer0.dll, then copy scilexer.dll from my attachment to ebasic/bin.
Run Ebasic again, and paste 中文.

Note: utf8 codepage will be always active, until you restore the original scilexer.dll, or reinstall your Ebasic.
Title: Re: Displaying Chinese Characters in GUI
Post by: forte on November 19, 2009, 08:28:39 AM
sapero,
I downloaded the attachment and followed your instruction to install the dll
now my IDE can handle chinese characters correctly , I don't need to hit the backspace/delete twice to delete one chinese character. Thank you very much!!!

However the compiled exe cannot show the characters correctly
I find that if I use the original scilexer.dll and type "中文" instead of L"中文" in the code editor, the compiled exe can show the character properly, but actually I don't understand why it works because I think that as one single chinese character occupies 2 bytes, WSTRING should be used and an L should be put before the quotation mark. Perhaps it works on Chinese OSes only.

Using your scilexer.dll, the chinese characters shown on the window of the compiled exe turn into some meaningless characters, even I've tried using both "中文" and L"中文".

I'm confused, I don't know much about character encoding, how can I write a unicode program in EBasic? Could you give me some hints?
Title: Re: Displaying Chinese Characters in GUI
Post by: sapero on November 19, 2009, 10:21:45 AM
Yup, the whole Ebasic GUI library is coded in ansi character set, the parser converts inline wstrings (L"string") using probably simple byte to word casting, instead MultiByteToWideChar with a string to byte/word array converter. The second case makes impossible to use non-englisch characters in inline unicode strings, directly in source code. For example: L"中文", even much simpler european diacritical characters will be not handled correctly in current Ebasic.
However it is possible to write a plugin (or extend the above) which will silently convert all the unicode strings after you start compiling, but before the parser is executed.

I have played with your issue, have installed all the additional fonts and played a bit.

This worked fine:
wstring str
MultiByteToWideChar(CP_UTF8, 0, "中文", -1, str, 256)
MessageBoxW(0, str, 0, 0)

So I have created a helper subroutine:sub utf8w(string utf8),wheap
int cchString = len(utf8)+1 ' LEN here will return more than expected
pointer out = AllocHeap(cchString*2)
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, out, cchString)
return out
endsub

And again, calling MessageBoxW(0, utf8w("中文"), 0,0) is working fine.
But callingSETCONTROLTEXTW window, id, utf8w("中文")didn't worked for me. Please check if the utf8w with SETCONTROLTEXTW is working for you.
There is a option (code patching) to force your program or module to create always native unicode windows, so it will be working like with MessageBoxW.
Title: Re: Displaying Chinese Characters in GUI
Post by: Ionic Wind Support Team on November 19, 2009, 11:17:55 AM
Close, but not quite;)

The built in @button type is an owner drawn control never designed to handle unicode strings, so SetControlTextW won't work for it.   Use the @sysbutton type instead, which is the native API created button control.

Paul.



Title: Re: Displaying Chinese Characters in GUI
Post by: forte on November 21, 2009, 01:05:07 AM
sapero, Paul,

The utf8w helper sub with SetControlTextW is working on my computer.
Chinese characters can be shown correctly now.

Thank you very much for your help.