1

using .NET Clipboard API you can write following code:

//dataObject - instance of IDataObject, received from Clipboard
if (dataObject != null)
{
    if (dataObject.GetDataPresent(DataFormats.Locale))
    {
        var data = dataObject.GetData(DataFormats.Locale);
        var locale = AsInt(data);
        if (locale.HasValue)
        {
            return new CultureInfo(locale.Value);
        }
     }
}

int? AsInt(object data); - my method which tries to read `Int32` value from `MemoryStream`

The question is why I always get en-US locale even when my PC's locale is ukrainian? I cannot get it, I thought Windows OS puts current locale info into clipboard when copy operation is performed? Isn't it?

UPD: I need to know locale of the object inside the clipboard, if it is possible

UPD2: My PC's locale is uk-UA, PC's UI locale is en-US, FAR Manager puts something different to clipboard (value 1024, which cannot be recognizsed as valid locale identifier). So it seems to be Excel2010 problem.

illegal-immigrant
  • 8,089
  • 9
  • 51
  • 84
  • Are you trying to get your systems current locale designation or the locale of the object inside the clipboard? – Bueller Dec 08 '11 at 14:10
  • Locale of the object inside the clipboard – illegal-immigrant Dec 08 '11 at 14:10
  • 2
    Just a thought, but perhaps the problem is on the side of the code that put it on the clipboard, and not on your side. Does this also happen if the object on the clipboard is something you put there yourself (with the desired locale)? – M-Peror Dec 08 '11 at 14:19
  • Tested applications - Windows Notepad, MS Excel 2010. Didn't tired to put data by myself – illegal-immigrant Dec 08 '11 at 14:20
  • 1
    Looking for some reason for this, I am leaning to the same though presented above by @M-Peror where the application putting the info on the clipboard may be the culprit. – Bueller Dec 08 '11 at 14:23
  • You both are right, FAR Manager puts '1024' as culture identifier to the clipboard (which, cannot be recognized by .NET as a valid identifier for some reasons). So, why the hell excel puts not my current culture? And how can i retrieve it? – illegal-immigrant Dec 08 '11 at 14:30
  • 1024 seems to be a special Office quasi-locale identifier meaning "No Proofing", see [Microsoft support](http://support.microsoft.com/kb/221435) – sq33G Dec 08 '11 at 15:52
  • Do you have the Ukranian Office language pack installed? This question belongs at superuser.com – Hans Passant Dec 08 '11 at 16:32
  • Thanks guys for your responses, see my answer if you are still interested in question – illegal-immigrant Dec 12 '11 at 18:24

1 Answers1

1

Answer from Microsoft

illegal-immigrant
  • 8,089
  • 9
  • 51
  • 84