Easy Unicode

Introduction

I was given a very simple task at work: Take a dialog box that acts as a registration page with a few registration fields (edit boxes), and convert it to support Unicode. This means that the entered data is wide characters. This data of course must be dealt with and should be (in my case) sent to a server. So? Easy isn't it?

I looked it up, studied the concept of Unicode, and?!?!? NADA! You can easily change the character set of your project to Unicode, but who is crazy enough to do that? You will waste lots of time altering your whole code to fit a Unicode character set. You might even end up rewriting your whole code... I could not find an easy or simple way of doing it otherwise. All the solutions I could find contained pages of useless or irrelevant code.

After some research, I came up with a simple and elegant solution that I share here, and I hope it might help someone's project or save some people a very large headache. This article includes code samples and a complete downloadable project (Unicode.zip) that you can compile and play with. In addition, the compiled sample application (Unicode_app.zip) is downloadable as well.

My Solution

Use a Rich Edit-Box Control (CRichEditCtrl) instead of an Edit-Box Control (CEdit). Please note that, to use a rich edit control, you must call AfxInitRichEdit() at the initialization of your application. This function initializes the rich edit control (see the AfxInitRichEdit MSDN documentation regarding rich edit box versions). Now, use SendMessageW to send your text to or from the rich edit box.

What SendMessageW Is

#ifdef UNICODE
#define SendMessage SendMessageW
#else
#define SendMessage SendMessageA
#endif    //!UNICODE

SendMessageW is actually the Unicode instance of SendMessage. If you compile your code with a Unicode character set, SendMessageW is used. Otherwise, SendMessageA is used. You actually want to enforce the usage of the Unicode version of SendMessage without a definition of UNICODE, so you call SendMessageW directly. How do you use SendMessageW? Well, the same way you use SendMessage, but you need to remember that all the function's parameters are Wide Character now (Unicode).

How to Use It

Following is an example code (I used it in Unicode.exe) for the usage of Unicode in a non-Unicode (ANSI) application:

void CUnicodeDlg::OnCopy()
{
   GETTEXTEX wParamIN;
   SETTEXTEX wParamOUT;
   LRESULT lResult;
   WCHAR lParam[100]      = {0};
   wParamIN.cb            = (this->m_rich1.
                             GetWindowTextLength()+1)*2;
   wParamIN.flags         = GT_RAWTEXT;
   wParamIN.codepage      = 1200;
   wParamIN.lpDefaultChar = NULL;
   wParamIN.lpUsedDefChar = NULL;
   wParamOUT.codepage     = 1200;
   wParamOUT.flags        = ST_SELECTION;

   // handle to source control
   lResult = SendMessageW(this->m_rich1.m_hWnd,
                          // message ID
                          EM_GETTEXTEX,
                          // = (WPARAM) () wParam
                          (WPARAM) &wParamIN,
                          // = (LPARAM) () lParam
                          (LPARAM) lParam);

   MessageBoxW(this->m_hWnd, lParam, L"Here we go...",
               MB_OK|MB_ICONASTERISK);

   // handle to destination control
   lResult = SendMessageW(this->m_rich2.m_hWnd,
                          // message ID
                          EM_SETTEXTEX,
                          // = (WPARAM) () wParam
                          (WPARAM) &wParamOUT,
                          // = (LPARAM) () lParam
                          (LPARAM) lParam);
}

How to Use Unicode.exe

My simple application (Unicode.exe) simply demonstrates entering a Unicode string into a rich edit box of a non-Unicode application and copying it to another rich edit box. You can use the Windows Character Map (Start->Programs-> Accessories->System Tools) to get Unicode symbols.

Paste the copied symbols in the Input rich edit box of the Unicode.exe.

Click Copy. A message box with the input string is shown. Click OK.

The entered Unicode string is copied to the Output rich edit box.

Summary

In my sample application, I used lParam as a wide character parameter to contain the Unicode string. You can keep using it to send its content forward, but always remember that it contains Unicode formatted data, meaning that each character/symbol takes twice the memory size.

I hope I could help. Enjoy.

About the Author

Lior Peretz

I'm a developer in Aladdin Ltd. at the Software DRM R&D.

Downloads

IT Offers

Comments

  • oakley outlet provide discount oakley sunglasses for cheap

    Posted by heterlife on 05/07/2013 08:51pm

    Take care when purchasing Oakley glasses from unverified locations.You may find out a design of reading throughfor these stores. [url=http://www.test.com/]cheap test holbrook[/url] Along with the second 1 is one of the two styles in Ray-Ban new Carbon Fiber Collection-the rectangular design.Bear in mind the following whenever impressing folks is often a matter the particular Ray Ban THUMP could hardly are more capable of the job. [url=http://www.test.com/]fake test sunglasses[/url] In fact, Ray Ban sunglasses don't turn into globe renowned until eventually the second Globe War when US military have been in will need of some special protective eye wear.Transitions Optical Inc. [url=http://www.test.com/]fake tests[/url] The high-tech material-Carbon Fiber the is main cause I create this piece into my list.Others might make an effort to make an impression on people who have only a developer's brand but the individual wearing of the group of Ray Ban Split Beat sunglasses may download favored songs within their eye wear. [url=http://www.test.com/]knock off test sunglasses[/url] What's astounding here is the ease with which we put our eyes at risk; those eyes that will make us see all colors of the world.These meet as well as exceed ANSI safety specifications. [url=http://www.test.com/]cheap test holbrook[/url] Ray ban are typically liked and praised it really is scarcely shocking they've grow to be desired and distinguished through the several persons in all avenues of life.She's it from him when she see Ray Ban Sunglasses picture about the letter.

    Reply
  • Nike Air Max 1 FB publicity, father a fervent color grain, the new shoes

    Posted by Geozyoceada on 04/22/2013 08:47pm

    In the summer in a goblet interior the chilling sprite seems to be a wholesome preferred, but if the sprite "feet"? Will also give you a frisk, get a invigorating! This summer, Nike and Sprite [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] and his sneakers to a fuse of enduring snow spread of green, white and indecent color system in the definitive Nike Arrogance Max 1 shoes let slip a food presumptuous scent.[url=http://markwarren.org.uk/property-waet.cfm]air max 90[/url] Summer is the yet to hand-pick a purified shoe, shoes should be a good choice. Qualifying series Nike Air Max HomeTurf megalopolis recently definitely comes up, this series in the immortal Breath Max shoes to London, Paris and Milan the three paid eulogy to the iconic megalopolis of Europe, combined with the characteristics of the three cities, Feeling Max 1 HYP,Allied Max 90 HYP,Connected Max 1 and shoes such as Make public Max 95, combined [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] with the Hyperfuse, as marvellously as a variety of materials, such as suede, Whether you hankering functional or retro-everything.

    Reply
  • Lightweight smart – Nike Unshackled TR Attack in shoot up 2013 3 series

    Posted by Tufffruntee on 04/19/2013 05:53am

    Nike Free TR Trim 3 noteworthy features is to exploit the additional plot: Nike Free 5 soles improved bending Scratch; stylish tractor layout making training more focused when; lighter preponderance, the permeability is stronger, and more smart shoe designs not not make shoes [url=http://northernroofing.co.uk/roofins.cfm]nike free run 3[/url] more serene wearing, barefoot training feel, but also more stylish appearance. Nike Relieve TR Fit 3 provides supreme lateral reliability, you can have the legs in the untenable during training. Diligent vamp nobles breathable webbing, drop foam's one of a kind lay out can be [url=http://northernroofing.co.uk/roofins.cfm]nike free run 3[/url] seen under the aegis it. Lightweight, ragged, reduce foam material occupied by completely occasional seams, more obedient, support is stronger. Need more help, role of a training utilize, foam close in more parts of the need for conformableness, effervescence loose. Throw away twice say nothing moisture wicking synthetic materials, vapid on your feet, mitigate living feet sear and comfortable. Phylite [url=http://markwarren.org.uk/goodbuy.cfm]nike free[/url] midsole offers lightweight shock unchanging, famous durability and sedate outsole can do to greatly turn the all-embracing weight of the shoe. Qianzhang pods on the outsole and heel-shaped Unripened rubber enhances the shoe multi-directional purchase on sundry surfaces.

    Reply
  • oakley sunglasses discount

    Posted by pgliliImpumpdzr on 03/29/2013 09:56am

    http://guccisunglassescheap.webs.com - ray ban sunglasses cheap discount sunglasses http://wholesalesunglasseschic.webs.com - wholesale oakley sunglasses cheap oakley http://discountsunglassesfinewebs.com - discount ray ban discount sunglasses http://wholesalesunglassescool.webs.com - wholesale oakley sunglasses wholesale sunglasses http://guccicheapsunglass.webs.com - cheap ray ban fake oakley sunglasses

    Reply
  • womens chemise

    Posted by Fishnethg1076 on 03/29/2013 07:47am

    http://Lingeriesv.webs.com - white LingerieThe babydoll was an instant classic upon its release, and remains one to this day The installation went smoothly, and we had him up and running in short order http://G-string.webs.com - Sexy ChemiseThose with large bosoms might prefer fitting designs that can be achieved with stretching synthetic materials that can be flexible to make them appear slimmer with a tighter, smoother finishDreamgirl is actually recognised as the leading marketer and manufacturer of sexy lingerie http://sexycostumesa.webs.com - Sexy cop costumeHalloween is undoubtedly a children's holiday The basic difference is that baby doll lingeries range between the upper thigh and the belly button in length, while baby doll dresses are slightly longer in length http://babydollnightgowns.webs.com - Babydoll lingerieGet into character and go with it Meanwhile, light green and dark green brings different meaning http://sexystockings.webs.com - Fishnet BodystockingsHowever, the item has also continued to evolveHowever, contrasting most other child mermaid costumes that are generally based on the blue-green colors of the sea, the Barbie costume comes in Barbie's favorite color, pink

    Reply
  • sunglasses wholesale

    Posted by bgliliImpumpnia on 03/29/2013 01:37am

    fake ray ban sunglasses [url=http://akeoakleysunglasses.webs.com]fake ray ban sunglasses[/url] cheap ray ban wayfarer discount ray ban [url=http://discountsunglassessale.webs.com]discount ray ban[/url] replica ray ban designer sunglasses cheap [url=http://sunglassdicountsaleu.webs.com]designer sunglasses cheap[/url] discount ray ban cheap sunglasses [url=http://sunglasspomoteauthentic.webs.com]cheap sunglasses[/url] cheap wayfarer sunglasses discount ray ban [url=http://discountsunglasseshoo.webs.com]discount ray ban[/url] oakley discount cheap oakley frogskins [url=http://sunglasswholesaleofgucci.webs.com]cheap oakley frogskins[/url] cheap sunglasses,,, wholesale sunglasses [url=http://wholesalesunglassescool.webs.com]wholesale sunglasses[/url] cheap ray ban sunglasses replica oakleys [url=http://replicaguccisunglasses.webs.com]replica oakleys[/url] wholesale sunglasses

    Reply
  • wholesale baseball caps

    Posted by xxds6on on 03/29/2013 01:29am

    [url=http://snapbackswholesalezone.webs.com]hats wholesale[/url] hats wholesale y zkkr [url=http://snapbackhatwholesale.webs.com]wholesale fitted hats[/url] wholesale fitted hats w zkvg[url=http://cheapsnapbackshat.webs.com]cheap hats online[/url] cheap hats online k yvxu[url=http://goodsnapbackhatscheap.webs.com]cheap snapbacks[/url] cheap snapbacks p tdwq[url=http://cheapsnapbacksforsalezone.webs.com]snapback hats cheap[/url] snapback hats cheap u cpxh[url=http://cheapsnapbacksforsalezone.webs.com]snapback hats cheap[/url] snapback hats cheap u xoaq [url=http://cheapsnapbacksforsalezone.webs.com]cheap snapbacks online[/url] cheap snapbacks online w xjwk [url=http://cheapsnapbackshat.webs.com]cheap hats online[/url] cheap hats online b kkpa[url=http://goodsnapbackhatscheap.webs.com]cheap snapbacks[/url] cheap snapbacks a pnev[url=http://snapbackhatwholesale.webs.com]wholesale beanies[/url] wholesale beanies d kfvu[url=http://cheapsnapbacksforsalezone.webs.com]snapback hats cheap[/url] snapback hats cheap i eoyp[url=http://snapbackswholesalezone.webs.com]hats wholesale[/url] hats wholesale x cnfz [url=http://cheapsnapbacksforsalezone.webs.com]cheap snapbacks for sale[/url] cheap snapbacks for sale x kmvp [url=http://wholesalefittedhat.webs.com]wholesale fitted hats[/url] wholesale fitted hats t yxqz[url=http://snapbackswholesalezone.webs.com]hats wholesale[/url] hats wholesale n jrtq[url=http://cheaphatsmall.webs.com]cheap snapback hats[/url] cheap snapback hats z vvgd[url=http://snapbackswholesalezone.webs.com]snapbacks wholesale[/url] snapbacks wholesale g evjf[url=http://cheaphatsmall.webs.com]cheap snapback hats[/url] cheap snapback hats o sbkf

    Reply
  • cheap uggs uk

    Posted by Laspeasereuby on 11/08/2012 10:21pm

    kids ugg boots on sale ,ugg boots uk ugg boots on sale ,buy ugg boots uk buy ugg boots online ,buy cheap uggs uk ugg boots sale uk ,buy ugg boots sale uk ugg boots on sale ,buy discount uggs uk. http://www.wholesaleuggsale.co.uk/

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds