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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSkinManagerApiHook.h: interface for the CXTPSkinManagerApiHook class.
  2. //
  3. // This file is a part of the XTREME SKINFRAMEWORK 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(__XTPSKINMANAGERAPIHOOK_H__)
  22. #define __XTPSKINMANAGERAPIHOOK_H__
  23. //}}AFX_CODEJOCK_PRIVATE
  24. #if _MSC_VER > 1000
  25. #pragma once
  26. #endif // _MSC_VER > 1000
  27. #include "XTPSkinObject.h"
  28. class CXTPWinThemeWrapper;
  29. //{{AFX_CODEJOCK_PRIVATE
  30. enum XTPSkinFrameworkApiFunctionIndex
  31. {
  32. xtpSkinApiLoadLibraryA,
  33. xtpSkinApiLoadLibraryW,
  34. xtpSkinApiLoadLibraryExA,
  35. xtpSkinApiLoadLibraryExW,
  36. xtpSkinApiGetProcAddress,
  37. xtpSkinApiGetModuleHandleA,
  38. xtpSkinApiRegisterClassA,
  39. xtpSkinApiRegisterClassW,
  40. xtpSkinApiGetSysColor,
  41. xtpSkinApiGetSysColorBrush,
  42. xtpSkinApiDrawEdge,
  43. xtpSkinApiDrawFrameControl,
  44. xtpSkinApiSetScrollInfo,
  45. xtpSkinApiSetScrollPos,
  46. xtpSkinApiGetScrollInfo,
  47. xtpSkinApiEnableScrollBar,
  48. xtpSkinApiOpenThemeData,
  49. xtpSkinApiDrawThemeBackground,
  50. xtpSkinApiCloseThemeData,
  51. xtpSkinApiGetThemeColor,
  52. xtpSkinApiIsAppThemed,
  53. xtpSkinApiIsThemeActive,
  54. xtpSkinApiGetCurrentThemeName,
  55. xtpSkinApiGetThemeSysBool,
  56. xtpSkinApiGetThemeSysColor,
  57. xtpSkinApiGetThemePartSize,
  58. xtpSkinApiSystemParametersInfo,
  59. xtpSkinApiDefWindowProcA,
  60. xtpSkinApiDefWindowProcW,
  61. xtpSkinApiDefMDIChildProcA,
  62. xtpSkinApiDefMDIChildProcW,
  63. xtpSkinApiDefFrameProcA,
  64. xtpSkinApiDefFrameProcW,
  65. xtpSkinApiDefDlgProcA,
  66. xtpSkinApiDefDlgProcW,
  67. xtpSkinApiCallWindowProcA,
  68. xtpSkinApiCallWindowProcW,
  69. xtpSkinApiCreateThread,
  70. xtpSkinApiFillRect,
  71. xtpSkinApiDeleteObject,
  72. xtpSkinApiAdjustWindowRectEx,
  73. XTP_SKIN_APIHOOKCOUNT
  74. };
  75. class CXTPSkinManagerApiHook;
  76. class CXTPSkinManagerApiFunction
  77. {
  78. public:
  79. CXTPSkinManagerApiFunction(CXTPSkinManagerApiHook* pApiHook,
  80. LPCSTR  pszCalleeModName, LPCSTR pszFuncName, PROC pfnOrig, PROC pfnHook);
  81. virtual ~CXTPSkinManagerApiFunction();
  82. public:
  83. BOOL HookImport();
  84. BOOL UnhookImport();
  85. private:
  86. BOOL ReplaceInOneModule(LPCSTR pszCalleeModName, PROC pfnCurrent, PROC pfnNew, HMODULE hmodCaller);
  87. BOOL ReplaceInAllModules(LPCSTR pszCalleeModName, PROC pfnCurrent, PROC pfnNew);
  88. private:
  89. CXTPSkinManagerApiHook* m_pApiHook;
  90. BOOL              m_bHooked;
  91. char              m_szCalleeModName[20];
  92. char              m_szFuncName[30];
  93. PROC              m_pfnOrig;
  94. PROC              m_pfnHook;
  95. static PVOID          sm_pvMaxAppAddr;
  96. static PVOID          sm_pfnAfxWndProc;
  97. friend class CXTPSkinManagerApiHook;
  98. friend class CXTPSkinObject;
  99. };
  100. class CXTPSkinManagerApiHook
  101. {
  102. struct EXCLUDEDMODULE
  103. {
  104. HMODULE hModule;
  105. CString strModule;
  106. BOOL bWin9x;
  107. };
  108. private:
  109. CXTPSkinManagerApiHook();
  110. public:
  111. static CXTPSkinManagerApiHook* AFX_CDECL GetInstance();
  112. virtual ~CXTPSkinManagerApiHook();
  113. public:
  114. void ExcludeModule(LPCTSTR lpszModule, BOOL bWin9x);
  115. BOOL IsModuleExcluded(HMODULE hModule) const;
  116. public:
  117. void InitializeHookManagement();
  118. void FinalizeHookManagement();
  119. public:
  120. CXTPSkinManagerApiFunction* GetHookedFunction(LPCSTR pszCalleeModName, LPCSTR pszFuncName);
  121. CXTPSkinManagerApiFunction* GetHookedFunction(XTPSkinFrameworkApiFunctionIndex nIndex);
  122. static PROC AFX_CDECL GetOriginalProc(XTPSkinFrameworkApiFunctionIndex nIndex);
  123. public:
  124. static FARPROC WINAPI GetProcAddressWindows(HMODULE hmod, LPCSTR   pszProcName);
  125. static LRESULT WINAPI CallWindowProcOrig(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  126. static BOOL AFX_CDECL IsSystemWindowModule(WNDPROC lpWndProc);
  127. void ConnectWrapper(CXTPWinThemeWrapper* pThemeWrapper);
  128. protected:
  129. void UnhookAllFunctions();
  130. CXTPSkinManagerApiFunction* HookImport(XTPSkinFrameworkApiFunctionIndex nIndex, LPCSTR pszCalleeModName, LPCSTR pszFuncName, PROC  pfnHook);
  131. private:
  132. static HMODULE WINAPI OnHookGetModuleHandleA(LPCSTR lpModuleName);
  133. CXTPSkinManagerApiFunction* AddHook(XTPSkinFrameworkApiFunctionIndex nIndex, LPCSTR  pszCalleeModName, LPCSTR  pszFuncName, PROC pfnOrig, PROC pfnHook);
  134. BOOL RemoveHook(LPCSTR pszCalleeModName, LPCSTR pszFuncName);
  135. void HackModuleOnLoad(HMODULE hmod, DWORD dwFlags);
  136. static HMODULE WINAPI OnHookLoadLibraryW(PCWSTR pszModuleName);
  137. static HMODULE WINAPI OnHookLoadLibraryExA(LPCSTR  pszModuleName, HANDLE hFile, DWORD dwFlags);
  138. static HMODULE WINAPI OnHookLoadLibraryExW(PCWSTR pszModuleName, HANDLE hFile, DWORD dwFlags);
  139. static FARPROC WINAPI OnHookGetProcAddress(HMODULE hmod, PCSTR pszProcName);
  140. static HMODULE WINAPI OnHookLoadLibraryA(LPCSTR pszModuleName);
  141. static ATOM WINAPI OnHookRegisterClassA( const WNDCLASSA *lpWndClass);
  142. static ATOM WINAPI OnHookRegisterClassW( const WNDCLASSW *lpWndClass);
  143. static int WINAPI OnHookSetScrollInfo(HWND hwnd, int fnBar, LPCSCROLLINFO lpsi, BOOL fRedraw);
  144. static int WINAPI OnHookSetScrollPos(HWND hwnd,  int nBar,   int nPos,  BOOL redraw);
  145. static BOOL WINAPI OnHookAdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle);
  146. static BOOL WINAPI OnHookEnableScrollBar(HWND hWnd, UINT wSBflags, UINT wArrows);
  147. static BOOL WINAPI OnHookGetScrollInfo(HWND hwnd, int nBar, LPSCROLLINFO lpsi);
  148. static DWORD WINAPI OnHookGetSysColor(int nIndex);
  149. static BOOL WINAPI OnHookDeleteObject(HGDIOBJ hObject);
  150. static BOOL WINAPI OnHookDrawEdge (HDC hdc, LPRECT qrc, UINT edge, UINT grfFlags);
  151. static BOOL WINAPI OnHookDrawFrameControl(HDC hDC, LPRECT rect, UINT, UINT);
  152. static HBRUSH WINAPI OnHookGetSysColorBrush(int nIndex);
  153. static BOOL WINAPI OnHookSystemParametersInfo (UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni);
  154. static LRESULT WINAPI OnHookDefWindowProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  155. static LRESULT WINAPI OnHookDefWindowProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  156. static LRESULT WINAPI OnHookDefFrameProcA(HWND hWnd, HWND hWndMDIClient, UINT Msg, WPARAM wParam, LPARAM lParam);
  157. static LRESULT WINAPI OnHookDefFrameProcW(HWND hWnd, HWND hWndMDIClient, UINT Msg, WPARAM wParam, LPARAM lParam);
  158. static LRESULT WINAPI OnHookDefDlgProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  159. static LRESULT WINAPI OnHookDefDlgProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  160. static LRESULT WINAPI OnHookDefMDIChildProcA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  161. static LRESULT WINAPI OnHookDefMDIChildProcW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  162. static LRESULT WINAPI OnHookCallWindowProcA(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  163. static LRESULT WINAPI OnHookCallWindowProcW(WNDPROC lpPrevWndFunc, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  164. static int WINAPI OnHookFillRect( HDC hDC, CONST RECT *lprc, HBRUSH hbr);
  165. static HRESULT STDAPICALLTYPE OnHookGetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars, LPWSTR pszColorBuff, int cchMaxColorChars, LPWSTR /*pszSizeBuff*/, int /*cchMaxSizeChars*/);
  166. static BOOL STDAPICALLTYPE OnHookGetThemeSysBool(HTHEME /*hTheme*/, int iBoolId);
  167. static COLORREF STDAPICALLTYPE OnHookGetThemeSysColor(HTHEME /*hTheme*/, int iColorId);
  168. static HRESULT STDAPICALLTYPE OnHookGetThemePartSize(HTHEME hTheme, HDC, int iPartId, int iStateId, RECT *pRect, THEMESIZE eSize, SIZE* pSize);
  169. static BOOL STDAPICALLTYPE OnHookIsAppThemed();
  170. static BOOL STDAPICALLTYPE OnHookIsThemeActive();
  171. static HRESULT STDAPICALLTYPE OnHookGetThemeColor(HTHEME hTheme, int iPartId, int iStateId, int iPropID, COLORREF *pColor);
  172. static HRESULT STDAPICALLTYPE OnHookCloseThemeData(HTHEME);
  173. static HRESULT STDAPICALLTYPE OnHookDrawThemeBackground(HTHEME hTheme, HDC hDC, int iPartId, int iStateId, const RECT* pRect, const RECT*);
  174. static HTHEME STDAPICALLTYPE OnHookOpenThemeData(HWND /*hWnd*/, LPCWSTR pszClassList);
  175. static HANDLE STDAPICALLTYPE OnHookCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes,
  176. UINT_PTR dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
  177. DWORD dwCreationFlags, LPDWORD lpThreadId);
  178. static DWORD WINAPI ThreadProcHook(LPVOID lpParameter);
  179. BOOL CallHookDefWindowProc(HWND hWnd, PROC pfnOrig, XTPSkinDefaultProc defProc, LPVOID lpPrev, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult);
  180. protected:
  181. CXTPSkinManagerApiFunction* m_arrFunctions[XTP_SKIN_APIHOOKCOUNT];
  182. BOOL m_bInitialized;
  183. CArray<EXCLUDEDMODULE, EXCLUDEDMODULE&> m_arrExcludedModules;
  184. CRITICAL_SECTION m_cs;
  185. friend class CXTPSkinManagerApiFunction;
  186. };
  187. //}}AFX_CODEJOCK_PRIVATE
  188. #endif // !defined(__XTPSKINMANAGERAPIHOOK_H__)