How to Localize Application Resources with Foundation ClassesLast reviewed: July 31, 1997Article ID: Q147149 |
WINDOWS | WINDOWS NT1.00 1.50 1.51 1.52 | 1.00 2.00 2.10 2.20 kbprg kbhowto kbcode The information in this article applies to:
SUMMARYMicrosoft Foundation Class Library Technical Note 23 explains how to customize standard framework resources, such as the buttons on a print preview dialog bar. However, this technical note does not provide a good solution for developers who are producing an application localized into more than one language, and there is a problem with the method described. When localizing an application for several languages, it is most convenient to place all of the application's resources into a dynamic link library (DLL). To localize the application into a new language, clone the DLL and translate the resources into the appropriate language. After testing, you can ship the application code with the appropriate language-specific DLL to address each market. The remainder of this article outlines the general steps required to localize an application by moving the resources into a DLL.
MORE INFORMATIONTo place all application resources into a DLL project, open the .rc file in App Studio. Choose Save As from the File menu to store the resources into another directory (created for this purpose). Then open the original .rc file, and remove all resources visible in the App Studio Resource Browser. Finally, choose Set Includes from the App Studio File menu. Delete the #include statements for Afxprint.rc and for Afxres.rc from the Compile-TimeDirectives list and choose OK. Use the Visual Workbench to create a new Windows DLL project for the resources. Set the project type to Windows dynamic-link library, and clear the "Use Microsoft Foundation Classes" check box. Add the .rc file to the project. Then create the following files in your DLL directory, and add them to the project.
Mylocal.cpp
#include <windows.h> int CALLBACK LibMain(HINSTANCE hinst, WORD wDataSeg, WORD cbHeap, LPSTR lpszCmdLine ){ return 1;}
Mylocal.def
LIBRARY MYLOCALDESCRIPTION 'Localized resources for MFC application' EXETYPE WINDOWS CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD MOVEABLE SINGLESEGMENTS WEP_TEXT FIXED PRELOADEXPORTS WEP @1 RESIDENTNAME ; required WEP entry point ; (uses library WEP routine)Copy the standard framework resources into the .rc file for your DLL so you can modify them. Technical Note 23 outlines a procedure to do this. To copy all resources from Afxprint.rc and Afxres.rc into the .rc file for your DLL, select the resources in each source file. Then press and hold the CTRL key and drag the resources into the new .rc file. Edit the Compile- Time Directives list box in App Studio to remove the #include files. There are two problems with this procedure. Perform the following two steps to work around these problems before compiling your DLL: NOTE: In MFC version 2.5 and later, step 1 is no longer necessary.
Build the DLL project and copy it into your application's directory. To use the localized resources in the DLL from your application, add the following code to your application and rebuild it:
For more information on this procedure, see the Microsoft Foundation Class Library Technical Notes. The Visual C++ 1.0 for Windows setup program creates an MFC Tech Notes icon in the Visual C++ 1.0 group.
|
Additional reference words: 1.00 1.50 2.00 2.50 2.51 2.52 2.10 2.20
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |