views:

33

answers:

2

Windows 7 and Windows Vista have a Region and Language control panel which contains a Formats tab which contains a popup menu titled Format. This menu allows the user to select from among many language-oriented sets of number, currency, time, and date formatting preferences regardless of the language of the base system. For example, I could decide I prefer the default currency symbol to be Japanese yen on a US English system. I don't care about the currency symbol in particular; that was just an example. I'm referring here to the sets of preferences which may be applied by selecting items from the Format menu.

The Windows Contacts application appears to change its behavior based on the selection in this menu. For example, if I select Japanese, Windows Contacts displays and lets me edit phonetic names (AKA "ruby", "yomi", and "furigana") but not middle names. If I select US English, then Windows Contacts displays and lets me edit middle names but not phonetic names.

I need to write code (native C calling Win32 on XP SP2 and later) which mirrors the behavior of the Windows Contacts application in this respect. Which API should I call?

A: 

The question seems to combine two kinds of features.

Using the Control Panel applet, a general language setting can be selected and then individual formatting items are given default values associated with that language setting.

If you want to retrieve the user's overall language setting then just get the user's default LCID or something of that sort.

If you want to retrieve individual formatting items, I think you need the CRT function locale(). The Win32 API SetLocaleInfo can set the user overrideable portion of the locale. However, at least as documented, GetLocaleInfo and GetLocaleInfoEx (Vista and later only) get information associated with some existing locale rather than from user overrides. The standard C locale() function should work though.

Your question asks about how to retrieve individual formatting items, but then you say you have to key on the user's selected general locale instead of the individual formatting items. From your description of the Windows Contacts application, it sounds like you need GetUserDefaultLCID.

Windows programmer
That might be the case. I'll have to see whether its value changes after I jigger the menu in question.
Integer Poet
The return value of GetUserDefaultLCID indeed changes when I select a different item from the menu.
Integer Poet
A: 

For most of these items, you can use functions like GetTimeFormat, GetNumberFormat, and GetCurrencyFormat. Contrary to what the names imply, these will actually format data as requested rather than just telling you what the format should be. Although you can specify a locale for them to use, you normally want to pass LOCALE_USER_DEFAULT, to use the settings the user has specified in the control panel.

Jerry Coffin