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.

188 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Descent2.cpp
  5. Abstract:
  6. Hooks all application-defined window procedures and forcefully clears the
  7. background to white. For some reason the EraseBackground that normally
  8. comes through on win9x does not always work.
  9. Notes:
  10. This shim can be reused for other shims that need to forcefully clear the
  11. background.
  12. History:
  13. 03/28/2000 a-michni Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(Descent2)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(RegisterClassA)
  20. APIHOOK_ENUM_ENTRY(RegisterClassW)
  21. APIHOOK_ENUM_ENTRY(RegisterClassExA)
  22. APIHOOK_ENUM_ENTRY(RegisterClassExW)
  23. APIHOOK_ENUM_ENTRY(SetWindowLongA)
  24. APIHOOK_ENUM_ENTRY(SetWindowLongW)
  25. APIHOOK_ENUM_END
  26. /*++
  27. Change WM_ERASEBKGND behaviour
  28. --*/
  29. LRESULT CALLBACK
  30. Descent2_WindowProcHook(
  31. WNDPROC pfnOld, // address of old WindowProc
  32. HWND hwnd, // handle to window
  33. UINT uMsg, // message identifier
  34. WPARAM wParam, // first message parameter
  35. LPARAM lParam // second message parameter
  36. )
  37. {
  38. HDC hdc;
  39. RECT rc;
  40. /* Retrieve the size info and fill with a standard White */
  41. switch( uMsg )
  42. {
  43. case WM_ERASEBKGND:
  44. hdc = (HDC) wParam;
  45. GetClientRect(hwnd, &rc);
  46. SetMapMode(hdc, MM_ANISOTROPIC);
  47. SetWindowExtEx(hdc, 100, 100, NULL);
  48. SetViewportExtEx(hdc, rc.right, rc.bottom, NULL);
  49. FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
  50. break;
  51. default: break;
  52. }
  53. return (*pfnOld)(hwnd, uMsg, wParam, lParam);
  54. }
  55. INT_PTR CALLBACK
  56. Descent2_DialogProcHook(
  57. DLGPROC pfnOld, // address of old DialogProc
  58. HWND hwndDlg, // handle to dialog box
  59. UINT uMsg, // message
  60. WPARAM wParam, // first message parameter
  61. LPARAM lParam // second message parameter
  62. )
  63. {
  64. return (*pfnOld)(hwndDlg, uMsg, wParam, lParam);
  65. }
  66. ATOM
  67. APIHOOK(RegisterClassA)(
  68. CONST WNDCLASSA *lpWndClass // class data
  69. )
  70. {
  71. WNDCLASSA wcNewWndClass = *lpWndClass;
  72. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, Descent2_WindowProcHook);
  73. return ORIGINAL_API(RegisterClassA)(&wcNewWndClass);
  74. }
  75. ATOM
  76. APIHOOK(RegisterClassW)(
  77. CONST WNDCLASSW *lpWndClass // class data
  78. )
  79. {
  80. WNDCLASSW wcNewWndClass = *lpWndClass;
  81. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpWndClass->lpfnWndProc, Descent2_WindowProcHook);
  82. return ORIGINAL_API(RegisterClassW)(&wcNewWndClass);
  83. }
  84. ATOM
  85. APIHOOK(RegisterClassExA)(
  86. CONST WNDCLASSEXA *lpwcx // class data
  87. )
  88. {
  89. WNDCLASSEXA wcNewWndClass = *lpwcx;
  90. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpwcx->lpfnWndProc, Descent2_WindowProcHook);
  91. return ORIGINAL_API(RegisterClassExA)(&wcNewWndClass);
  92. }
  93. ATOM
  94. APIHOOK(RegisterClassExW)(
  95. CONST WNDCLASSEXW *lpwcx // class data
  96. )
  97. {
  98. WNDCLASSEXW wcNewWndClass = *lpwcx;
  99. wcNewWndClass.lpfnWndProc = (WNDPROC) HookCallback(lpwcx->lpfnWndProc, Descent2_WindowProcHook);
  100. return ORIGINAL_API(RegisterClassExW)(&wcNewWndClass);
  101. }
  102. LONG
  103. APIHOOK(SetWindowLongA)(
  104. HWND hWnd,
  105. int nIndex,
  106. LONG dwNewLong
  107. )
  108. {
  109. if( nIndex == GWL_WNDPROC )
  110. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Descent2_WindowProcHook);
  111. else if( nIndex == DWL_DLGPROC )
  112. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Descent2_DialogProcHook);
  113. return ORIGINAL_API(SetWindowLongA)(hWnd, nIndex, dwNewLong );
  114. }
  115. LONG
  116. APIHOOK(SetWindowLongW)(
  117. HWND hWnd,
  118. int nIndex,
  119. LONG dwNewLong
  120. )
  121. {
  122. if( nIndex == GWL_WNDPROC )
  123. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Descent2_WindowProcHook);
  124. else if( nIndex == DWL_DLGPROC )
  125. dwNewLong = (LONG) HookCallback((PVOID)dwNewLong, Descent2_DialogProcHook);
  126. return ORIGINAL_API(SetWindowLongA)(hWnd, nIndex, dwNewLong );
  127. }
  128. /*++
  129. Register hooked functions
  130. --*/
  131. HOOK_BEGIN
  132. APIHOOK_ENTRY(USER32.DLL, RegisterClassA)
  133. APIHOOK_ENTRY(USER32.DLL, RegisterClassW)
  134. APIHOOK_ENTRY(USER32.DLL, RegisterClassExA)
  135. APIHOOK_ENTRY(USER32.DLL, RegisterClassExW)
  136. APIHOOK_ENTRY(USER32.DLL, SetWindowLongA)
  137. APIHOOK_ENTRY(USER32.DLL, SetWindowLongW)
  138. HOOK_END
  139. IMPLEMENT_SHIM_END