0

I want my application to be work in minimized state.this application is for detecting change in computer language..For example, I change my language from English to Russia application will detect it. But my application not working in minimized state or in taskbar.I have code for show in taskbar.Is there any solution for this problem? I want application to be detect change language(working) while minimized in toolbar Here I have code for language change detection and to minimized application in toolbar..

private void HandleCurrentLanguage()
{
    //CultureInfo.CurrentCulture.ClearCachedData();
    //Thread.CurrentThread.CurrentCulture.ClearCachedData();

    var newLayout = GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero));
    if (_currentKeyboardLayout != newLayout)
    {
        Thread.Sleep(100);
        _currentKeyboardLayout = newLayout;
        string show = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
        //  MessageBox.Show(show);

        string current_language = InputLanguage.CurrentInputLanguage.Culture.Parent.DisplayName;

        string current_layout = InputLanguage.CurrentInputLanguage.LayoutName;
        var name = new StringBuilder(_currentKeyboardLayout.ToString());
        var keyboardLayoutId = (UInt32)GetKeyboardLayout((UInt32)Thread.CurrentThread.ManagedThreadId);
        var languageId = (UInt16)(keyboardLayoutId & 0xFFFF);
        var keyboardId = (UInt16)(keyboardLayoutId >> 16);

        if (button1.InvokeRequired)
        {
            button1.Invoke(new MethodInvoker(delegate
            {
                button1.PerformClick();
            }));
        }
        //CultureInfo.CurrentCulture.ClearCachedData();
        //Thread.CurrentThread.CurrentCulture.ClearCachedData();
    }
}
// code for minimized application in toolbar

MenuItem exitMenuItem = new MenuItem("Exit", new EventHandler(Exit));

notifyIcon.Icon =SystemTray.Properties.Resources.system_tray;
notifyIcon.Click += new EventHandler(Open);
notifyIcon.ContextMenu = new ContextMenu(new MenuItem[] { 
exitMenuItem });
notifyIcon.Visible = true;
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • You should put a break point on Thread.Sleep(100); and see if this break point even gets hit when the program is minimised and you change the language – Jack May 27 '20 at 21:36
  • 2
    Just the obvious explanation, the input language for *your* program did not change. Windows changes it only for the process who currently has a window in the foreground, you know it isn't yours since you minimized it. Changing it for every process has the obvious and clear outcome, Windows reminds you that you have to reboot. – Hans Passant May 27 '20 at 21:36
  • How do you expect your `HandleCurrentLanguage` to be called? Who is it subscribed to? – Formula12 May 28 '20 at 02:10
  • If you wanted to try and pick up the language in this situation, you could try something like the solution here: https://stackoverflow.com/questions/26617159/hook-detect-windows-language-change-even-when-app-not-focused – Jack May 28 '20 at 05:44
  • Also, hi @HansPassant - just wanted to say thanks for so many answers of yours on StackOverflow - they've helped me a lot of times over the years – Jack May 28 '20 at 05:45
  • @HansPassant If I create foreground thread then this will work or not? –  May 28 '20 at 11:42

0 Answers0