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.

147 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FakeThemeMetrics.cpp
  5. Abstract:
  6. This Shim will allow the Skemers group to shim applications that do not behave
  7. well with "Themed" system metrics
  8. History:
  9. 11/30/2000 a-brienw Converted to shim frame work version 2.
  10. --*/
  11. #include "precomp.h"
  12. #ifndef ARRAYSIZE
  13. #define ARRAYSIZE(x) sizeof(x)/sizeof((x)[0])
  14. #endif
  15. IMPLEMENT_SHIM_BEGIN(FakeThemeMetrics)
  16. #include "ShimHookMacro.h"
  17. // Add APIs that you wish to hook to this enumeration. The first one
  18. // must have "= USERAPIHOOKSTART", and the last one must be
  19. // APIHOOK_Count.
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(GetSysColor)
  22. APIHOOK_ENUM_END
  23. #define F_TYPE_RGB 0
  24. #define F_TYPE_MAP 1
  25. #define F_TYPE_PERCENT 2
  26. #define F_TYPE_MAX 3
  27. #define F_TYPE_NOTEQUAL 4
  28. typedef struct
  29. {
  30. int nIndex;
  31. DWORD fType;
  32. COLORREF rgb;
  33. int nMap; // If mapping we need to use the post processed color. Call HookedGetSysColor. See note
  34. int iPercent;
  35. } GETSYSCOLOR_MAP;
  36. const static GETSYSCOLOR_MAP s_ColorMap[] =
  37. {
  38. {COLOR_MENU, F_TYPE_MAP, RGB(212, 208, 200), COLOR_BTNFACE, 10},
  39. {COLOR_BTNFACE, F_TYPE_MAX, RGB(227, 227, 227), 0, 0},
  40. {COLOR_3DDKSHADOW, F_TYPE_NOTEQUAL, RGB(0,0,0), COLOR_BTNFACE, 20}
  41. };
  42. COLORREF AdjustPercent(COLORREF crOld, int iPercent)
  43. {
  44. return RGB(GetRValue(crOld) - (GetRValue(crOld) * iPercent) / 100,
  45. GetGValue(crOld) - (GetGValue(crOld) * iPercent) / 100,
  46. GetBValue(crOld) - (GetBValue(crOld) * iPercent) / 100);
  47. }
  48. // NOTE: If you are mapping a color (i.e. a direct map), then you need to call HookedGetSysColor. For example
  49. // MSDEV calls GetSysColor(COLOR_BTNFACE). It then calls GetSysColor(COLOR_MENU) and compares the two.
  50. // If they are different then it pukes. However we hook both COLOR_MENU and COLOR_BTNFACE. So we need to get the mapped color.
  51. DWORD HookedGetSysColor(int nIndex)
  52. {
  53. for (int i = 0; i < ARRAYSIZE(s_ColorMap); i++)
  54. {
  55. if (nIndex == s_ColorMap[i].nIndex)
  56. {
  57. switch (s_ColorMap[i].fType)
  58. {
  59. case F_TYPE_RGB:
  60. return (DWORD)s_ColorMap[i].rgb;
  61. break;
  62. case F_TYPE_MAP:
  63. return HookedGetSysColor(s_ColorMap[i].nMap);
  64. break;
  65. case F_TYPE_PERCENT:
  66. {
  67. COLORREF crOld = (COLORREF)ORIGINAL_API(GetSysColor)(nIndex);
  68. return (DWORD)AdjustPercent(crOld, s_ColorMap[i].iPercent);
  69. }
  70. case F_TYPE_MAX:
  71. {
  72. COLORREF crOld = (COLORREF)ORIGINAL_API(GetSysColor)(nIndex);
  73. BYTE r = GetRValue(crOld);
  74. BYTE g = GetGValue(crOld);
  75. BYTE b = GetBValue(crOld);
  76. if (r > GetRValue(s_ColorMap[i].rgb))
  77. r = GetRValue(s_ColorMap[i].rgb);
  78. if (g > GetGValue(s_ColorMap[i].rgb))
  79. g = GetGValue(s_ColorMap[i].rgb);
  80. if (b > GetBValue(s_ColorMap[i].rgb))
  81. b = GetBValue(s_ColorMap[i].rgb);
  82. return RGB(r,g,b);
  83. }
  84. case F_TYPE_NOTEQUAL:
  85. {
  86. COLORREF crOld = (COLORREF)ORIGINAL_API(GetSysColor)(nIndex);
  87. COLORREF crNotEqual = (COLORREF)HookedGetSysColor(s_ColorMap[i].nMap);
  88. if (crOld == crNotEqual)
  89. {
  90. crOld = AdjustPercent(crOld, s_ColorMap[i].iPercent);
  91. }
  92. return crOld;
  93. }
  94. }
  95. break;
  96. }
  97. }
  98. return ORIGINAL_API(GetSysColor)( nIndex );
  99. }
  100. DWORD
  101. APIHOOK(GetSysColor)(int nIndex)
  102. {
  103. return HookedGetSysColor(nIndex);
  104. }
  105. /*++
  106. Register hooked functions
  107. --*/
  108. HOOK_BEGIN
  109. APIHOOK_ENTRY(USER32.DLL, GetSysColor)
  110. HOOK_END
  111. IMPLEMENT_SHIM_END