Click here to Skip to main content
13,254,373 members (66,605 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 20 Oct 2006

How to extract Unicode strings (Japanese) from an MFC edit control

, 20 Oct 2006
Rate this:
Please Sign up or sign in to vote.
How to extract any Unicode string from an MFC edit box.


This project is a small demo to show how VC++ can be used for localization of existing products.

Windows 2000 is the suggested OS, as it was completely built on Unicode, and though NT was built on Unicode too, using its full capabilities is difficult. Visual Studio and Visual C++ were used to implement this tool.

Japanese language is used as an example to implement the case.


Before we get our hands dirty, let us understand the distinction between Internationalization and Localization.

Internationalization versus Localization

For the software development process, internationalization means to prepare an application so that the code does not need to be modified each time an additional language is to be displayed. Separate files contain all of the translatable information.

Localization of an application means to change it to be able to handle a particular language and locale. To localize a program that has already been internationalized involves no changes to the source code. Instead, translatable files are sent to the product or a contractor translation agency for modification.

For a system to support multiple languages, we need to:

  • Windows 2000 or XP.
  • Visual Studio and Visual C++.

Setting up Windows 2000 or XP

Step 1: Install the Japanese language pack.

Navigate to Start menu->Control Panel->Regional Options->General. Once in the General tab, check the check box left to the Japanese language from the language settings for the System tab.

Sample screenshot

Step 2: Setting the input locale.

Navigate to Start menu->Control Panel->Regional Options->Input Locale. Under the Installed Input Locales section, click Add. From the Input Locale drop down list, select Japanese, and for the Keyboard Layout/IME drop down box, select Japanese Input System (MS-IME2000).

Sample screenshot

Step 3: Setting the default locale.

In the Control Panel - Regional Options, under the General tab, scroll down the list for Language Settings for the System. Highlight Japanese, and click Set Default. Once done, verify it did not change your Input Locale default input language. Click OK.

Sample screenshot

Setting up Visual C++ for Unicode compilation

Step 1: To Unicode enable a project in VC++: in the VC++ IDE, navigate to Project->Settings->C++, in the Preprocessor definitions section, insert WIN32,_DEBUG,_WINDOWS,_AFXDLL,_UNICODE, as normal MFC uses WIN32,_DEBUG,_WINDOWS,_AFXDLL,_MBCS.

Sample screenshot

Once _UNICODE has been defined for your project, a few steps need to be taken to ensure that string handling is done properly.

The first thing you need to understand is that the use of a char or char* for strings is no longer valid. TCHAR should be used in place of this. However, for binary data processing, use of char, char*, and BYTE (typedefed as an unsigned char) are still OK.

From MSDN:
  • Except for database class member functions, all MFC functions are Unicode-enabled, including CString. CString also provides Unicode/ANSI conversion functions.
  • The run-time library supplies Unicode versions of all string-handling functions. (The run-time library also supplies “portable” versions suitable for Unicode or for MBCS. These are the _tcs macros.)
  • TCHAR.H supplies portable data types and the _T macro for translating literal strings and characters. See Generic-Text Mappings in TCHAR.H.
  • The run-time library provides a wide-character version of main. Use wmain to make your application “Unicode-aware.”

Step 2: Navigate to the Link tab and select Output in the drop down list in the Category section, and specify wWinMainCRTStartup as the entry point for the program, in the Entry-point symbol edit box.

Sample screenshot

Hurry !!! Now, we are all set to build a small application with a dialog box which accepts Japanese language codes and outputs the same text in the output window.


// I am trying to collect stones from the ocean of knowledge...
// Today I learnt it how to extract unicode information from
// edit box which is not supported by MFC but taken help from
// win32 SDK function, named ::GetWindowTextW() 
void CUnicode_DialogDlg::OnOK()
  // TODO: Add extra validation here
  CWnd *pWnd="GetDlgItem(IDC_EDIT_UNICODE);
  LPWSTR lpString = new WCHAR[MAX_PATH];
  ::GetWindowTextW(pWnd->m_hWnd, lpString, MAX_PATH);
  LPWSTR caption = A2W("Caption");
  HWND hWnd = this->m_hWnd;
  MessageBoxW(lpString, caption, MB_OK );
  // free the string
  delete[] lpString;

// ******************************* //

Further reading


Locale programming


The Operating System is responsible for loading the language specific resources.


This project does not demonstrate the conversion of the file dialog and the titles in the application as this is all part of the Windows Common Dialog library.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chaitanya Seshadri
Web Developer
India India
Completed B.E in Electrical and Electronics
Senior Software Engineer in Thomson Corporation

You may also be interested in...


Comments and Discussions

QuestionJapanese characters displayed as ??? Pin
limaye_ketaki1-Mar-11 21:00
memberlimaye_ketaki1-Mar-11 21:00 
GeneralThanks ! Pin
2pers14-Sep-09 13:29
member2pers14-Sep-09 13:29 
GeneralMy vote of 1 Pin
etking007200410-May-09 23:54
memberetking007200410-May-09 23:54 
Generalis this code trully working... Pin
aravind.sn4-May-09 2:23
memberaravind.sn4-May-09 2:23 
GeneralRe: is this code trully working... Pin
2pers14-Sep-09 13:34
member2pers14-Sep-09 13:34 
GeneralVery good, 5 star ! Pin
includeh1017-Oct-08 6:08
memberincludeh1017-Oct-08 6:08 
QuestionHow to Show Japanese String in CWnd? Pin
JothiMurugeswaran23-Sep-08 22:05
memberJothiMurugeswaran23-Sep-08 22:05 
GeneralGood! Pin
yearn_remy23-Oct-06 1:20
memberyearn_remy23-Oct-06 1:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 20 Oct 2006
Article Copyright 2006 by Chaitanya Seshadri
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid