Implement MFC-based component localization in VC 5.0

Source: Internet
Author: User

Implement MFC-based component localization in VC 5.0

Zhejiang University computer department 344 mailbox (310027) Zheng Jie
Visual c ++ (VC) is one of Microsoft's visual software development tools. For non-English programmers, software localization is inevitable. VC itself supports multilingual programming, which brings great convenience to localization. Here we mainly discuss the localization of MFC-based components.

To localize the components that use MFC, you need to solve the following two problems.
The first problem is to localize some special resources of components, such as strings and dialog boxes. Most components structured on the basis of MFC also contain and use some resources defined by MFC, so these MFC Resources must be localized at the same time. Fortunately, MFC itself provides localized versions in multiple languages, including Chinese, German, Spanish, French, Italian, Japanese, and Korean. The corresponding/devstudi/VC/mfc/[SRC | include]/L. in the xxx/directory, "L" indicates "localization. CHS stands for simplified Chinese. Copy the *. RC file in these directories to the corresponding directory on the hard disk. This method should be used when the static link mode is used between the application and MFC, but it is only supported in the Professional Edition and Enterprise Edition of VC 5.0.
Most applications and MFC use dynamic links. At this time, the local version of the corresponding MFC resource DLL file must be available under the system directory of Win95-mfc4xloc. DLL (pwin95 oemsr2 provides mfc0 loc. DLL ). Copy the file mfc42xxx in the directory/devstudio/VC/redist of the VC disc. DLL is copied to the system directory of pwi95 and renamed to mfc42loc. DLL (mfc42chs. DLL stands for the resource DLL file in the Simplified Chinese version ). In addition to solving the version issue of DLL with the same name, you should also pay attention to the following two aspects:
First, you should not install mfc4xloc. dll on an English version system (such as Win95. Because the English version of resource file code has been built in mfc4x. dll, it is much faster for applications to load code from mfc4x. dll than to search for and Load Code first from mfc4xlocd ll.
Second, because there are multiple versions of mfc4xloc. DLL, which can be found at the same time in the directory/devstudio/VC/redist of the VC disc, such as mfc4xchs. DLL-Simplified Chinese version, mfc4xdeu. DLL-German version, mfc4xesp. ll-the Italian version.
Therefore, before installation, determine the installed mfc4xloc. whether the local version code of DLL is consistent with the window system used, for example, only mfc42chs. dll can be installed on the pwin95 system.
It should be pointed out that the above method will bring some complexity to the application installation, because the user's system may install a variety of localized versions of the application. For example: supports Simplified Chinese, and later installed a Japanese version of software to link the library file mfc4xloc. there is only one DLL. If the latter overwrites the former, a Resource Link error occurs when the application is running. Therefore, we recommend that you create your own local version of the MFC resource DLL file instead of directly calling the mfc4xloc. dll file. This method will continue to be analyzed later.

Process Code
The second problem is that the code of the localized resources of each component should be processed to make it run well in the target environment. In most cases, this depends on the application's processing capabilities for high bytes and dubyte characters. By default, MFC directly supports them.
Therefore, local applications and DLL only need to rewrite the corresponding resources in the local language. If the C ++ Source Code does not contain a string or body that requires localization, you only need to modify the resource file. In fact, you can implement your own components so that you can obtain the local version without recreating the original code. This may be complicated, but it is worth it. MFC also uses this technology. You can open the resource file editor and edit it in the local language. However, you need to re-build the application for each version upgrade.
Note: VC 4.0 or later versions directly support. RC files in multiple languages.
One way to avoid this is to create a separate DLL and localize it. This dll is sometimes called a satellite DLL ". When the program runs, it will be dynamically linked. Resources will be loaded from this "satellite DLL" instead of from the main module of the Code. MFC directly supports this method. mfc4xloc. dll itself is a localized "satellite DLL", but it is provided by MFC by default. We can create a satellite DLL of our own. For example, if an application named MyApp. EXE comes from a file named Myres. dll. These are all completed in the initinstance event of the application, as shown below:
Cmyapp: initinstance ()
{
// Start part of the initialization code
Hinstance hinst = loadlibrary ("Myres. dll ");
If (hinst! = NULL)
Afxsetresourcehandle (hinst );
// Other initialization code
.
.
.
}
After this code is executed, MFC will load resources from Myres. dll, rather than directly from MyApp. EXE.
Creating a single resource DLL file is not difficult. Create a DLL project file, add the. RC file and other necessary resources, and add a "/noentry" parameter to the linker parameter. This parameter tells the linker that the DLL has no access point because the resource DLL file has no code.
In addition, if the application is created in Win32 release mode (that is, the debug code is not embedded in the EXE file), you need to complete the following steps. In the project file, open the menu projects/settings ..., select the C/C ++ page and R esources page respectively, and remove the parameter [/D "_ afxdll"] (which is generally automatically generated by Appwizard ). This parameter specifies that only resources are loaded from the shared DLL file of MFC, and other resource sources are not defined, so that the resource DLL file created by the user does not work.
Finally, because Appwizard is a major feature of VC ++, VC ++ allows you to select different languages when using Appwizard to create an MFC-based application framework, directly generate a local program framework. Because the dual-byte operating system is required, the MFC Appwizard DLLs corresponding to the three Far East languages was not mounted to the hard disk by the VC 5.0 installer. Therefore, these language entries cannot be found in the drop-down list box on the first page of the Application Generation wizard, but can be found in the/devstudio/nvidide/Bi/ide directory of the VC disc:
Language: Appwizard DLL
-----------------------------------
Japanese ---- appwzjpn. dll
Korean ---- appwzkor. dll
Simplified Chinese ---- appwzchs. dll
In the Simplified Chinese pwin95, you only need to copy the corresponding appwzchs. dll file from the VC disc to the/devsudio/nvidide/bin/ide directory on the hard disk. In this case, the entry "simplified Chinese" appears in the drop-down list box on the first page of the Application Generation wizard, the application framework generated by Appwizard automatically contains the menu, title, and status bar in simplified Chinese. After compiling the Framework Program, we will see a beautiful all-Chinese interface.
Therefore, it is very convenient to use VC to create Simplified Chinese. If you are interested, you can continue to view the VC help system for more information.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.