Program to achieve multi-language dynamic switching solutions Author: Geng sea by
Download Try Source Code (Download Link of VC Knowledge Base) Implementing Thoughts: Traditional practice is to put all resources into dynamic libraries, a dynamic library, and the program is running by loading different dynamic libraries. Language features. The disadvantage of this is that it cannot be dynamically switched. If the language must be restarted after replacing the language. Of course, no one will need a frequent switching language to play, but use dynamic libraries, if the program needs to modify resources, you will update all dynamic libraries, which is a very boring and easy to have a honest work.
My way is to put all the strings used in the files in the file, a language, and load the string based on the selected language to the corresponding file. This can not only dynamically switch language, but users can add new languages as needed.
Specific implementation: 1. Check the selected language when the program starts, determines the language file, save the file path
2. Provide a full-class function, such as g_loadstring (CString Szid), returning its content according to the supplied string ID, which language is determined in the function, so as long as a string ID is provided in the program, you can automatically load different languages. The text.
3, how to use in the program: Original code:
CString Str;
Str = "Language"; after the change:
CString Str;
Str = g_loadstring ("ids_language"); 4, how to implement in the dialog
If you use it in the program, if each string is loaded, if the dialog is more, the workload can be too big.
So I provide a function g_setdialogstrings (CDIALOG * PDLG, UINT UDLGID), each dialog box calls the function when the dialog is initialized, pass the pointer to the dialog, and I will loop all the child controls in the function, set the text one by one. This will save a lot of work.
Note: Since the static text (cstatic) default ID is IDC_STATIC, the value is 65535, it is impossible to distinguish, so you need to change the CSTATIC to change its text, you can't use the default
5, language file sample: Chinese version:
[Setting]
Language = Chinese
[String]
IDS_MENU_FILE = File
IDS_MENU_FILE_NEW = New (& n)
IDS_MENU_FILE_OPEN = Open (& O)
IDS_MENU_FILE_CLOSE = Off (& C)
IDS_MENU_FILE_EXIT = Exit (& E)
English version:
[Setting]
Language = 中文 =
[String]
IDS_MENU_FILE = file
IDS_MENU_FILE_NEW = & New
IDS_MENU_FILE_OPEN = & Open
IDS_MENU_FILE_CLOSE = & close
IDS_MENU_FILE_EXIT = & exit