Vista SDK里带了一个Samples/winui/MUIAppSample, 这个演示了如何制作MUI应用程序
获取当前用户的默认UI语言: GetUserDefaultUILanguage
Retrieves the user UI language for the current user. If the current user has not set a language, GetUserDefaultUILanguage returns the language identifier for the system default UI language.
如何获取一个Module指定语言的某个资源
以获取MUIAppSample.exe中的日语的IDC_GOSTR(ID为104)为例:
// 0x0411 是日语的语言ID
// 查看所有的语言ID和描述的对应关系, ms-help://MS.LHSMSSDK.1033/MS.LHSWinSDK.1033/intl/nls_238z.htm
HINSTANCE h = LoadMUILibrary (L"D://Win32//Release//MUIAppSample.exe", MUI_LANGUAGE_NAME, 0x0411);
if (h != NULL)
{
LoadString(h, 104, szTitle, MAX_LOADSTRING);
FreeMUILibrary (h);
}
更多的Cases
Loading Win32 MUI Resource Files
This topic discusses the loading of user interface resources on Windows Vista and on pre-Windows Vista operating systems. For an MUI application targeted at Windows Vista, the Windows Vista resource loading functions contain the proper logic to retrieve the correct language resources in the language-specific resource (.mui) files at runtime. However, the Windows Vista resource loading technology does not exist on pre-Windows Vista operating systems. Therefore, you must modify your MUI application code to load the appropriate resources on such an operating system.
The MUILoad library furnished by the Microsoft Windows SDK for Windows Vista includes the LoadMUILibrary and FreeMUILibrary functions. These functions can be used by your MUI applications targeted at either Windows Vista or a pre-Windows Vista operating system to load and unload resources based on operating system user interface settings. The LoadMUILibrary function returns a handle to the appropriate LN file based on operating system user interface language settings, and the FreeMUILibrary function closes the handle. The fallback priority used in LoadMUILibrary is user UI language, followed by system UI language and system default UI language. If the function cannot find an LN file in these languages, it returns the handle of the .mui file located in the same folder as the code .dll. If the .mui file does not exist either, the function returns a handle to the binary file that contains the code.
Note: MUILoad library functions are based on the assumption that the MUI application uses Win32 MUI resource configuration . If your application uses another resource technology, it must implement its own approach to loading resources.
Note: Because a particular user's language preferences might include languages that are not supported by your MUI application, the application should always handle these languages by loading the appropriate fallback resources.
Loading Win32 MUI Resources on Windows Vista Only
This section discusses the loading of Win32 MUI resources on Windows Vista only.
Load Resources Based on Operating System User Interface Language Setting
For most situations, your application targeted at Windows Vista can let the operating system load the correct resources according to the operating system user interface language settings for the current user. The Win32 resource API functions, for example, FindResourceEx and LoadString , have been modified to load resources from the .mui files automatically. Your application can include calls to these functions, treating the resources as if they are contained in the LN file. Thus, your application refers to resources through a handle to the loaded LN file. The application does not have to load any .mui files explicitly.
Here is an example of application code that loads an LN file based on operating system user interface language settings:
HMODULE hResModule = LoadLibraryEx(TEXT("Mymodule.dll"), 0, LOAD_LIBRARY_AS_DATAFILE);...
LoadString(hResModule, myID, lpBuffer, cbBufferSize);...
FreeMUILibrary(hResModule);
Load Resources Based on User-selected Language or a Specific Language Identifier
When your MUI application supports more languages than the operating system does, the loading logic of the application should allow the user to select a different language for the application user interface. To react to this setting, the application must set the thread-preferred UI languages using SetThreadPreferredUILanguages to guide the resource loader to the correct language resources. After that, finding and loading the .mui files according to the thread-preferred UI languages is transparent to the code. Here is an example that loads an LN file based on a specific language identifier compatible with all Windows operating systems, including Windows Vista:
LANGID langid;
... insert code here to get the language identifier for the user's application language preference...
or
... insert code here to get the language identifier for the specific operating system user interface language setting...
HMODULE hResModule = LoadLibraryEx(TEXT("Mymodule.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE);...
HRSRC hResInfo = FindResourceEx
(hResModule, RT_DIALOG, myID, langid);...
FreeLibrary(hResModule);
Loading Win32 MUI Resources on Windows Vista and Pre-Windows Vista Operating Systems
This section discusses the loading of Win32 MUI resources on all Windows operating systems, including Windows Vista.
Load Resources on Multiple Operating Systems Based on User UI Language Setting
The following code example loads an LN file based on a user UI language setting that is compatible with all Windows operating systems including, Windows Vista:
#include "MuiLoad.h"
HMODULE hResModule = LoadMUILibrary(TEXT("Mymodule.dll"), MUI_LANGUAGE_NAME, 0);...
LoadString(hResModule, myID, lpBuffer, cbBufferSize);...
FreeMUILibrary(hResModule);
Load Resources on Multiple Operating Systems Based on User-selected Language or a Specific Language Identifier
The following is an example of code that loads an LN file based on a specific language identifier that is compatible with all Windows operating systems, including Windows Vista:
#include "MuiLoad.h"
LANGID langid;
... insert code here to get the language identifier for the user's application language preference ...
or
... insert code here to get the language identifier for a specific operating system user interface language setting ...
HMODULE hResModule = LoadMUILibrary(TEXT("Mymodule.dll"), MUI_LANGUAGE_ID, langid);
HRSRC hResInfo = FindResourceEx(hResModule, RT_DIALOG, myID, langid);...
FreeMUILibrary(hResModule);
Load a Specific LN File
If the application has the exact path of the LN file to load, it can retrieve a handle to the file by calling LoadLibraryEx . The application can then use the retrieved handle in all subsequent calls to load resources. Here is an example of code that loads resources only from an LN file compatible with all Windows operating systems, including Windows Vista:
HMODULE hResModule =
LoadLibraryEx(TEXT("c://<myfolder>//en-us//MyResourceModule.dll.mui"), NULL, NULL);...
HRSRC hResInfo = LoadString
(hResModule, myID, lpBuffer, cbBufferSize);...
FreeLibrary(hResModule);
本文介绍如何在Windows Vista中使用MUI技术加载多语言用户界面资源。包括根据用户界面语言设置加载资源的方法,以及在不同操作系统上实现多语言支持的策略。
3848

被折叠的 条评论
为什么被折叠?



