コミットメタ情報

リビジョン5e252e07b7b49ba83368c3a5c0ad829d88bad6c2 (tree)
日時2011-08-30 16:01:56
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

Improve the member functions of CXkeymacsDll relating the hooks.

Remove the member variables of the hook handles from the shared section.
Remove unnecessary type casts in SetHooks.
Merge the invocations of CallNextHookEx in CallWndProc.
Add the invocations of SetKeyboardHook to CallWndRetProc and GetMsgProc.
Process messages in GetMsgProc only when nCode >= 0.

変更サマリ

差分

--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -207,10 +207,6 @@ DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
207207 #pragma data_seg(".xkmcs")
208208 bool CXkeymacsDll::m_bEnableKeyboardHook = false;
209209 DWORD CXkeymacsDll::m_nHookAltRelease = 0;
210- HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;
211- HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;
212- HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;
213- HHOOK CXkeymacsDll::m_hHookShell = NULL;
214210 BOOL CXkeymacsDll::m_bRightControl = FALSE;
215211 BOOL CXkeymacsDll::m_bRightAlt = FALSE;
216212 BOOL CXkeymacsDll::m_bRightShift = FALSE;
@@ -227,6 +223,10 @@ DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
227223 TCHAR CXkeymacsDll::m_M_xTip[128] = "";
228224 CONFIG CXkeymacsDll::m_Config = {0};
229225 #pragma data_seg()
226+HHOOK CXkeymacsDll::m_hHookCallWnd = NULL;
227+HHOOK CXkeymacsDll::m_hHookCallWndRet = NULL;
228+HHOOK CXkeymacsDll::m_hHookGetMessage = NULL;
229+HHOOK CXkeymacsDll::m_hHookShell = NULL;
230230 BOOL CXkeymacsDll::m_bRecordingMacro = FALSE;
231231 BOOL CXkeymacsDll::m_bDown[MAX_KEY] = {0};
232232 std::list<KbdMacro> CXkeymacsDll::m_Macro;
@@ -270,10 +270,10 @@ void CXkeymacsDll::SetConfig(const CONFIG& config)
270270
271271 void CXkeymacsDll::SetHooks()
272272 {
273- m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, g_hDllInst, 0);
274- m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC)CallWndRetProc, g_hDllInst, 0);
275- m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)GetMsgProc, g_hDllInst, 0);
276- m_hHookShell = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, g_hDllInst, 0);
273+ m_hHookCallWnd = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, g_hDllInst, 0);
274+ m_hHookCallWndRet = SetWindowsHookEx(WH_CALLWNDPROCRET, CallWndRetProc, g_hDllInst, 0);
275+ m_hHookGetMessage = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, g_hDllInst, 0);
276+ m_hHookShell = SetWindowsHookEx(WH_SHELL, ShellProc, g_hDllInst, 0);
277277 m_bEnableKeyboardHook = true;
278278 }
279279
@@ -353,34 +353,35 @@ BOOL CXkeymacsDll::IsKeyboardHook()
353353 LRESULT CALLBACK CXkeymacsDll::CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
354354 {
355355 SetKeyboardHook();
356- if (nCode < 0)
357- return CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);
358- const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);
359- switch (cwps->message) {
360- case WM_IME_STARTCOMPOSITION:
361- InitKeyboardProc(TRUE);
362- break;
363- case WM_IME_ENDCOMPOSITION:
364- InitKeyboardProc(FALSE);
365- break;
366- case WM_SETFOCUS:
367- if (cwps->hwnd == GetForegroundWindow()) {
368- InitKeyboardProc(FALSE);
369- ShowKeyboardHookState();
370- }
371- break;
372- case WM_NCACTIVATE:
373- if (cwps->wParam && cwps->hwnd == GetForegroundWindow()) {
356+ if (nCode >= 0) {
357+ const CWPSTRUCT *cwps = reinterpret_cast<CWPSTRUCT *>(lParam);
358+ switch (cwps->message) {
359+ case WM_IME_STARTCOMPOSITION:
360+ InitKeyboardProc(TRUE);
361+ break;
362+ case WM_IME_ENDCOMPOSITION:
374363 InitKeyboardProc(FALSE);
375- ShowKeyboardHookState();
364+ break;
365+ case WM_SETFOCUS:
366+ if (cwps->hwnd == GetForegroundWindow()) {
367+ InitKeyboardProc(FALSE);
368+ ShowKeyboardHookState();
369+ }
370+ break;
371+ case WM_NCACTIVATE:
372+ if (cwps->wParam && cwps->hwnd == GetForegroundWindow()) {
373+ InitKeyboardProc(FALSE);
374+ ShowKeyboardHookState();
375+ }
376+ break;
376377 }
377- break;
378378 }
379379 return CallNextHookEx(m_hHookCallWnd, nCode, wParam, lParam);
380380 }
381381
382382 LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
383383 {
384+ SetKeyboardHook();
384385 if (nCode >= 0) {
385386 const CWPRETSTRUCT *cwprets = reinterpret_cast<CWPRETSTRUCT *>(lParam);
386387 switch (cwprets->message) {
@@ -398,14 +399,17 @@ LRESULT CALLBACK CXkeymacsDll::CallWndRetProc(int nCode, WPARAM wParam, LPARAM l
398399
399400 LRESULT CALLBACK CXkeymacsDll::GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
400401 {
401- const MSG *msg = reinterpret_cast<MSG *>(lParam);
402- switch (msg->message) {
403- case WM_IME_STARTCOMPOSITION:
404- InitKeyboardProc(TRUE);
405- break;
406- case WM_IME_ENDCOMPOSITION:
407- InitKeyboardProc(FALSE);
408- break;
402+ SetKeyboardHook();
403+ if (nCode >= 0) {
404+ const MSG *msg = reinterpret_cast<MSG *>(lParam);
405+ switch (msg->message) {
406+ case WM_IME_STARTCOMPOSITION:
407+ InitKeyboardProc(TRUE);
408+ break;
409+ case WM_IME_ENDCOMPOSITION:
410+ InitKeyboardProc(FALSE);
411+ break;
412+ }
409413 }
410414 return CallNextHookEx(m_hHookGetMessage, nCode, wParam, lParam);
411415 }
@@ -420,7 +424,7 @@ LRESULT CALLBACK CXkeymacsDll::ShellProc(int nCode, WPARAM wParam, LPARAM lParam
420424 ShowKeyboardHookState();
421425 }
422426 }
423- return CallNextHookEx( m_hHookShell, nCode, wParam, lParam );
427+ return CallNextHookEx(m_hHookShell, nCode, wParam, lParam);
424428 }
425429
426430 UINT CXkeymacsDll::GetModifierState(BOOL bPhysicalKey)
旧リポジトリブラウザで表示