OSDN Git Service

Add the invocation of SetKeyboardHook to ShellProc in CXkeymacsDll,
authorKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Sun, 23 Oct 2011 13:44:43 +0000 (22:44 +0900)
committerKazuhiro Fujieda <fujieda@users.sourceforge.jp>
Sun, 23 Oct 2011 13:44:43 +0000 (22:44 +0900)
and modify SetKeyboardHook to accept a thread ID.

xkeymacsdll/xkeymacsdll.cpp
xkeymacsdll/xkeymacsdll.h

index 006a49f..92326c2 100644 (file)
@@ -274,7 +274,7 @@ void CXkeymacsDll::SetHooks()
        m_bEnableKeyboardHook = true;\r
 }\r
 \r
-void CXkeymacsDll::SetKeyboardHook()\r
+void CXkeymacsDll::SetKeyboardHook(DWORD threadId)\r
 {\r
        LPVOID lpData = TlsGetValue(g_TlsIndex);\r
        if (!lpData) {\r
@@ -286,7 +286,7 @@ void CXkeymacsDll::SetKeyboardHook()
        }\r
        HHOOK *phHook = reinterpret_cast<HHOOK *>(lpData);\r
        if (!*phHook)\r
-               *phHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, g_hDllInst, GetCurrentThreadId());\r
+               *phHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hDllInst, threadId ? threadId : GetCurrentThreadId());\r
 }\r
 \r
 inline void unhook(HHOOK &hh)\r
@@ -420,8 +420,9 @@ LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lPara
 LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam)\r
 {\r
        if (nCode == HSHELL_WINDOWACTIVATED) {\r
-               TCHAR className[256];\r
-               GetClassName((HWND)wParam, className, 255);\r
+               SetKeyboardHook(GetWindowThreadProcessId(reinterpret_cast<HWND>(wParam), NULL));\r
+               TCHAR className[CLASS_NAME_LENGTH];\r
+               GetClassName(reinterpret_cast<HWND>(wParam), className, CLASS_NAME_LENGTH);\r
                if (!_tcsicmp(className, _T("ConsoleWindowClass"))) {\r
                        InitKeyboardProc(FALSE);\r
                        ShowKeyboardHookState();\r
index 2ac695b..e619a4e 100644 (file)
@@ -25,7 +25,7 @@ public:
        static BOOL LoadConfig();\r
        static void SetConfig(const Config& config);\r
        static void SetHooks();\r
-       static void SetKeyboardHook();\r
+       static void SetKeyboardHook(DWORD threadId = 0);\r
        static void ResetHooks();\r
        static void ReleaseHooks();\r
        static void ReleaseKeyboardHook();\r