CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2009
    Location
    Genova - Italy
    Posts
    38

    [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

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    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

  3. #3
    Join Date
    Jul 2009
    Location
    Genova - Italy
    Posts
    38

    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

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    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.

  5. #5
    Join Date
    Jul 2009
    Location
    Genova - Italy
    Posts
    38

    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
  •  





Click Here to Expand Forum to Full Width

Featured