Click here to Skip to main content
12,303,190 members (75,200 online)
Click here to Skip to main content
Add your own
alternative version


128 bookmarked

Internationalization and Multiple Language Support

, 14 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Changing the language of a Windows program on the fly using resource only DLLs.
<!-- Download Links --> <!-- Article image -->

Sample Image - mult_lang_support.gif


This is a simple article showing how one can internationalize a Windows program, changing the menu, accelerators, dialog boxes, and common dialogs (the file open dialog is used in this example) etc. on the fly. I have seen many questions on the newsgroups about this, but have yet to see a good, simple, example.


This code is based on snippets of information found in various newsgroups.


The code is contained primarily in one function, CMainFrame::SetLanguage, it is partially displayed below. The source code does have more comments and also has the ability to set the language based on the PC's locale.

If a resource DLL has been loaded we should remove it, this is done in the destructor.


We simply branch on the language we want and load the relevant DLL using LoadLibrary. The library is kept in memory once it is loaded, because removing it when a new language was required caused problems with accelerators in NT4, this is described later.

   m_hInstFrench = LoadLibrary(_T("LangFRA.dll"));

If a resource DLL was loaded we need to set the MultiLang's resource handle to the handle of the DLL from which the application’s resources will be loaded. Otherwise we use m_hInstEnglish, which is initially set to AfxGetInstanceHandle(), to obtain the current instance of the application, and use that to load the resource from the EXE.


The menu has to be changed to be the one from our resource DLL. It should be noted that we need to get the menu from the CMainFrame, this is because we in effect need to force a change of any elements that are currently displayed. The dialog boxes, as you will see will be displayed in the correct language automatically, in this example, the About box.

New is used to create the new CMenu so we can then use SetMenu() to set the current menu to the new menu. This causes the window to be redrawn to reflect the menu change.

Any other redraws etc. must be done as well, such as updating the status bar with "Ready", using new accelerators, or re-painting any windows that display text.

CMenu *pMenuCurrent = GetMenu();

   // Create a new menu instance, we need to use this in SetMenu
m_pMenuNew = new CMenu;

   // has the menu changed?
   // m_hMenuDefault is the default menu resource for this frame see AFXWIN.H
if(pMenuCurrent->m_hMenu != m_hMenuDefault)
      // Destroy the "New" menu and delete the resource
      // We, after all created it!
   delete pMenuCurrent;

   // Load our new resource, menu and
   // Displauy the new menu

Date Display

Method CMainFrame::GetDate() shows how to use _tsetlocale() and _tcsftime() to display the current date the langauge we have specified.


These need to be loaded every time the language changes, during testing on NT4 it was found that if the resource only DLL was unloaded when not required the accelerators would not change the next time the language changed. So once loaded they stay in memory until no longer required. Each language uses a different set of accelerators as a test.

   // m_hAccelTable is used in Winfrm.cpp as the accelerator handle,
   // only one accelerator can be loaded at a time so we MUST clear it
m_hAccelTable = NULL;

Custom Common Dialog

MSDN article Q102332 "How to Show a Custom Common Dialog using CFileDialog" describes how to do this using CFileDialog, this example uses the Win32 function GetOpenFileName(). Although the code is the same for both methods there appears to be a bug when using CFileDialog and Visual C++ 6.0, this will be investigated later.

The code for this is CMainFrame::OnFileOpen(). Visual C++ provides some templates, these can be found in one of the Visual C++ directories they have .dlg suffices, the example uses Fileopen.dlg, to use this do the following:-

  • Find the correct template from Fileopen.dlg.
  • Add this to your resource, open the resource as a text file to do this.
  • Select the resource and using View - Resource Includes menu, add #include <dlgs.h>, as a "Read-only symbol directive".
  • Add #include <dlgs.h> to the source file in which GetOpenFileName is to be used.

The OFN_ENABLETEMPLATE has to be added to the Flags member of the OPENFILENAME structure, the magic number 1537 is the resource template ID.

ofn.hInstance = AfxGetResourceHandle();
ofn.lpTemplateName = MAKEINTRESOURCE(1537);

Should there be a mistake in the template, the dialog will not be displayed! There has to be one template per language, so this is not an ideal solution, and every common dialog box, and style of dialog box, that is used would need to be called this way.

Resource Code DLL

This is a "Win32 Dynamic-Link Library", a Resource Only DLL. To create it, do the following:

  • Create a new project, add it to the current workplace, a Win32 Dynamic-Link Library project.
  • Make it "An empty DLL Project"
  • Now click "Finish"
  • To the linker option add \NOENTRY in the "Project Settings", "Linker" pane, "Project Options" section.
  • Copy all the resources from the main program to the new DLL.
  • A useful trick is to create a dummy project, and select the language that you want the resources to be in, then copy the strings, menus etc. across, this does save a bit of time.
  • Possibly changing the properties to the language that matches the DLL, although this is not strictly required.
  • Now "simply" translate the Strings, Menu, Dialog boxes etc.
  • Certain languages will have far longer text strings than English, therefore it is likely that the dialog box layouts may change.


  • The resource ID values MUST be consistent (i.e. the same) between all the resources language DLLs.
  • You may find that the DLLs do not always compile correctly when doing a build, you may need to do a "Rebuild All" on them.
  • The DLLs are placed into the MultiLang Release or Debug directory after linking.
  • The translations were done on the Internet, so they may not be 100% correct!


  • The sample project MUST be compiled using the "Build", "Batch Build" option.
  • The EXE and DLLs are provided in the demo.


  • Original Version
  • Display today's date in the selected language
  • Use Accelerators
  • Use a Custom Common Dialog


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Ted Ferenc
Web Developer
United Kingdom United Kingdom
Ted wrote his first program c. 1972, and has been writing software professionally since 1975. For his sins he has been a user of Visual C++ from version 1.0 days.

On the odd days that he leaves his PC he is into walking in the Peak District, but tends to get waylaid at the lunch time pub.

You may also be interested in...

Comments and Discussions

GeneralRe: Translated strings appear like this "???". Pin
Ted Ferenc17-Aug-06 1:28
memberTed Ferenc17-Aug-06 1:28 
GeneralRe: Translated strings appear like this "???". Pin
p_shetty17-Aug-06 19:31
memberp_shetty17-Aug-06 19:31 
GeneralRe: Translated strings appear like this "???". Pin
p_shetty20-Aug-06 18:19
memberp_shetty20-Aug-06 18:19 
GeneralRe: Translated strings appear like this "???". Pin
BadBoy_Prez25-Jan-07 16:53
memberBadBoy_Prez25-Jan-07 16:53 
GeneralRe: Translated strings appear like this "???". Pin
Ted Ferenc21-Aug-06 6:17
memberTed Ferenc21-Aug-06 6:17 
GeneralRe: Translated strings appear like this "???". Pin
Tarekat17-Nov-06 22:36
memberTarekat17-Nov-06 22:36 
GeneralRe: Translated strings appear like this "???". Pin
Hamp Turner29-May-07 9:47
memberHamp Turner29-May-07 9:47 
QuestionCustomize common dialog Pin
karthikoncodeproject13-Jul-06 2:50
memberkarthikoncodeproject13-Jul-06 2:50 
QuestionUser input String and log file Pin
karthikoncodeproject12-Jul-06 2:42
memberkarthikoncodeproject12-Jul-06 2:42 
AnswerRe: User input String and log file Pin
Ted Ferenc12-Jul-06 6:24
memberTed Ferenc12-Jul-06 6:24 
GeneralIn MDI Applications Failed!! Pin
lupyhlp092511-Jan-06 19:32
memberlupyhlp092511-Jan-06 19:32 
GeneralRe: In MDI Applications Failed!! Pin
Ted Ferenc11-Jan-06 21:43
memberTed Ferenc11-Jan-06 21:43 
GeneralRe: In MDI Applications Failed!! Pin
lupyhlp092512-Jan-06 0:02
memberlupyhlp092512-Jan-06 0:02 
GeneralRe: In MDI Applications Failed!! Pin
Ted Ferenc12-Jan-06 21:33
memberTed Ferenc12-Jan-06 21:33 
GeneralImplement In MDI Applications! Pin
krasi_top4-Oct-05 20:39
memberkrasi_top4-Oct-05 20:39 
GeneralRe: Implement In MDI Applications! Pin
Ted Ferenc5-Oct-05 7:45
memberTed Ferenc5-Oct-05 7:45 
GeneralFrench words doesn't swap in AboutBox Dialog Pin
Jasonwu2319-Sep-05 0:09
memberJasonwu2319-Sep-05 0:09 
GeneralRe: French words doesn't swap in AboutBox Dialog Pin
Ted Ferenc19-Sep-05 1:15
memberTed Ferenc19-Sep-05 1:15 
GeneralDocked DialogBar Pin
turtleshell4-Aug-05 11:32
memberturtleshell4-Aug-05 11:32 
GeneralRe: Docked DialogBar Pin
Ted Ferenc5-Aug-05 3:43
memberTed Ferenc5-Aug-05 3:43 
GeneralRe: Docked DialogBar Pin
turtleshell5-Aug-05 6:35
memberturtleshell5-Aug-05 6:35 
GeneralRe: Docked DialogBar Pin
Ted Ferenc5-Aug-05 7:38
memberTed Ferenc5-Aug-05 7:38 
Generaldialogs! Pin
dSolariuM9-Jul-05 19:16
memberdSolariuM9-Jul-05 19:16 
GeneralRe: dialogs! Pin
Ted Ferenc9-Jul-05 21:18
memberTed Ferenc9-Jul-05 21:18 
GeneralRe: dialogs! Pin
dSolariuM10-Jul-05 22:24
memberdSolariuM10-Jul-05 22:24 
GeneralRe: dialogs! Pin
Ted Ferenc11-Jul-05 21:16
memberTed Ferenc11-Jul-05 21:16 
agutnick1-Jun-05 4:13
memberagutnick1-Jun-05 4:13 
GeneralRe: NEWFILEOPENORD DIALOG not works Pin
Ted Ferenc1-Jun-05 6:06
memberTed Ferenc1-Jun-05 6:06 
GeneralRe: NEWFILEOPENORD DIALOG not works Pin
agutnick1-Jun-05 21:31
memberagutnick1-Jun-05 21:31 
GeneralRe: NEWFILEOPENORD DIALOG not works Pin
Ted Ferenc2-Jun-05 23:33
memberTed Ferenc2-Jun-05 23:33 
GeneralCustom control troubles Pin
Kaworu229-May-05 23:35
memberKaworu229-May-05 23:35 
GeneralRe: Custom control troubles Pin
Kaworu231-May-05 0:37
memberKaworu231-May-05 0:37 
GeneralRe: Custom control troubles Pin
Kaworu27-Jun-05 20:38
memberKaworu27-Jun-05 20:38 
GeneralRe: Custom control troubles Pin
ctodor31-Aug-05 5:05
memberctodor31-Aug-05 5:05 
GeneralRe: Custom control troubles Pin
Kaworu223-Mar-06 5:09
memberKaworu223-Mar-06 5:09 
GeneralInitialize my App in CDialogs Pin
Kaworu223-May-05 0:01
memberKaworu223-May-05 0:01 
GeneralRe: Initialize my App in CDialogs Pin
Ted Ferenc23-May-05 0:18
memberTed Ferenc23-May-05 0:18 
GeneralRe: Initialize my App in CDialogs Pin
Kaworu223-May-05 3:01
memberKaworu223-May-05 3:01 
GeneralRe: Initialize my App in CDialogs Pin
Kaworu223-May-05 4:34
memberKaworu223-May-05 4:34 
GeneralRe: Initialize my App in CDialogs Pin
Ted Ferenc23-May-05 5:10
memberTed Ferenc23-May-05 5:10 
GeneralRe: Initialize my App in CDialogs Pin
Kaworu229-May-05 20:23
memberKaworu229-May-05 20:23 
GeneralRe: Initialize my App in CDialogs Pin
jeffreycui@hotmail.com3-Aug-06 11:09
memberjeffreycui@hotmail.com3-Aug-06 11:09 
GeneralMDI Form View Application Pin
Ben D.24-Mar-05 4:37
memberBen D.24-Mar-05 4:37 
GeneralRe: MDI Form View Application Pin
Ted Ferenc24-Mar-05 5:49
memberTed Ferenc24-Mar-05 5:49 
GeneralDialog Based applications Pin
Koderiter14-Feb-05 11:49
memberKoderiter14-Feb-05 11:49 
GeneralRe: Dialog Based applications Pin
Ted Ferenc14-Feb-05 22:04
memberTed Ferenc14-Feb-05 22:04 
GeneralRe: Dialog Based applications Pin
Shallyee Shang15-Sep-11 14:06
memberShallyee Shang15-Sep-11 14:06 
GeneralAdd a japanese language (step by step) Pin
YSLYSL31-Jan-05 14:35
memberYSLYSL31-Jan-05 14:35 
GeneralRe: Add a japanese language (step by step) Pin
Ted Ferenc31-Jan-05 22:51
memberTed Ferenc31-Jan-05 22:51 
GeneralRe: Add a japanese language (step by step) Pin
YSLYSL1-Feb-05 4:53
memberYSLYSL1-Feb-05 4:53 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160530.1 | Last Updated 15 Dec 2002
Article Copyright 2002 by Ted Ferenc
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid