Programmatically change the default codepage in Windows XP? (from Delphi)

Can someone tell me how to programmatically change the standard code page of Windows XP (I am doing this from Delphi)? (This will be the equivalent of switching to Control Panel → Regional Settings → Language for applications other than Unicode).

In this case, I want to switch to Chinese (PRC), so I write the following registry lines: HKLM \ SYSTEM \ CurrentControlSet \ Control \ Nls \ CodePage \ ACP = 936 MACCP = 10008 OEMCP = 936

(This is exactly what changes the non-Unicode code page in the control panel). There should be another parameter that I need to change - and I would prefer to use the Win API call (if available), rather than writing to the registry myself.

I also tried setting HKLM \ SYSTEM \ CurrentControlSet \ Control \ NLS \ Language \ Default = 0804 (Chinese People's Republic of China) to no avail.

I don’t want to change the “locale” as such, as it will also change the time and date settings, delimiters, etc. etc.

This is because I use the ANSI application, which should display Chinese characters, and I am writing a tool to automatically switch the system by showing characters (leaving other aspects of the user interface intact).

Thanks!

Duncan

+6
delphi localization codepages
source share
1 answer

The only time this would be appropriate is if you are writing an application such as a kiosk in which nothing will be launched on the system. This change will affect all other applications in the system.

If you just need to display the characters and get them in WideString, you can display them in older versions of Delphi by calling the W versions of the Windows API directly, instead of going through TCanvas Methods. That is, call DrawTextW or ExtTextOutW instead of TCanvas.TextOut , and it will draw Unicode characters without converting them to the ANSI system code page.

A more complete option is the TMS Unicode Component Pack . It supports the creation of Unicode-enabled applications in Delphi 6-2007 and allows you to call all the W functions for you. It works well, and you can simply use the TCanvas or Caption / Text properties as usual; the only difference in properties is all WideStrings. It was originally a TNT Unicode Controls package, and there was an older unsupported version of it here .

Finally, you can use the Microsoft AppLocale utility to change the ANSI code page for your application only. There is detailed information about calling it from a script package here , a patch for running it without a nag screen here , and a command line clone named SBAppLocale . It works, but it’s a hack, and other options are better long-term.

+8
source share

All Articles