Home > Software engineering >  Using VB6 development of multilingual application strategy resource file
Using VB6 development of multilingual application strategy resource file

Time:09-24

VB6 is considered by many programmers as a gas development tool, but it is Microsoft's most classic development tools, there is no one! Compile the program short, is generally a few K, and since XP operating system, must carry its runtime library, as long as using only standard controls of the VB program, don't even need to install, can be run directly, so, not too complex GUI program I use VB6 development, that how to call a fast word get!
Recently, I made a Mini flow chart of software, but need to support multiple languages, checked the online information, feeling is fake, is essentially a headache cure head, feet hurt the medical foot, without a comprehensive control scheme based on the system, then carefully studies the resource file system, VB6 realize Microsoft already provides a perfect solution, is China's most programmers are not used to this kind of aristocratic elegance, VC6 also using this mechanism, but the GUI done worse than VB a few streets, intuitive, nothing about programmer intelligence quotient (IQ) below 120 for the basic functions, but after the VC has inherited the mechanism of Visual Studio (although the expression is still so bad), don't like VB. Net began to forsake this mechanism, using the simple and crude way to solve, perhaps, simple and crude is the trend of society, but I still pursue the elegant, so the following only applies to pursuit perfect have abnormal condition of the classmates,
VB6 resource file generally include strings, ICONS, cursors, and user defined byte stream, a total of five types of resources, the instance of each resource has two properties, one is the resource ID, another is the language ID, that is, a resource need two ID logo together, for example: a string resource ID is 101, the Chinese language ID is 1028 string content is Taiwan, its language ID is 1033 string content is American English, the language ID is 1049 string content is Russian, the language ID is 2052 string content is China's Chinese, English is the language ID is 2057 string content in English, and so on, as shown is the string resource editor VB6, intuitive! VC development project manager's arrogant!

When a program requests resources, only need to enter a resource ID parameter, runtime library based on the system language ID automatically returns the corresponding resources, for a quick buck the classmates, these basic will do the trick, because the project manager said do 8 languages, most programmers do not consider the feelings of the ninth peoples, later will share VB6 resource file system read strategy to elegant solution to the problem of the ninth peoples,
Before this, have to popularize the Windows kernel knowledge of many languages, from Microsoft NT start using Unicode kernel, its advantage is to reduce the cost of the global deployment, Microsoft's global as one of the important means of technical support, for the user, the advantage of the most intuitive is the output of a string inside can contain multiple foreign languages at the same time, although the demand is very rare, but switch languages that with the support of Unicode technology, it is not matter!
Although Windows at the launch of the bond, pointed out the language versions, but in fact, any language Windows support any Microsoft supported language, so in the language, Windows has two levels of language, one kind is Installed level (Installed), namely the System (the System) language; The other is a support level (Supported), namely User (User) language,
Under normal circumstances, the system of language and language is the same, the second as a what? For example, in an international school, the teacher is American, he certainly install English version of Windows, but his students were French, German, Chinese, Korean, is no americans! To consider the students' patriotism, the teacher assigned to each of them a login account, after logging in, can modify the control panel in the region and language, in order to conform to the habit of each student, in this way, in the context of each student's login session system language is English, the user language is the language of the user in the control panel to set,
OK, now let's see the VB6 runtime library is how to action for the resource request, when a program requests resources, only need to enter a resource ID parameter, runtime library ID the first to use the user ID and the language of a resource required to service this request have all language ID to match, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you don't succeed, then use the system language ID and requested resource ID have all language ID to match, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you are not successful, then the request of resource ID have all language ID ID value that corresponds to the minimum resource returned,
Look at the example, for your convenience, I added a string resource ID is 99, the inside of the content is the language ID value, if the login session environment of user and system language are not matching, string is returned in Chinese (Taiwan) resources, because 1028 is the least of all provide language ID!
Here, we may soon think of, minimum ID value must be 0, 0 is how to define? Then we have to first take a look at how Microsoft definition language ID:
# define MAKELANGID (PrimaryLanguage, SubLanguage) ((((WORD) (SubLanguage)) & lt; <10) | (WORD) (PrimaryLanguage))
Mean language ID by a 16-bit word means (maximum 65536 languages), mainly including low 10 language ID (maximum 1024 main languages), high six for child language ID (each language has a maximum of 64 seeds),
Subjects and language policy is to express the following situation: languages such as Spanish, the native language is Spanish country in the world more than 20, more than English, this want to ask the 15th century talented, energetic queen Isabella, is her instigate Columbus classmate global settlement caused by our present problems, this more than 20 countries birdcall in Spanish language, but they belong to the Spanish area, this area as the main language,
Main language ID 0 by Microsoft called Neutral language (Neutral), it also has the language, are respectively SUBLANG_NEUTRAL (0), SUBLANG_DEFAULT (1) and SUBLANG_SYS_DEFAULT (2), corresponding to three kinds of Neutral language Neutral, Neutral Default and Neutral System Default,
So, the front is a home edition, now look at Microsoft's runtime library professional version of resource request action, when a program requests resources, only need to enter a resource ID parameter, runtime library ID the first to use the user ID and the language of a resource required to service this request have all language ID to match, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you don't succeed, then back to the main language ID 0 and child language ID is also zero resources; If not found, and then use the system language ID and request the resource ID of all languages have ID matching, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you are not successful, then the request of resource ID have all language ID ID value that corresponds to the minimum resource returned,
So, the best practice using VB6 multilingual resource file is: according to the software is mainly on the language areas, set the language to Neutral Default or Neutral System Default (the two effects, if set to Neutral, the System language will lose an opportunity to match), such as: software ready to put in the European market, only for the project, method, and four languages, you can put the English set to Neutral Default, when a user and System language is not law, Germany, Italy, all in English; If not so configuration, will use ID the youngest language (German), obviously, in Europe, who knew English should be more than people who know German, that was a better user experience,
Of course, the best solution is to provide all language! In fact, is not difficult! The key is to do a good job, must first sharpen his machine!
In 2001, there was a call Phil Jollans (http://www.jollans.com), a German guy made a called World Resource String Editor VB6 plug-in, can directly import from excel String resources! Picture is truth:

I just use this tool, you just need to fill in China (in Chinese) that the content of the column, translate documents distributed to each group, to collect import, work easily outrageous! What? Spanish has 20 countries? Come on, I make a copy of Spanish (Spain) that a list of 20 columns, firing a language ID a change again, easily support all of the Spanish region, feather fan, black silk ribbon scarf Qiang OARS ashes feeling! Meet demand are too weak, forecast demand can be in an impregnable position,
But forecast demand is an intermediate level, only lead demand is the highest realm! What is the highest realm, then? Speaking of which, has solved the problem of 80% above, but spent only 20% of the work force, the following solution to the problem of the remaining 20%, but needs 80% of the work force,
In fact, Microsoft's whole strategy or to demand to know enough full, slightly simple and crude, such as Belgium, a few small European country such as Switzerland also speak French, it to some extend, the standard French like dialect, knows the Belgian French one surely understand French standard French, this is a very natural demand, therefore, resource extraction of complete the optimal strategy should be like this:
When a program requests resources, only need to enter a resource ID parameter, runtime library ID the first to use the user ID and the language of a resource required to service this request have all language ID to match, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you don't succeed, is the main language of the user language ID ID with all requested resource ID have ID's main language ID matching, if successful, the requested resource ID and language ID match Lord face language ID the youngest ID corresponding resource return; If you don't succeed, then back to the main language ID 0 and child language ID is also zero resources; If not found, and then use the system language ID and request the resource ID of all languages have ID matching, if successful, will match the requested resource ID and successful language ID corresponding resource return; If you don't succeed, sent the main language of system language ID ID with all requested resource ID have ID's main language ID matching, if successful, the requested resource ID and language ID match Lord face language ID the youngest ID corresponding resource return; If still not successful, the request of the resources of all the language ID ID have ID value that corresponds to the minimum resource returned, I have already tried life talent in an attempt to let forrest gump can understand it, if you still don't understand, just wash your sleep, natural is the true happiness,
Well, the ultimate showdown blacklist, so good suddenly and violently day demand how gracefully implementation? Read all information about the multinational language resources on MSDN, found a set of modified resources API: BeginUpdateResource, UpdateResource and EndUpdateResource, can modify the language of the resource ID, but still too complex, seriously damaged VB6 the simple beauty of image, in a way of thinking, since change resources so tired, can change the user language? SetLocaleInfo discovered such a function, you can set the user language, ha ha, so, general idea came out: after the start process, first call an adjustment function: this function get the user first language, and language than the existing resources, if there is an exact match, you can quit; If there is no exact match, and then use the user language the main language and language the main language than the existing resources, if there is a match, use SetLocaleInfo language is set to match the user ID, the main language of the language in this way, the resources need to offer a primary language standard language to support the use of the main language of all countries, the system of language change is very troublesome, to call a series of API, need to restart the operating system is the most deadly, this basically gave up, but also no matter, because the user language is the most important basis for matching to the system language to how much it feels a bit like the ostrich,
SetLocaleInfo but real change, however, the user language, even if you quit before the change back to the original user language, will also affect the other after you start the application, what's more, your program is likely to collapse, even have no chance to change back,
Again after careful search, and found that SetThreadLocale, such a function parameter is more simple, the most important is the language of the modified information play a role in this thread only, do not actually modify the user language, this is everyone satisfied!
Have the opinion, email @qq.com, 45672463 titles indicate the figure is big,

CodePudding user response:

CodePudding user response:

Cattle! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related