April 20, 2024, 02:32:34 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Displaying Chinese Characters in GUI

Started by forte, October 10, 2009, 10:13:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

forte

October 10, 2009, 10:13:32 AM Last Edit: October 10, 2009, 11:33:02 AM by forte
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

yujinwunz

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.


LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

forte

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.

yujinwunz

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.


sapero

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.

forte

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?

sapero

November 19, 2009, 10:21:45 AM #7 Last Edit: November 19, 2009, 10:23:27 AM by sapero
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.

Ionic Wind Support Team

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.



Ionic Wind Support Team

forte

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.