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.

245 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Millionaire.cpp
  5. Abstract:
  6. On Win9x, paint messages did not always cause WM_ERASEBKGND messages. This
  7. is for applications that paint themselves before the WM_PAINT message and
  8. then pass WM_PAINT onto the default handler.
  9. Notes:
  10. This is a general purpose shim, but should not be in a layer.
  11. History:
  12. 06/05/2000 linstev Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(Millionaire)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(RegisterClassA)
  19. APIHOOK_ENUM_ENTRY(RegisterClassW)
  20. APIHOOK_ENUM_ENTRY(RegisterClassExA)
  21. APIHOOK_ENUM_ENTRY(RegisterClassExW)
  22. APIHOOK_ENUM_ENTRY(SetWindowLongA)
  23. APIHOOK_ENUM_ENTRY(SetWindowLongW)
  24. APIHOOK_ENUM_END
  25. /*++
  26. Handle paint messages
  27. --*/
  28. LRESULT
  29. CALLBACK
  30. Millionaire_WindowProcHook(
  31. WNDPROC pfnOld,
  32. HWND hwnd,
  33. UINT uMsg,
  34. WPARAM wParam,
  35. LPARAM lParam
  36. )
  37. {
  38. switch( uMsg )
  39. {
  40. case WM_PAINT:
  41. RECT r;
  42. if (GetUpdateRect(hwnd, &r, FALSE))
  43. {
  44. DPFN( eDbgLevelSpew, "Validating on paint");
  45. ValidateRect(hwnd, &r);
  46. }
  47. break;
  48. default: break;
  49. }
  50. return (*pfnOld)(hwnd, uMsg, wParam, lParam);
  51. }
  52. /*++
  53. The dialogproc hook
  54. --*/
  55. INT_PTR
  56. CALLBACK
  57. Millionaire_DialogProcHook(
  58. DLGPROC pfnOld,
  59. HWND hwndDlg,
  60. UINT uMsg,
  61. WPARAM wParam,
  62. LPARAM lParam
  63. )
  64. {
  65. return (*pfnOld)(hwndDlg, uMsg, wParam, lParam);
  66. }
  67. /*++
  68. Hook the wndproc
  69. --*/
  70. ATOM
  71. APIHOOK(RegisterClassA)(
  72. CONST WNDCLASSA *lpWndClass
  73. )
  74. {
  75. WNDCLASSA wcNewWndClass = *lpWndClass;
  76. wcNewWndClass.lpfnWndProc =
  77. (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, Millionaire_WindowProcHook);
  78. return ORIGINAL_API(RegisterClassA)(&wcNewWndClass);
  79. }
  80. /*++
  81. Hook the wndproc
  82. --*/
  83. ATOM
  84. APIHOOK(RegisterClassW)(
  85. CONST WNDCLASSW *lpWndClass
  86. )
  87. {
  88. WNDCLASSW wcNewWndClass = *lpWndClass;
  89. wcNewWndClass.lpfnWndProc =
  90. (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, Millionaire_WindowProcHook);
  91. return ORIGINAL_API(RegisterClassW)(&wcNewWndClass);
  92. }
  93. /*++
  94. Hook the wndproc
  95. --*/
  96. ATOM
  97. APIHOOK(RegisterClassExA)(
  98. CONST WNDCLASSEXA *lpwcx
  99. )
  100. {
  101. WNDCLASSEXA wcNewWndClass = *lpwcx;
  102. wcNewWndClass.lpfnWndProc =
  103. (WNDPROC) HookCallback(lpwcx->lpfnWndProc, Millionaire_WindowProcHook);
  104. return ORIGINAL_API(RegisterClassExA)(&wcNewWndClass);
  105. }
  106. /*++
  107. Hook the wndproc
  108. --*/
  109. ATOM
  110. APIHOOK(RegisterClassExW)(
  111. CONST WNDCLASSEXW *lpwcx
  112. )
  113. {
  114. WNDCLASSEXW wcNewWndClass = *lpwcx;
  115. wcNewWndClass.lpfnWndProc =
  116. (WNDPROC) HookCallback(lpwcx->lpfnWndProc, Millionaire_WindowProcHook);
  117. return ORIGINAL_API(RegisterClassExW)(&wcNewWndClass);
  118. }
  119. /*++
  120. Hook the wndproc
  121. --*/
  122. LONG
  123. APIHOOK(SetWindowLongA)(
  124. HWND hWnd,
  125. int nIndex,
  126. LONG dwNewLong
  127. )
  128. {
  129. if (nIndex == GWL_WNDPROC)
  130. {
  131. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Millionaire_WindowProcHook);
  132. }
  133. else if (nIndex == DWL_DLGPROC)
  134. {
  135. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Millionaire_DialogProcHook);
  136. }
  137. return ORIGINAL_API(SetWindowLongA)(
  138. hWnd,
  139. nIndex,
  140. dwNewLong);
  141. }
  142. /*++
  143. Hook the wndproc
  144. --*/
  145. LONG
  146. APIHOOK(SetWindowLongW)(
  147. HWND hWnd,
  148. int nIndex,
  149. LONG dwNewLong
  150. )
  151. {
  152. if (nIndex == GWL_WNDPROC)
  153. {
  154. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Millionaire_WindowProcHook);
  155. }
  156. else if (nIndex == DWL_DLGPROC)
  157. {
  158. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Millionaire_DialogProcHook);
  159. }
  160. return ORIGINAL_API(SetWindowLongA)(
  161. hWnd,
  162. nIndex,
  163. dwNewLong);
  164. }
  165. /*++
  166. Register hooked functions
  167. --*/
  168. HOOK_BEGIN
  169. APIHOOK_ENTRY(USER32.DLL, RegisterClassA)
  170. APIHOOK_ENTRY(USER32.DLL, RegisterClassW)
  171. APIHOOK_ENTRY(USER32.DLL, RegisterClassExA)
  172. APIHOOK_ENTRY(USER32.DLL, RegisterClassExW)
  173. APIHOOK_ENTRY(USER32.DLL, SetWindowLongA)
  174. APIHOOK_ENTRY(USER32.DLL, SetWindowLongW)
  175. HOOK_END
  176. IMPLEMENT_SHIM_END