The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on April 08, 2011, 06:53:22 AM

Title: Unicode listbox
Post by: Farabi on April 08, 2011, 06:53:22 AM
Anyone know how to create a unicode listbox?
Title: Re: Unicode listbox
Post by: donkey on April 08, 2011, 07:06:23 AM
Use Unicode functions to create the listbox. If its in a dialog use DialogBoxParamW to initialize the dialog box, if you are creating it with CreateWindowEx, use CreateWindowExW etc... In GoAsm use /d UNICODE on the command line and STRINGS UNICODE in your source and it will be done transparently. In MASM it is a little more involved but you can use ANSI messages with Unicode windows, they will be translated to Unicode so it shouldn't be too difficult but it will slow things down a tad.
Title: Re: Unicode listbox
Post by: hutch-- on April 08, 2011, 07:09:48 AM
Onan,

Just make sure that the text you place in the list box is also unicode and use the unicode versions of SendMessage etc ... to load the list box.
Title: Re: Unicode listbox
Post by: donkey on April 08, 2011, 07:10:52 AM
Quote from: hutch-- on April 08, 2011, 07:09:48 AM
Onan,

Just make sure that the text you place in the list box is also unicode and use the unicode versions of SendMessage etc ... to load the list box.

Makes no difference except in terms of a slight penalty in speed, Windows will translate all messages below WM_USER to Unicode during the marshalling process.

QuoteThe system does automatic two-way translation (Unicode to ANSI) for window messages. For example, if an ANSI window message is sent to a window that uses the Unicode character set, the system translates that message into a Unicode message before calling the window procedure. The system calls IsWindowUnicode to determine whether to translate the message.
Title: Re: Unicode listbox
Post by: hutch-- on April 08, 2011, 07:14:03 AM
 :bg

Fine but don't expect 2 byte strings to load correctly into a list box if the source is not in the right format. I get this with Japanese characters if its done wrong.
Title: Re: Unicode listbox
Post by: donkey on April 08, 2011, 07:15:02 AM
Quote from: hutch-- on April 08, 2011, 07:14:03 AM
:bg

Fine but don't expect 2 byte strings to load correctly into a list box if the source is not in the right format. I get this with Japanese characters if its done wrong.

You can't send Japanese characters with the ANSI character set so that's a non-issue. They require DBCS in which case you have to set the proper code page and not use a Unicode message.
Title: Re: Unicode listbox
Post by: Farabi on April 08, 2011, 10:05:02 AM
I tried to create the unicode using CreateWindowExW but failed. Anyone successfully use it? Or I need to typ the class name on unicode?
Before I able to create a unicode richedit I need to load some library first, does I need to load something first before using the listbox unicode version?
Title: Re: Unicode listbox
Post by: hutch-- on April 08, 2011, 10:59:39 AM
 :bg

Funny enough I have no problems loading and saving Japanese characters in combined Kanji and Katakana as straight unicode. The problem is it cannot be easily emulated in ANSI characters so you save and load Japanese as unicode. What you do need is to have the east asian fonts loaded so you can display the character sets.

Onan, from memory richedit 1 does not support unicode where richedit 2/3 does. Just make sure you use the correct window class for richedit 2/3. You may have to make sure that in the Windows version you are running that you have the right fonts to display the characters you need.
Title: Re: Unicode listbox
Post by: Farabi on April 08, 2011, 02:15:26 PM
Somebody should say that I need to use unicode for the class name  :lol
is MASM had a macro for unicode text like CADD("text") macro? I think I asked this before, but the thread is gone.
Title: Re: Unicode listbox
Post by: donkey on April 08, 2011, 03:56:55 PM
Quote from: Farabi on April 08, 2011, 02:15:26 PM
Somebody should say that I need to use unicode for the class nameĀ  :lol
is MASM had a macro for unicode text like CADD("text") macro? I think I asked this before, but the thread is gone.

Hi Onan,

All xxxxxW or unicode functions only accept unicode as input and output unicode. This is a standard in Windows and shouldn't have to be mentioned.
Title: Re: Unicode listbox
Post by: hutch-- on April 09, 2011, 01:31:10 AM
Onan,

MASM does not natively support unicode strings as literal strings, there are some macros that will convert ansi to unicode but this will not help you if the character set requires something that cannot be represented by ANSI text. The conventional way to handle unicode in MASM is to store the string data in the resource section which is native unicode. You can also store unicode string as byte data and pass the address like normal.

隱庵こんにちわ。    Onan konnichiwa.

    Onan db 177,150,181,94,83,48,147,48,107,48,97,48,143,48,00

Title: Re: Unicode listbox
Post by: jj2007 on April 09, 2011, 06:08:52 AM
Quote from: Farabi on April 08, 2011, 02:15:26 PMis MASM had a macro for unicode text like CADD("text") macro? I think I asked this before, but the thread is gone.

MasmBasic (http://www.masm32.com/board/index.php?topic=12460) Unicode functions: wArrayFill, wCat$, wChr$, wCL$(), wClip$, wData, wDate$, CrtDate$, wInkey, wInstr, wLeft$, wLen, wLet, wLower$, wMid$, wMsgBox, wPrint, wPrint #n, wRes$, wRight$, wSetWin$, wStr$, wTime$, wUpper$, wWin$

Example (sets the text of an editbox using a Unicode string from a resource file's stringtable):

QuotewSetWin$ hEdit=wRes$(1)+wCrLf$+wCrLf$+wRes$(2)
[/b]
Title: Re: Unicode listbox
Post by: Farabi on April 09, 2011, 07:00:23 AM
Hi JJ  :U
Yeah I saw your MASM basic but it yield an error, but I'll try to fix it.
Title: Re: Unicode listbox
Post by: hutch-- on April 09, 2011, 11:49:18 AM
Onan,

I am sure you already have it working but here is a unicode test piece that loads 1 to 10 in Indonesian into a list box.

The RSRC.RC file is written as UNICODE so you need a unicode text editor to change it.
Title: Re: Unicode listbox
Post by: Farabi on April 09, 2011, 03:00:41 PM
Thanks hutch, yeah I already fix it.