Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 570
Duncan Avatar asked Jun 09 '10 16:06

Duncan


1 Answers

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 or ExtTextOutW instead of TCanvas.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.

like image 180
Zoë Peterson Avatar answered Sep 28 '22 01:09

Zoë Peterson