Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How we can Make Our Windows Controls Unicode Supportive.

Author: DevASP
Download Source Code :

This article describes how we can make our windows controls Unicode supportive. Normally we use ASCII character code in which only 256 characters can be presented to the user.

It takes a single byte to store a character. Unicode is urbanized to support the worldwide languages for computation. Unicode takes two bytes for a single character I support and it approximately supports the every symbol of the world which is present in whatever language.Lets get started and Fire up your MS visual Studio 2003 and create a new dialog based project. Gave it a name “UnicodeControls” . Place the following controls on the dialog in the dialog resource editor and add the following member variables to them.


Control Type                  Control ID                      Added Member variable  Member Type




Button                           IDC_BUTTON1   m_button                                    Control

Check Box                    IDC_CHECK1     m_check                                    Control

Edit Box                        IDC_EDIT1         m_edit                                       Control

Combo Box                   IDC_COMBO1    m_combo                                   Control


Add another button and make its caption “Press to show Unicode” and add handler function which receive the event when this button is pressed.To make your controls Unicode supportive we will first have to make some changes in our project settings. Let’s first do that.You have to follow these steps to make your project Unicode supportive.Go to the project’s properties and then select from the left pane C/C++ then select the Preprocessors

from the sub options of C/C++ and on the right side pane in the process definitions add _UNICODE both in DEBUG mode and RELEASE mode.


And press Ok.


Go to the project’s properties again and select Linker from the left pane and then select the Advance option from the sun options displayed by Linker, From there Select the Entry Point from the right side pane and add there wWinMainCRTStartup .Make sure that these both settings are in Release configuration also.Now our project is supportive to Unicode. And now we will write a txt File in UNICODE encoding so that we could display UNICODE text from this file to our controls.


Create a txt file in the same directory of project and gave it the Name “Uni.txt” open this file and select the Save as then change the Encoding Option to Unicode and overwrite to the opened file.Now this is a file in Unicode encoding, we can display the Unicode characters in this file according to the selected font for this file.


To add some Unicode character in this file first select font option and select the appropriate font available to your system. Must remember the name of font you have selected for file because we have to load his font when we will display the Unicode characters stored in this file to our controls.For the Sample purpose you select the “Verdana”.


Now open the Character Map from Start->All Programs->Accessories->System ToolsOpen it and select the Symbol font this will open all the characters in Symbol font.Select the  characters .Copy them and paste into the txt file which we have created. Now close the txt file.Now come to the Code editor. Add a member variable named “m_font” of type CFont into your dialog class and a function like this


Void  FontsForControls();


In the definition of this function add the following code which set the Symbol font to all the controls on our dialog.



int CUnicodeControlsDlg::FontsForControls(void)



CDC *pDeviceContext = GetDC();

      LOGFONT logicalFont;

      memset(&logicalFont, 0, sizeof(logicalFont));


pDeviceContext->m_hDC,LOGPIXELSY), 72);

      logicalFont.lfWeight = FW_NORMAL;

      logicalFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;

      wcscpy(logicalFont.lfFaceName, _T("Symbol"));



//Set the font to controls








Now we will write some code to handle the button event which we have added in the last to our dialog with the Caption “Press to show Unicode”. 


void CUnicodeControlsDlg::OnBnClickedButton2()



            // TODO: Add your control notification handler code here

            FILE *streamRead;

            wchar_t data1[15]=L"0";

            if( (streamRead = _wfopen( L"Uni.txt", L"r" )) != NULL )




            fclose( streamRead );








This code is simply reading the text from the file and Sending messages to the controls through SendMessage.


This is the all inside story….


You can change the file font to store the other fonts characters and then load this font into your code and display the Unicode on your controls.

Article Comments
I tried to test this appliction with some chinese characters by copying into that uni.txt file . But i only saw some square box on controls.
i am able to see proper character on that txt file .then why not on that controls???

Posted on 12/1/2006 7:46:05 AM by santosh K Mishra

Add Article Comment:
Name :
Email Address :
Comments :
<< Creating Drop Down Menu Script on a Page.

Disclaimer - Privacy
© 2002-2017