Solved

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

Posted on 2003-11-28
20
319 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:sacchit
  • 10
  • 6
  • 4
20 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9836308
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.
0
 
LVL 3

Author Comment

by:sacchit
ID: 9837164
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9837176
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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9837528
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.

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9837715
... 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().
0
 
LVL 3

Author Comment

by:sacchit
ID: 9837949
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
0
 
LVL 3

Author Comment

by:sacchit
ID: 9838023
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 .
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9838321
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 (http://www.codeproject.com/tools/smarttranslator.asp). 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.
0
 
LVL 3

Author Comment

by:sacchit
ID: 9841342
Hi,
     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
 
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9842337
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Author Comment

by:sacchit
ID: 9844772
Ok i will have to use  the translator for the resource dll.and for the xml soln as well.
0
 
LVL 3

Author Comment

by:sacchit
ID: 9850674
Hi,
    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.
thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9850954
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.
0
 
LVL 3

Author Comment

by:sacchit
ID: 9880259
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. http://www.idevresource.com/vs/library/articles/alteringresources.asp. 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.
thanks
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9881165
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"
0
 
LVL 3

Author Comment

by:sacchit
ID: 9882893
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.
thanks
0
 
LVL 3

Author Comment

by:sacchit
ID: 9882914
Andy,
Can the menus from resources  which have value sfrom the string table  be modfied (Captions)
at runtime?
Thanks again
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9883010
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
0
 
LVL 3

Author Comment

by:sacchit
ID: 9918055
Hi,
   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:
free((void*)m_pszExeName);
//Change the name of the .EXE file.
//The CWinApp destructor will free the memory.
m_pszExeName=_tcsdup(_T(?d:\\somedir\\myapp?));
But it does not work
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 250 total points
ID: 9918601
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?
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 125
viewing source code from eclipse 13 74
only14 challenge 19 64
canBalance challenge 34 65
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now