Exemple #1
0
        private void timLanguage_Tick(object sender, EventArgs e)
        {
            // Makes this window is topmost.
            base.TopLevel = true;
            base.TopMost  = true;

            // Finds active window.
            IntPtr foregroundWindow  = MainForm.GetForegroundWindow();
            IntPtr hWnd              = MainForm.ImmGetDefaultIMEWnd(foregroundWindow);
            string activeWindowTitle = this.GetActiveWindowTitle();

            MainForm.COPYDATASTRUCT copydatastruct = default(MainForm.COPYDATASTRUCT);

            // Gets Caps lock state.
            bool capsLock = (((ushort)GetKeyState(0x14)) & 0xffff) != 0;

            // Gets the IME state.
            IntPtr value    = MainForm.SendMessage(hWnd, WM_IME_CONTROL, IMC_GETOPENSTATUS, ref copydatastruct);
            bool   flag     = value == IntPtr.Zero;
            String onColor  = appSettings["OnColor"];
            String offColor = appSettings["OffColor"];

            if (flag)
            {
                // IME is off. It's English mode.
                if (onColor != null)
                {
                    this.BackColor = System.Drawing.ColorTranslator.FromHtml(offColor);
                }
                else
                {
                    this.BackColor = Color.Red;
                }
            }
            else
            {
                // IME is on. So, it's not English mode.
                if (offColor != null)
                {
                    this.BackColor = System.Drawing.ColorTranslator.FromHtml(onColor);
                }
                else
                {
                    this.BackColor = Color.Blue;
                }
            }

            if (capsLock)
            {
                this.Visible = !this.Visible;
            }
            else
            {
                this.Visible = true;
            }
        }
Exemple #2
0
 private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, ref MainForm.COPYDATASTRUCT lParam);