+ -
当前位置:首页 → 问答吧 → 关于MFC使用多语言的问题

关于MFC使用多语言的问题

时间:2011-12-14

来源:互联网

再使用MFC框架编程时,实现多语言也有很多方案,我个人采取了一个相对简单的方案,即一个ID多份不同语言的资源副本,在Windows NT 3.1及之后版本可以使用SetThreadLocale手工修改UI显示语言,在Vista之后的版本可以使用SetThreadUILanguage方法手工修改UI显示语言,本人采用这种方式可以达到预期的效果,只是这里有一个疑问,在MSDN上明确指出Windwos 2000/xp 不应该使用SetThreadLocale去选择UI语言,而应该使用FindResourceEx,原文如下:

The SetThreadLocale function affects the selection of resources that are defined with a LANGUAGE statement. This affects such functions as CreateDialog, DialogBox, LoadMenu, LoadString, and FindResource, and sets the code page implied by CP_THREAD_ACP, but does not affect FindResourceEx. 

Windows 2000/XP: Do not use SetThreadLocale to select a UI language. To select the proper resource that is defined with a LANGUAGE statement, use FindResourceEx.

这里并没有解释原因,实际使用中如果使用FindResourceEx编码量会大很多,而且直接使用SetThreadLocale完全可以实现预期的目的,这里是很迷惑的地方,请各位了解其原因的朋友指导一下~谢谢!

作者: wjh173069597   发布时间: 2011-12-14

最好使用DLL,不同语言的做个对应的DLL,然后根据选择自行加载,这个是MS推荐的方式

作者: VisualEleven   发布时间: 2011-12-14

引用 1 楼 visualeleven 的回复:

最好使用DLL,不同语言的做个对应的DLL,然后根据选择自行加载,这个是MS推荐的方式


多谢楼主回复,因为我只是做一个小工具,不到2W行代码,一切从简了,不过你说的这个方法虽然知道,但这是MS推荐的方式我倒是才知道的,以前在MSDN上没注意到这个说法,多谢提醒
不过MSDN上的Do not use SetThreadLocale to select a UI language. 到底是不推荐还是不能?
如果是不能的话,又是为什么呢?有隐含的问题存在么?因为通过MSDN查看可以知道:

The SetThreadLocale function affects the selection of resources that are defined with a LANGUAGE statement. This affects such functions as CreateDialog, DialogBox, LoadMenu, LoadString, and FindResource, and sets the code page implied by CP_THREAD_ACP, but does not affect FindResourceEx. 

VS2010版本的MSDN有如下解释:
Windows Vista and later: Do not use SetThreadLocale to select a user interface language. The resource loader selects the resource that is defined in the .rc file with a LANGUAGE statement, or the application can use FindResourceEx. Additionally, the application can use SetThreadUILanguage. 

是不是可以理解成在VISTA之后版本系统采用FindResourceEx加载资源,所以使用SetThreadLocale 选择语言接口将无法有效设置UI语言,而必须使用SetThreadUILanguage,相对的在之前的系统版本中,除了FindResourceEx之外,系统仍然使用其他的加载方式,故使用SetThreadLocale 能够有效加载UI语言,
但以上仍然不能解释 Do not use SetThreadLocale to select a user interface language.这句话

楼上朋友,你说MS建议的这个DLL方式难道就是采用FindResourceEx么?如果是这样的话,你是否是根据这句话来认为是推荐的:
To select the resource that is defined in the .rc file with a LANGUAGE statement, the application must use the FindResourceEx function. 

这个貌似没有要求一定要在其他的DLL中处理。。。我都塞在EXE中也行啊

作者: wjh173069597   发布时间: 2011-12-14

这个多语言实现有多种方式。。

ini,dll,多种方式都可以。。还是看自己的选择了!!

作者: shen_wei   发布时间: 2011-12-19