SkinSBDemo.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // SkinSBDemo.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "SkinSBDemo.h"
  5. #include "SkinSBDemoDlg.h"
  6. //包含头文件
  7. #include "..\lib\detours.h"
  8. #include "..\lib\skinsb.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // 申明钩子
  13. DETOUR_TRAMPOLINE(int WINAPI SetScrollInfoT(HWND, int, LPCSCROLLINFO, BOOL), SetScrollInfo)
  14. DETOUR_TRAMPOLINE(BOOL WINAPI GetScrollInfoT(HWND, int, LPSCROLLINFO), GetScrollInfo)
  15. DETOUR_TRAMPOLINE(int WINAPI SetScrollPosT(HWND, int, int, BOOL), SetScrollPos)
  16. DETOUR_TRAMPOLINE(int WINAPI GetScrollPosT(HWND, int), GetScrollPos)
  17. DETOUR_TRAMPOLINE(BOOL WINAPI GetScrollRangeT(HWND, int, LPINT, LPINT), GetScrollRange)
  18. DETOUR_TRAMPOLINE(BOOL WINAPI SetScrollRangeT(HWND, int, int, int, BOOL), SetScrollRange)
  19. DETOUR_TRAMPOLINE(BOOL WINAPI ShowScrollBarT(HWND, int, BOOL), ShowScrollBar)
  20. DETOUR_TRAMPOLINE(BOOL WINAPI EnableScrollBarT(HWND, UINT, UINT), EnableScrollBar)
  21. int WINAPI SetScrollInfoD(HWND hwnd, int fnBar, LPCSCROLLINFO lpsi, BOOL bRedraw)
  22. {
  23. if( SkinSB_IsValid(hwnd) )
  24. return SkinSB_SetScrollInfo(hwnd, fnBar, lpsi, bRedraw);
  25. else
  26. return SetScrollInfoT(hwnd, fnBar, lpsi, bRedraw);
  27. }
  28. BOOL WINAPI GetScrollInfoD(HWND hwnd, int fnBar, LPSCROLLINFO lpsi)
  29. {
  30. if( SkinSB_IsValid(hwnd) )
  31. return SkinSB_GetScrollInfo(hwnd, fnBar, lpsi);
  32. else
  33. return GetScrollInfoT(hwnd, fnBar, lpsi);
  34. }
  35. int WINAPI SetScrollPosD(HWND hwnd, int nBar, int nPos, BOOL bRedraw)
  36. {
  37. if( SkinSB_IsValid(hwnd) )
  38. return SkinSB_SetScrollPos(hwnd, nBar, nPos, bRedraw);
  39. else
  40. return SetScrollPosT(hwnd, nBar, nPos, bRedraw);
  41. }
  42. int WINAPI GetScrollPosD(HWND hwnd, int nBar)
  43. {
  44. if( SkinSB_IsValid(hwnd) )
  45. return SkinSB_GetScrollPos(hwnd, nBar);
  46. else
  47. return GetScrollPosT(hwnd, nBar);
  48. }
  49. BOOL WINAPI SetScrollRangeD(HWND hwnd, int nBar, int nMinPos, int nMaxPos, BOOL bRedraw)
  50. {
  51. if( SkinSB_IsValid(hwnd) )
  52. return SkinSB_SetScrollRange(hwnd, nBar, nMinPos, nMaxPos, bRedraw);
  53. else
  54. return SetScrollRangeT(hwnd, nBar, nMinPos, nMaxPos, bRedraw);
  55. }
  56. BOOL WINAPI GetScrollRangeD(HWND hwnd, int nBar, LPINT lpMinPos, LPINT lpMaxPos)
  57. {
  58. if( SkinSB_IsValid(hwnd) )
  59. return SkinSB_GetScrollRange(hwnd, nBar, lpMinPos, lpMaxPos);
  60. else
  61. return GetScrollRangeT(hwnd, nBar, lpMinPos, lpMaxPos);
  62. }
  63. BOOL WINAPI ShowScrollBarD(HWND hwnd, int nBar, BOOL bShow)
  64. {
  65. if( SkinSB_IsValid(hwnd) )
  66. return SkinSB_ShowScrollBar(hwnd, nBar, bShow);
  67. else
  68. return ShowScrollBarT(hwnd, nBar, bShow);
  69. }
  70. BOOL WINAPI EnableScrollBarD(HWND hwnd, UINT wSBflags, UINT wArrows)
  71. {
  72. if( SkinSB_IsValid(hwnd) )
  73. return SkinSB_EnableScrollBar(hwnd, wSBflags, wArrows);
  74. else
  75. return EnableScrollBarT(hwnd, wSBflags, wArrows);
  76. }
  77. // CSkinSBDemoApp
  78. BEGIN_MESSAGE_MAP(CSkinSBDemoApp, CWinApp)
  79. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  80. END_MESSAGE_MAP()
  81. // CSkinSBDemoApp construction
  82. CSkinSBDemoApp::CSkinSBDemoApp()
  83. {
  84. // TODO: add construction code here,
  85. // Place all significant initialization in InitInstance
  86. }
  87. // The one and only CSkinSBDemoApp object
  88. CSkinSBDemoApp theApp;
  89. // CSkinSBDemoApp initialization
  90. BOOL CSkinSBDemoApp::InitInstance()
  91. {
  92. // InitCommonControlsEx() is required on Windows XP if an application
  93. // manifest specifies use of ComCtl32.dll version 6 or later to enable
  94. // visual styles. Otherwise, any window creation will fail.
  95. INITCOMMONCONTROLSEX InitCtrls;
  96. InitCtrls.dwSize = sizeof(InitCtrls);
  97. // Set this to include all the common control classes you want to use
  98. // in your application.
  99. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  100. InitCommonControlsEx(&InitCtrls);
  101. CWinApp::InitInstance();
  102. AfxEnableControlContainer();
  103. // Standard initialization
  104. // If you are not using these features and wish to reduce the size
  105. // of your final executable, you should remove from the following
  106. // the specific initialization routines you do not need
  107. // Change the registry key under which our settings are stored
  108. // TODO: You should modify this string to be something appropriate
  109. // such as the name of your company or organization
  110. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  111. // 加载钩子
  112. DetourFunctionWithTrampoline((PBYTE)SetScrollInfoT, (PBYTE)SetScrollInfoD);
  113. DetourFunctionWithTrampoline((PBYTE)GetScrollInfoT, (PBYTE)GetScrollInfoD);
  114. DetourFunctionWithTrampoline((PBYTE)SetScrollPosT, (PBYTE)SetScrollPosD);
  115. DetourFunctionWithTrampoline((PBYTE)GetScrollPosT, (PBYTE)GetScrollPosD);
  116. DetourFunctionWithTrampoline((PBYTE)SetScrollRangeT, (PBYTE)SetScrollRangeD);
  117. DetourFunctionWithTrampoline((PBYTE)GetScrollRangeT, (PBYTE)GetScrollRangeD);
  118. DetourFunctionWithTrampoline((PBYTE)ShowScrollBarT, (PBYTE)ShowScrollBarD);
  119. DetourFunctionWithTrampoline((PBYTE)EnableScrollBarT, (PBYTE)EnableScrollBarD);
  120. CSkinSBDemoDlg dlg;
  121. m_pMainWnd = &dlg;
  122. INT_PTR nResponse = dlg.DoModal();
  123. if (nResponse == IDOK)
  124. {
  125. // TODO: Place code here to handle when the dialog is
  126. // dismissed with OK
  127. }
  128. else if (nResponse == IDCANCEL)
  129. {
  130. // TODO: Place code here to handle when the dialog is
  131. // dismissed with Cancel
  132. }
  133. // Since the dialog has been closed, return FALSE so that we exit the
  134. // application, rather than start the application's message pump.
  135. return FALSE;
  136. }
  137. int CSkinSBDemoApp::ExitInstance()
  138. {
  139. // 卸载钩子
  140. DetourRemove((PBYTE)SetScrollInfoT, (PBYTE)SetScrollInfoD);
  141. DetourRemove((PBYTE)SetScrollPosT, (PBYTE)SetScrollPosD);
  142. DetourRemove((PBYTE)GetScrollInfoT, (PBYTE)GetScrollInfoD);
  143. DetourRemove((PBYTE)GetScrollPosT, (PBYTE)GetScrollPosD);
  144. DetourRemove((PBYTE)SetScrollRangeT, (PBYTE)SetScrollRangeD);
  145. DetourRemove((PBYTE)GetScrollRangeT, (PBYTE)GetScrollRangeD);
  146. DetourRemove((PBYTE)ShowScrollBarT, (PBYTE)ShowScrollBarD);
  147. DetourRemove((PBYTE)EnableScrollBarT, (PBYTE)EnableScrollBarD);
  148. return CWinApp::ExitInstance();
  149. }