Display Chinese Characters in Symbian

Source: Internet
Author: User

Commonly used Chinese character encoding Notation: gb2312, GBK, Unicode, UTF-8, where GBK is the superset of gb2312, that is, covers all the content of gb2312 encoding, UTF-8 is a unicode encoding format in network transmission, if we use VC as a development tool, under the Development of win, then win's default character set is GBK, the default encoding method of the Symbian system is Unicode. That is to say, when the characters directly written in the program are displayed on the mobile phone, they become garbled characters.

(1) static resource file solution
(2) dynamic call of Character Set Conversion Function Solution

 

For the first solution

First, we add the following line of code at the beginning of the LOC file.
Character_set utf8

Step 2: define the required string Resources in the LOC file, as shown below:
# Define qtn_exam_caption "Chinese demonstration"
  
Step 3: Save the edited file as utf8. This step is critical. Otherwise, your program will be garbled.
Note: Save the LOC file in utf8 format. The file starts with a three-byte file header. We need to open the LOC file in binary mode, delete the file headers of the first three bytes. You can use vc6 to open the file headers in binary mode and delete the first three bytes or open the file in uehex format, this is required in s60 3rd SDK.

Step 4: Define string resources in RSS as follows:
Resource tbuf32 r_exam_caption {Buf = qtn_title_main_view ;}

Finally, we can use Chinese in the program. The usage is as follows:
Hbufc * pformat = stringloader: oadlc (r_exam_caption );
... // Now you can use your Chinese string resources.
Cleanupstack: opanddestroy (); // do not release resources after use; otherwise, memory leakage may occur.

 

Method for dynamically converting character sets
Add header file
# Include <charconv. h> // for char set convert GBK-Unicode
Add
Library charconv. Lib // For GBK to Unicode Converter

After the two steps are completed, recompile them. The following two functions can be used.
Void cmcappui: convgbk2uni (tdesc8 & original, TDES & res ){
# Ifndef _ wins __
RFS afileserversession;
Afileserversession. Connect ();
Ccnvcharactersetconverter * converter = ccnvcharactersetconverter: newlc ();

If (converter-> preparetoconverttoorfroml (kcharactersetidentifiergbk, afileserversession )! = Ccnvcharactersetconverter: eavailable)
User: Leave (kerrnotsupported );

Tint state = ccnvcharactersetconverter: kstatedefault;

Tptrc8 STR (original );
Hbufc * iinfotext = hbufc: newl (Str. Length ());
Tptr16 PTR = iinfotext-> des ();

If (ccnvcharactersetconverter: eerrorillformedinput = converter-> converttounicode (PTR, STR, State ))
User: Leave (kerrargument );

Res. Zero ();
Res. Copy (PTR );
Afileserversession. Close ();
Cleanupstack: popanddestroy ();
Delete iinfotext;
# Else
Res. Format (_ L ("Wayne Len % d"), original. Length ());
# Endif
}

Void cmcappui: convuni2gbk (tdesc & original, tdes8 & res ){
# Ifndef _ wins __
Tint state = ccnvcharactersetconverter: kstatedefault;
Ccnvcharactersetconverter * iconv;
Iconv = ccnvcharactersetconverter: newlc ();
If (iconv-> preparetoconverttoorfroml (kcharactersetidentifiergbk,
Ieikonenv-> fssession ())! = Ccnvcharactersetconverter: eavailable)
User: Leave (kerrnotsupported );
Iconv-> convertfromunicode (Res, original, State );
Cleanupstack: popanddestroy ();
# Else
Res. Format (_ L8 ("Wayne Chen % s"), original );
# Endif
}

Specific usage:
Tbuf8 <20> title8;
Tbuf <20> title16;
Tbuf8 <20> msg8;
Tbuf <20> msg16;
Title8.format (_ L8 ("tip "));
Convgbk2uni (title8, title16 );
Msg8.format (_ L8 ("Thank you for using "));
Convgbk2uni (msg8, msg16 );
Showinfodialog (title16, msg16 );
Now, both title16 and msg16 store 16-bit Unicode Chinese strings.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lmyuanhang/archive/2009/10/09/4646115.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.