XTPKeyboardManager.h
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPKeyboardManager.h : interface for the CXTPKeyboardManager class.
  2. //
  3. // This file is a part of the XTREME COMMANDBARS MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. //{{AFX_CODEJOCK_PRIVATE
  21. #if !defined(__XTPKEYBOARDMANAGER_H__)
  22. #define __XTPKEYBOARDMANAGER_H__
  23. //}}AFX_CODEJOCK_PRIVATE
  24. #if _MSC_VER >= 1000
  25. #pragma once
  26. #endif // _MSC_VER >= 1000
  27. //===========================================================================
  28. // Summary:
  29. //     CXTPKeyboardManager class used to handle keyboard hooks
  30. //===========================================================================
  31. class _XTP_EXT_CLASS CXTPKeyboardManager : public CNoTrackObject
  32. {
  33. public:
  34. //-----------------------------------------------------------------------
  35. // Summary:
  36. //     Constructs a CXTPKeyboardManager object.
  37. //-----------------------------------------------------------------------
  38. CXTPKeyboardManager();
  39. //-------------------------------------------------------------------------
  40. // Summary:
  41. //     Destroys a CXTPKeyboardManager object, handles clean up and deallocation
  42. //-------------------------------------------------------------------------
  43. ~CXTPKeyboardManager();
  44. public:
  45. //-----------------------------------------------------------------------
  46. // Summary:
  47. //     This method is called to start/end keyboard hooks
  48. // Parameters:
  49. //     bSetup - TRUE to start keyboard hooks
  50. // See Also: SetupCallWndProcHook
  51. //-----------------------------------------------------------------------
  52. void SetupKeyboardHook(BOOL bSetup = TRUE);
  53. //-----------------------------------------------------------------------
  54. // Summary:
  55. //     This method is called to start/end message hooks
  56. // Parameters:
  57. //     bSetup - TRUE to start message hooks
  58. // See Also: SetupKeyboardHook
  59. //-----------------------------------------------------------------------
  60. void SetupCallWndProcHook(BOOL bSetup = TRUE);
  61. //-----------------------------------------------------------------------
  62. // Summary:
  63. //     Call this method to hook keyboard notifications
  64. // Parameters:
  65. //     pHook - CXTPHookManagerHookAble object that will receive keyboard notifications
  66. // See Also: UnhookKeyboard
  67. //-----------------------------------------------------------------------
  68. void HookKeyboard(CXTPHookManagerHookAble* pHook);
  69. //-----------------------------------------------------------------------
  70. // Summary:
  71. //      Call this method to unhook keyboard notifications
  72. // Parameters:
  73. //      pHook - CXTPHookManagerHookAble object to remove
  74. // See Also: HookKeyboard
  75. //-----------------------------------------------------------------------
  76. void UnhookKeyboard(CXTPHookManagerHookAble* pHook);
  77. //-----------------------------------------------------------------------
  78. // Summary:
  79. //     Determines if keyboard is hooked
  80. // Returns:
  81. //     TRUE if keyboard is hooked
  82. //-----------------------------------------------------------------------
  83. BOOL IsKeyboardHooked() { return m_lstKeyboardHooks.GetCount() > 0; }
  84. //-----------------------------------------------------------------------
  85. // Summary:
  86. //     This method is called to process keyboard hook
  87. // Parameters:
  88. //     nMessage - Message to process
  89. //     wParam - Message specified parameter
  90. //     lParam - Message specified parameter
  91. // Returns:
  92. //     TRUE if message was processed
  93. //-----------------------------------------------------------------------
  94. BOOL ProcessKeyboardHooks(UINT nMessage, WPARAM wParam, LPARAM lParam = 0);
  95. protected:
  96. //{{AFX_CODEJOCK_PRIVATE
  97. static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam);
  98. static LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam);
  99. static LRESULT CALLBACK GetMessageProc(int code, WPARAM wParam, LPARAM lParam);
  100. //}}AFX_CODEJOCK_PRIVATE
  101. protected:
  102. HHOOK m_hHookKeyboard;          // Keyboard hook
  103. HHOOK m_hHookCallWndProc;       // Message hook
  104. HHOOK m_hHookGetMessage;       // Message hook
  105. #ifdef _AFXDLL
  106. AFX_MODULE_STATE* m_pModuleState; // Module state
  107. #endif
  108. static CThreadLocal<CXTPKeyboardManager> _xtpKeyboardThreadState;           // Instance of Keyboard hook
  109. CList<CXTPHookManagerHookAble*, CXTPHookManagerHookAble*> m_lstKeyboardHooks;   // List of keyboard hooks
  110. private:
  111. friend CXTPKeyboardManager* XTPKeyboardManager();
  112. friend class CXTPCommandBars;
  113. };
  114. AFX_INLINE CXTPKeyboardManager* XTPKeyboardManager() {
  115. return CXTPKeyboardManager::_xtpKeyboardThreadState.GetData();
  116. }
  117. #endif //#if !defined(__XTPKEYBOARDMANAGER_H__)