Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PlaneCrazy.cpp
  5. Abstract:
  6. Hooks all application-defined window procedures and adds a WM_PAINT
  7. message upon receipt of a WM_SETFOCUS. For some reason the one that normally
  8. came through on win9x gets lost.
  9. Notes:
  10. This shim can be reused for other shims that require WindowProc hooking.
  11. Copy all APIHook_* functions and simply replace the code in PlaneCrazy_WindowProcHook
  12. and PlaneCrazy_DialogProcHook.
  13. History:
  14. 11/01/1999 markder Created
  15. 02/15/1999 markder Reworked WndProc hooking mechanism so that it generically
  16. hooks all WndProcs for the process.
  17. 02/15/1999 a-chcoff copied to here and created this shim with code base.
  18. --*/
  19. #include "precomp.h"
  20. IMPLEMENT_SHIM_BEGIN(PlaneCrazy)
  21. #include "ShimHookMacro.h"
  22. APIHOOK_ENUM_BEGIN
  23. APIHOOK_ENUM_ENTRY(RegisterClassA)
  24. APIHOOK_ENUM_ENTRY(RegisterClassW)
  25. APIHOOK_ENUM_ENTRY(RegisterClassExA)
  26. APIHOOK_ENUM_ENTRY(RegisterClassExW)
  27. APIHOOK_ENUM_ENTRY(CreateDialogParamA)
  28. APIHOOK_ENUM_ENTRY(CreateDialogParamW)
  29. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamA)
  30. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamW)
  31. APIHOOK_ENUM_ENTRY(CreateDialogIndirectParamAorW)
  32. APIHOOK_ENUM_ENTRY(SetWindowLongA)
  33. APIHOOK_ENUM_ENTRY(SetWindowLongW)
  34. APIHOOK_ENUM_END
  35. /*++
  36. Change WM_DRAWITEM behaviour
  37. --*/
  38. LRESULT CALLBACK
  39. PlaneCrazy_WindowProcHook(
  40. WNDPROC pfnOld, // address of old WindowProc
  41. HWND hwnd, // handle to window
  42. UINT uMsg, // message identifier
  43. WPARAM wParam, // first message parameter
  44. LPARAM lParam // second message parameter
  45. )
  46. {
  47. // Check for message we're interested in
  48. if (uMsg == WM_SETFOCUS)
  49. {
  50. SendMessage(hwnd,WM_PAINT,NULL,NULL);
  51. }
  52. return (*pfnOld)(hwnd, uMsg, wParam, lParam);
  53. }
  54. INT_PTR CALLBACK
  55. PlaneCrazy_DialogProcHook(
  56. DLGPROC pfnOld, // address of old DialogProc
  57. HWND hwndDlg, // handle to dialog box
  58. UINT uMsg, // message
  59. WPARAM wParam, // first message parameter
  60. LPARAM lParam // second message parameter
  61. )
  62. {
  63. // Check for message we're interested in
  64. if (uMsg == WM_SETFOCUS)
  65. {
  66. SendMessage(hwndDlg,WM_PAINT,NULL,NULL);
  67. }
  68. return (*pfnOld)(hwndDlg, uMsg, wParam, lParam);
  69. }
  70. /*++
  71. Hook all possible calls that can initialize or change a window's
  72. WindowProc (or DialogProc)
  73. --*/
  74. ATOM
  75. APIHOOK(RegisterClassA)(
  76. CONST WNDCLASSA *lpWndClass // class data
  77. )
  78. {
  79. WNDCLASSA wcNewWndClass = *lpWndClass;
  80. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, PlaneCrazy_WindowProcHook);
  81. return ORIGINAL_API(RegisterClassA)(&wcNewWndClass);
  82. }
  83. ATOM
  84. APIHOOK(RegisterClassW)(
  85. CONST WNDCLASSW *lpWndClass // class data
  86. )
  87. {
  88. WNDCLASSW wcNewWndClass = *lpWndClass;
  89. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, PlaneCrazy_WindowProcHook);
  90. return ORIGINAL_API(RegisterClassW)(&wcNewWndClass);
  91. }
  92. ATOM
  93. APIHOOK(RegisterClassExA)(
  94. CONST WNDCLASSEXA *lpwcx // class data
  95. )
  96. {
  97. WNDCLASSEXA wcNewWndClass = *lpwcx;
  98. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpwcx->lpfnWndProc, PlaneCrazy_WindowProcHook);
  99. return ORIGINAL_API(RegisterClassExA)(&wcNewWndClass);
  100. }
  101. ATOM
  102. APIHOOK(RegisterClassExW)(
  103. CONST WNDCLASSEXW *lpwcx // class data
  104. )
  105. {
  106. WNDCLASSEXW wcNewWndClass = *lpwcx;
  107. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpwcx->lpfnWndProc, PlaneCrazy_WindowProcHook);
  108. return ORIGINAL_API(RegisterClassExW)(&wcNewWndClass);
  109. }
  110. HWND
  111. APIHOOK(CreateDialogParamA)(
  112. HINSTANCE hInstance, // handle to module
  113. LPCSTR lpTemplateName, // dialog box template
  114. HWND hWndParent, // handle to owner window
  115. DLGPROC lpDialogFunc, // dialog box procedure
  116. LPARAM dwInitParam // initialization value
  117. )
  118. {
  119. lpDialogFunc = (DLGPROC) HookCallback(lpDialogFunc, PlaneCrazy_DialogProcHook);
  120. return ORIGINAL_API(CreateDialogParamA)( hInstance,
  121. lpTemplateName,
  122. hWndParent,
  123. lpDialogFunc,
  124. dwInitParam );
  125. }
  126. HWND
  127. APIHOOK(CreateDialogParamW)(
  128. HINSTANCE hInstance, // handle to module
  129. LPCWSTR lpTemplateName, // dialog box template
  130. HWND hWndParent, // handle to owner window
  131. DLGPROC lpDialogFunc, // dialog box procedure
  132. LPARAM dwInitParam // initialization value
  133. )
  134. {
  135. lpDialogFunc = (DLGPROC) HookCallback(lpDialogFunc, PlaneCrazy_DialogProcHook);
  136. return ORIGINAL_API(CreateDialogParamW)( hInstance,
  137. lpTemplateName,
  138. hWndParent,
  139. lpDialogFunc,
  140. dwInitParam );
  141. }
  142. HWND
  143. APIHOOK(CreateDialogIndirectParamA)(
  144. HINSTANCE hInstance, // handle to module
  145. LPCDLGTEMPLATE lpTemplate, // dialog box template
  146. HWND hWndParent, // handle to owner window
  147. DLGPROC lpDialogFunc, // dialog box procedure
  148. LPARAM lParamInit // initialization value
  149. )
  150. {
  151. lpDialogFunc = (DLGPROC) HookCallback(lpDialogFunc, PlaneCrazy_DialogProcHook);
  152. return ORIGINAL_API(CreateDialogIndirectParamA)( hInstance,
  153. lpTemplate,
  154. hWndParent,
  155. lpDialogFunc,
  156. lParamInit );
  157. }
  158. HWND
  159. APIHOOK(CreateDialogIndirectParamW)(
  160. HINSTANCE hInstance, // handle to module
  161. LPCDLGTEMPLATE lpTemplate, // dialog box template
  162. HWND hWndParent, // handle to owner window
  163. DLGPROC lpDialogFunc, // dialog box procedure
  164. LPARAM lParamInit // initialization value
  165. )
  166. {
  167. lpDialogFunc = (DLGPROC) HookCallback(lpDialogFunc, PlaneCrazy_DialogProcHook);
  168. return ORIGINAL_API(CreateDialogIndirectParamW)( hInstance,
  169. lpTemplate,
  170. hWndParent,
  171. lpDialogFunc,
  172. lParamInit );
  173. }
  174. HWND
  175. APIHOOK(CreateDialogIndirectParamAorW)(
  176. HINSTANCE hInstance, // handle to module
  177. LPCDLGTEMPLATE lpTemplate, // dialog box template
  178. HWND hWndParent, // handle to owner window
  179. DLGPROC lpDialogFunc, // dialog box procedure
  180. LPARAM lParamInit // initialization value
  181. )
  182. {
  183. lpDialogFunc = (DLGPROC) HookCallback(lpDialogFunc, PlaneCrazy_DialogProcHook);
  184. return ORIGINAL_API(CreateDialogIndirectParamAorW)( hInstance,
  185. lpTemplate,
  186. hWndParent,
  187. lpDialogFunc,
  188. lParamInit );
  189. }
  190. LONG
  191. APIHOOK(SetWindowLongA)(
  192. HWND hWnd,
  193. int nIndex,
  194. LONG dwNewLong
  195. )
  196. {
  197. if( nIndex == GWL_WNDPROC )
  198. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, PlaneCrazy_WindowProcHook);
  199. else if( nIndex == DWL_DLGPROC )
  200. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, PlaneCrazy_DialogProcHook);
  201. return ORIGINAL_API(SetWindowLongA)( hWnd,
  202. nIndex,
  203. dwNewLong );
  204. }
  205. LONG
  206. APIHOOK(SetWindowLongW)(
  207. HWND hWnd,
  208. int nIndex,
  209. LONG dwNewLong
  210. )
  211. {
  212. if( nIndex == GWL_WNDPROC )
  213. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, PlaneCrazy_WindowProcHook);
  214. else if( nIndex == DWL_DLGPROC )
  215. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, PlaneCrazy_DialogProcHook);
  216. return ORIGINAL_API(SetWindowLongA)( hWnd,
  217. nIndex,
  218. dwNewLong );
  219. }
  220. /*++
  221. Register hooked functions
  222. --*/
  223. HOOK_BEGIN
  224. APIHOOK_ENTRY(USER32.DLL, RegisterClassA)
  225. APIHOOK_ENTRY(USER32.DLL, RegisterClassW)
  226. APIHOOK_ENTRY(USER32.DLL, RegisterClassExA)
  227. APIHOOK_ENTRY(USER32.DLL, RegisterClassExW)
  228. APIHOOK_ENTRY(USER32.DLL, CreateDialogParamA)
  229. APIHOOK_ENTRY(USER32.DLL, CreateDialogParamW)
  230. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamA)
  231. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamW)
  232. APIHOOK_ENTRY(USER32.DLL, CreateDialogIndirectParamAorW)
  233. APIHOOK_ENTRY(USER32.DLL, SetWindowLongA)
  234. APIHOOK_ENTRY(USER32.DLL, SetWindowLongW)
  235. HOOK_END
  236. IMPLEMENT_SHIM_END