-
September 14th, 2009, 08:07 AM
#1
[RESOLVED] How to display UTF8 coded characters in a Listbox
Hello to all
Is possible to display a char string, formatted in UTF-8 code, in a listbox?
Here is my code:
Code:
char destination[] = "/*string UTF-8 coded*/";
SendMessage (hWnd, LB_ADDSTRING, 0, (LPARAM)destination);
I know that I could convert all in UNICODE and correctly display it, but I would like to display it in UTF-8 code also.
Thank you
-
September 14th, 2009, 08:51 AM
#2
Re: How to display UTF8 coded characters in a Listbox
>> Is possible to display a char string, formatted in UTF-8 code, in a listbox?
Yes. The Windows API takes UTF16LE encoded Unicode in wchar_t's (WCHAR's). So you just have to convert UTF8 to a Window's wchar_t string, and use the "wide" version of the Windows API.
>> char destination[] = "/*string UTF-8 coded*/"
Just be sure to use hex escape sequences for any bytes >= 0x7F, and no character literals outside the basic C character set.
Sample conversion code: http://www.codeguru.com/forum/showpo...1&postcount=11
gg
-
September 15th, 2009, 01:53 AM
#3
Re: How to display UTF8 coded characters in a Listbox
Codeplug thank you for your quick answer!
I know that is possible to convert a UTF8 string in a WCHAR string, and display it in a listbox. But, I would like to display an UTF8 string directly, without any type of convertion.
Is it possible? Is there any way to let understand the listbox that the string is in UTF8 code and not in simply char?
Thank you
-
September 15th, 2009, 02:34 AM
#4
Re: How to display UTF8 coded characters in a Listbox
No, sorry, there is no way to avoid the conversion.
Anyway, I prefer to do it in my code, than to ask Windows to do it for me in an API that will be big and slow because it will have to do the extra work of the conversion when its main goal is to deal with a listbox.
-
September 15th, 2009, 04:15 AM
#5
Re: How to display UTF8 coded characters in a Listbox
olivthill2, I agree with you.
I also have done a version of my code with the UNICODE conversion, but I was curious...
Thank you for your reply!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|