支持多种语言的MFC程序

来源:百度文库 编辑:神马文学网 时间:2024/04/29 09:00:29

Multilingual Application - Change Application Language

By Daniel Zuppinger |18 Nov 1999Multilingual Application - Change Application LanguageIs your email address OK?You are signed up for our newsletters but your email address has not been reconfirmed in along time. To make this warning go away please clickhere to have aconfirmation email sent so we can confirm your email address and continue sending you yournewsletters. Alternatively, you canupdate your subscriptions.
  • Download source - 27.1 Kb

Introduction

Developing applications supporting multiple languages has always been a drag. With thepossibility of including several languages into the rc file of a project, the problem isnot entirely solved: The operating system is used as a base and decides what language yourapplication is working with.

If as example, the resources contain English and German, the application will use theEnglish resources on an American or British Windows system, and German on a German orSwiss (German) Windows version. Other language versions of Windows will use the defaultlanguage (English in most cases).

This behavior is acceptable in most cases, but can cause some headaches: A Frenchspeaking person might prefer the German version of your application, but gets by defaultthe English version. Under Windows NT and Windows 2000, there is a simple way of adding thefunctionality for switching between languages.

Please note: This will only work under NT 3.51 and Windows 2000. There were someproblems using NT 4.0 SP3 (and earlier?) reported, but I could not confirm them.

Step 1.

Add the desired languages to your resources.

Step 2.

Enhance your code as follows:

Collapse
 // Place this code in InitInstance()

m_lang = GetProfileInt("General","Language",0);
if (m_lang == 0) {
// switch language to english

::SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,
SUBLANG_DEFAULT),SORT_DEFAULT));
}
else {
// switch language to german

::SetThreadLocale(MAKELCID(MAKELANGID(LANG_GERMAN,
SUBLANG_DEFAULT),SORT_DEFAULT));
}
//

//

// Add a menu or a toolbar button and attach this method


void CLanguageApp::OnLanguageTogglelanguage()
{
if (m_lang == 0) {
WriteProfileInt("General","Language",1);
}
else {
WriteProfileInt("General","Language",0);
}
AfxMessageBox(IDS_RESTART); // tell the user to restart the application

}

//

License

This article has no explicit licenseattached to it but may contain usage terms in the article text or thedownload files themselves. If in doubt please contact the author via thediscussion board below.

A list of licenses authors might use can be found here