views:

52

answers:

1

Basically I want to write an application which would display the current language as a tray icon. Mainly I can code C++ and C#. Guess Google would help me out but I would like to ask it here first, since the community, the knowledge here is something I trust.

(Never wrangled with such parts of the system so far. So that's why I would like to ask the community.)

Okay thanks to your help, I managed to discover two ways. Using the DllImport in C# (importing the user32.dll) and the InputLanguage.

Found a snippet:

public void SetNewCurrentLanguage() {
    // Gets the default, and current languages.
    InputLanguage myDefaultLanguage = InputLanguage.DefaultInputLanguage;
    InputLanguage myCurrentLanguage = InputLanguage.CurrentInputLanguage;
    textBox1.Text = "Current input language is: " + myCurrentLanguage.Culture.EnglishName + '\n';
    textBox1.Text += "Default input language is: " + myDefaultLanguage.Culture.EnglishName + '\n';

    // Changes the current input language to the default, and prints the new current language.
    InputLanguage.CurrentInputLanguage = myDefaultLanguage;
    textBox1.Text += "Current input language is now: " + myDefaultLanguage.Culture.EnglishName;
}  

I applied this like the following:

        InputLanguage myCurrentLanguage = InputLanguage.CurrentInputLanguage;
        notifyIcon.Text = myCurrentLanguage.LayoutName + '\n' + myCurrentLanguage.Culture.DisplayName;  

This displays it if you hover it above the icon. However, it won't update on switch, nor show the layout as text in the tray area. For that, I found a "Drawing in VB.NET" article, maybe this will help me working out this issue. About the switch detect, that's a good question.

+2  A: 

To get the user's overall UI language, GetUserDefaultUILanguage.

To get the current thread's language, GetThreadUILanguage or GetThreadLocale.

To get the current keyboard input language, GetKeyboardLayout.

To display a notification area icon in Windows prior to Windows 7, Shell_NotifyIcon. In Windows 7 Shell_NotifyIcon might still work if the user sets appropriate options, but otherwise you have to find another way.

If you have more than one possible keyboard input language, Windows already displays the current keyboard input language in the language bar unless the user has disabled it. The user might put the language bar in the task bar, though it's not quite the same as being in the notification area.

If you want to receive notices when the user changes a language, WM_SETTINGCHANGE might let you know when you should call SystemParametersInfo to check. I'm not sure if there's a better way.

Windows programmer
Thank you, great answer. Will try these out ASAP. Thanks!!!
Shiki