sacchit
asked on
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.
ASKER
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.
The requirement for the app is that the exe should be lighter as the app is a graphic image editor.
thanks again andy.
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.
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.
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.
... 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().
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().
ASKER
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
Thank you
ASKER
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 .
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.
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.
ASKER
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
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
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.
ASKER
Ok i will have to use the translator for the resource dll.and for the xml soln as well.
ASKER
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
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
pWnd->SetWindowText(szNewT ext) 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.
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.
ASKER
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
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
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"
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"
ASKER
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
thanks
ASKER
Andy,
Can the menus from resources which have value sfrom the string table be modfied (Captions)
at runtime?
Thanks again
Can the menus from resources which have value sfrom the string table be modfied (Captions)
at runtime?
Thanks again
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
There is a sample DYNAMENU maybe that contains useful code
ASKER
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
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
But it does not work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.