以编程方式更改 Windows XP 中的默认代码页? (来自德尔福)
谁能建议如何以编程方式更改默认的 Windows XP 代码页(我是在 Delphi 中执行此操作)? (这相当于进入控制面板 -> 区域设置 -> 非 Unicode 应用程序的语言)。
在这种情况下,我想切换到中文(中国),因此正在写入以下注册表字符串: HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage\ ACP=936 MACCP=10008 OEMCP=936
(这正是更改控制面板中的非 Unicode 代码页下拉列表所做的操作)。必须有另一个我需要更改的设置 - 而且我更喜欢使用 Win API 调用(如果可用)而不是自己写入注册表。
我也尝试过设置 HKLM\SYSTEM\CurrentControlSet\Control\Nls\语言\ 默认=0804(中国)无济于事。
我不想更改“区域设置”本身,因为这也会更改时间/日期设置、分隔符等。
这是因为我正在使用需要呈现中文字符的 ANSI 应用程序,并且我编写一个工具来自动切换系统显示的字符(同时保持 UI 的其他方面完好无损)。
谢谢!
邓肯
Could anyone advise how to programmatically change the default Windows XP code page (I'm doing this from Delphi)? (This would be the equivalent of going into Control Panel -> Regional Settings -> Language for non-Unicode applications).
In this case, I want to switch to Chinese (PRC) and so am writing to the following registry strings:
HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage\
ACP=936
MACCP=10008
OEMCP=936
(Which is exactly what changing the non-Unicode codepage drop down in Control Panel does). There must be another setting which I need to change - and I'd prefer to use a Win API call (if available) rather than writing to the registry myself.
I've also tried setting
HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language\
Default=0804 (Chinese PRC) to no avail.
I don't want to change the 'locale' per se as this will also change time / date settings, separators, etc. etc.
This is because I'm using an ANSI application that needs to render Chinese characters, and I'm writing a tool to automatically switch the system show the characters (while leaving other aspects of the UI intact).
Thanks!
Duncan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
唯一合适的情况是,如果您正在编写一个信息亭类型的应用程序,系统上不会运行其他任何东西。该更改将影响系统上的所有其他应用程序。
如果您只需要渲染字符并可以将它们放入 WideString 中,则可以通过直接调用 Windows API 的 W 版本,而不是通过 TCanvas 方法,在旧版本的 Delphi 中渲染它们。也就是说,调用
DrawTextW
或ExtTextOutW
而不是TCanvas.TextOut
,它将绘制 Unicode 字符,而不将它们转换为系统的 ANSI 代码页。更完整的选项是 TMS Unicode 组件包。它支持在 Delphi 6-2007 中创建支持 Unicode 的应用程序,并为您处理调用所有 W 函数。它运行良好,您可以像平常一样使用 TCanvas 或标题/文本属性。唯一的区别是属性都是 WideStrings。这最初是 TNT Unicode 控件包,并且有一个较旧的、不受支持的版本可用
最后,您可以使用 Microsoft 的 AppLocale 实用程序仅更改您的应用程序的 ANSI 代码页。有关于从批处理脚本调用它的详细信息这里,一个运行它的补丁没有导航屏幕此处,以及名为的命令行克隆SBAppLocale。它有效,但它是一个黑客,其他选择从长远来看更好。
The only time this would be appropriate is if you're writing a kiosk type application where nothing else will run on the system. That change will affect every other application on the system.
If you just need to render the characters and can get them into a WideString you can render them in older versions of Delphi by calling the W versions of the Windows APIs directly, rather than going through the TCanvas methods. That is, call
DrawTextW
orExtTextOutW
instead ofTCanvas.TextOut
and it will draw the Unicode characters without converting them to the system's ANSI codepage.A more complete option is the TMS Unicode Component Pack. It supports making Unicode-enabled applications in Delphi 6-2007, and handles calling all of the W functions for you. It works well, and you can just use TCanvas or the Caption/Text properties like normal.; the only difference is the properties are all WideStrings instead. That was originally the TNT Unicode Controls pack, and there's an older, unsupported version of that available here.
Finally, you can use Microsoft's AppLocale utility to change the ANSI codepage for just your application. There are details on calling it from a batch script here, a patch to run it without the nag screen here, and a command line clone named SBAppLocale. It works, but it's a hack, and the other options are better long-term.