GetCurrentThreadId() private method

private GetCurrentThreadId ( ) : uint
return uint
コード例 #1
0
ファイル: Composer.cs プロジェクト: DarkDare/wincompose
        // FIXME: this is useless for now
        private static void CheckKeyboardLayout()
        {
            // FIXME: the foreground window doesn't seem to notice keyboard
            // layout changes caused by the Win+Space combination.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            Log.Debug("Active window layout handle:0x{0:X} lang:0x{0:X}",
                      (uint)active_layout >> 16, (uint)active_layout & 0xffff);

            tid = NativeMethods.GetCurrentThreadId();
            IntPtr my_layout = NativeMethods.GetKeyboardLayout(tid);

            Log.Debug("WinCompose process layout handle:0x{0:X} lang:0x{0:X}",
                      (uint)my_layout >> 16, (uint)my_layout & 0xffff);
        }
コード例 #2
0
        public static void CheckForChanges()
        {
            // Detect keyboard layout changes by querying the foreground window,
            // and apply the same layout to WinCompose itself.
            IntPtr hwnd = NativeMethods.GetForegroundWindow();
            uint   pid, tid = NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
            IntPtr active_layout = NativeMethods.GetKeyboardLayout(tid);

            Window.IsGtk          = false;
            Window.IsNPPOrLO      = false;
            Window.IsOffice       = false;
            Window.IsOtherDesktop = false;

            const int     len = 256;
            StringBuilder buf = new StringBuilder(len);

            if (NativeMethods.GetClassName(hwnd, buf, len) > 0)
            {
                string wclass = buf.ToString();

                if (wclass == "gdkWindowToplevel" || wclass == "xchatWindowToplevel" ||
                    wclass == "hexchatWindowToplevel")
                {
                    Window.IsGtk = true;
                }

                /* Notepad++ or LibreOffice */
                if (wclass == "Notepad++" || wclass == "SALFRAME")
                {
                    Window.IsNPPOrLO = true;
                }

                if (wclass == "rctrl_renwnd32" || wclass == "OpusApp")
                {
                    Window.IsOffice = true;
                }

                if (Regex.Match(wclass, "^(SynergyDesk|cygwin/x.*)$").Success)
                {
                    Window.IsOtherDesktop = true;
                }
            }

            if (active_layout != m_current_layout)
            {
                m_current_layout = active_layout;

                Log.Debug("Active window layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                if (active_layout != (IntPtr)0)
                {
                    NativeMethods.ActivateKeyboardLayout(active_layout, 0);
                }

                tid           = NativeMethods.GetCurrentThreadId();
                active_layout = NativeMethods.GetKeyboardLayout(tid);

                Log.Debug("WinCompose process layout tid:{0} handle:0x{1:X} lang:0x{2:X}",
                          tid, (uint)active_layout >> 16, (uint)active_layout & 0xffff);

                // We need to rebuild the list of dead keys
                AnalyzeLayout();
            }
        }