changing the language locale (resources) at run time through xml.

I am still quite new in c++ prog .I want an win app to load ( language selection ) locale settings at runtime independent of the exe through an xml file in vc++6. Is that possible  as what i have seen on the web all the dialog boxes,menus  are made in respective locale and then the respective string table is called to access those  specific languages.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Usually one localises language support with a dll which contains the strings.  One then loads the appropriate dll into the memory space of the exe.
If you wanted to use an xml file per language you could do so.  You would need to extract the appropriate string and display it (eg. SetWindowText, SetDlgItemText) for each window/control you have.  Tooltips would require a callback for the text and menu's would have to be destroyed/recreated dynamically when you switch a language.
sacchitAuthor Commented:
I want the xml file to contain all any language .So the string values of each resource  eg a menu item or a dialog  will be accessed by the dynamically generated resource from the xml file in the respective language.thanks for that info.But then the bitmap or ico files, images will be a part of the exe .I would like to have a little more info on how the resources will be stored.
The requirement for the app is that the exe should be lighter as the app is a graphic image editor.
thanks again andy.
Karl Heinz KremerCommented:
It's easier to to this with a resource DLL because a number of MFC functions take a string ID as a parameter, so that you don't have to load the string, but it can certainly be done with any source for your strings. You would - when your program starts - determine which language you have to run in, then load the XML file and extract all the strings, and store them e.g. in a CMap or a vector so that you can access an indivudual string by a an index. Then at the time you want to use the string, you can access the translated string by going into your string collection and extract one specific string by specifying the string ID.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

AndyAinscowFreelance programmer / ConsultantCommented:
Are images language dependant?  And how do you intend to store them as XML?
I would go for a resource dll per language.  You could keep bitmaps and icons in that.

Have a look at the AfxSetRecourceHandle function in the help file.

Karl Heinz KremerCommented:
... or you could combine both mechanism. Even tough I would use resource DLLs, I can see the potential advantage an XML file has: You can change it without any special tools. If your images, dialogs, (and all the other resource elements besides the strings) don't have to be as accessible as the strings, store them in a resource DLL and then dynamically load the strings from your XML file.

I'm not saying you should do this, but if you are absolutely set on using XML files, it's possible.

If you want to use resource DLLs, there are tools available to change string information in a resource DLL without the need for Visual Studio. So if you need a mechanism for your translators to access and change this data, you can do this with resource DLLs as well. Maybe you should tell us why you want to use XML files instead of resource DLLs.

BTW: The correct process is to first call LoadLibrary() to load your resource DLL, followed by the call to AfxSetResourceHandle() which AndyAinscow listed. You would pass in the resource handle returned by LoadLibrary().
sacchitAuthor Commented:
I have to look for and work on the code .But What  i have learnt from you friends if not wrong  is that  to store the images in the dll (language independent) and the string values in the xml file so that the application (to my knowledge) will  become more easy to switch to other language by any end user just by making changes to the xml file without affecting th exe or the dll.Is that right plz correct it.  
Thank you
sacchitAuthor Commented:
khkremer Comment on why xml to use instead of just the resource dll because i was not sure whether  a resource dll can be changed (ie the language string data)  that easy or is it really possible without much of a hassle.  XML  only because as you said ..............You can change it without any special tools and easier.Independent to the exe and the dll the data would be more easy to handle by end user  Is a end user view i have.Any better option .
Karl Heinz KremerCommented:
sacchit, I have a really hard time to understand what you are saying. I understand that English is not your native language. So if my answer is not what you asked for, please try to explain your question in different words.

I think you asked for a tool that can be used to translate the string resources in a DLL or an executable. Try the SmartTranslator from CodeProjet ( This is a free tool that will extract, change and update string resources in an executable. You could point your users to this tool.

Again, if this is not what you asked, please try again.
sacchitAuthor Commented:
     I would want to store images in the dll, create menus and dialog dynamically if it is possible  and store strings in  xml.The xml file will be editable without having to recompile  the exe.

Comments of  AndyAinscow and  khkremer  suggest to me the above said is possible.I think i am reasonably clear now.And if i am not clear i am ready to explain again.

thank you
Karl Heinz KremerCommented:
Yes, this is possible, but with the tool I recoommended (SmartTranslator), you can have the same by just using a resouce DLL: You can translate (or your users can) the application without recompilation by using SmartTranslator, which can modify string resources in an executable.
sacchitAuthor Commented:
Ok i will have to use  the translator for the resource dll.and for the xml soln as well.
sacchitAuthor Commented:
    I just want to store the captions of the menus,dialog box,messagebox text in the xml file.
And for that i want  the code to  change  AT RUNTIME  the captions or Assign the caption to the respective active controls resources which are  there in the resource dll  or exe.
If that is possible you can   really  help.
Because in VB6 you can change the caption,title  properties  of controls at runtime so that should be possbile.
AndyAinscowFreelance programmer / ConsultantCommented:
pWnd->SetWindowText(szNewText) will modify text of a lot of things.  To get a pointer to a wnd for buttons (and other controls) on dialogs use GetDlgItem(IDC_xxx).
To change the menu text at runtime I think you have to destroy the menu and recreate it with your new text.  For tooltips I think you will need to set it as a callback when you cretae them.
sacchitAuthor Commented:
Ok some things to be cleared
1. Andy I can change the caption  of  the Application with SetWindowText(szNewText)  but when i open a document the  name caption of the application  is over  written.
2.i got an article to change resource at run time. is i that the  answer for my soln.i will be accessing the strings from the xml file .
3.Another  problem i am having is when i access the xml dom document  for the strings for captions Each time  i have to load th xml file to change the caption of an item in the exe.Any help  on keeping the xml file loaded in there and just access the file in memory.
AndyAinscowFreelance programmer / ConsultantCommented:
In the resource file the strings are associated with an ID (eg. 1234 via an ID such as IDS_MYSTRING).  So store in your xml file the integer ID along with the string.

When you read in your xml file have a map structure to store the info in.
eg. in the .h file for your app
CMap<int, int, CString, CString&> m_mapStrings;

When you read in your xml file
int iD;    //=1234
CString szValue;    //="this is the title of my app"
m_map.Add(ID, szValue)

When you want a value back
int ID = 1234;
CString s;

m_mapStrings.Lookup(ID, s);
now s contains "this is the title of my app"
sacchitAuthor Commented:
Andy you said that menus have to be dynamically created  and destroyed .I have 3 menus and they  are too hugh to be dynamically created each  with lots of funcitons  have ssome graphics as well.Can you give an example of  top-level menu to be modified ie change the captions instead of the creating the whole menu dynamically.I tried but they some how crash the app at run time with fatal error.
sacchitAuthor Commented:
Can the menus from resources  which have value sfrom the string table  be modfied (Captions)
at runtime?
Thanks again
AndyAinscowFreelance programmer / ConsultantCommented:
Have a look at the CMenu::ModifyMenu command in help.  That may well allow you to modify the text of the menu's that appear, whether it changes the text in the menu bar I don't know.  I haven't actually done this task myself.

There is a sample DYNAMENU maybe that contains useful code
sacchitAuthor Commented:
   I have got one problem with the appliction window name.I can change the name of the window with SetWindowText.
 But once I open a document in the application the application window name  changes to the earlier  name of the application.
i TRIED the thing below in the constructor of the App object:
//Change the name of the .EXE file.
//The CWinApp destructor will free the memory.
But it does not work
AndyAinscowFreelance programmer / ConsultantCommented:
The app requeries the resources for the name of the app (another reason for using the dll method).
One work around is to handle the OpenDoc command yourself, call the base implementation and then reset the name of the app to what you want.
Of interest why is the name of your app language dependant?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.