Source code of Windows XP (NT5)
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.

128 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. EmulateDrawText.cpp
  5. Abstract:
  6. Win9x DrawText modified the rectangle coordinates if they were
  7. out of range. With Win2000 the text will not appear on the
  8. screen with out of range formatting dimensions. The solution
  9. is to toggle the high order bit for out of range coordinates.
  10. We also cast nCount to 16-bits for apps which pass 0x0000ffff
  11. instead of a true -1, because the Win9x thunk does this.
  12. Notes:
  13. This is a general purpose shim.
  14. History:
  15. 05/03/2000 a-michni Created
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(EmulateDrawText)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(DrawTextA)
  22. APIHOOK_ENUM_ENTRY(DrawTextW)
  23. APIHOOK_ENUM_END
  24. /*++
  25. Correct the formatting dimensions if necessary.
  26. --*/
  27. long
  28. Fix_Coordinate(
  29. long nCoord
  30. )
  31. {
  32. if ((nCoord & 0x80000000) && ((nCoord & 0x40000000) == 0)) {
  33. nCoord &= 0x7FFFFFFF;
  34. } else if (((nCoord & 0x80000000) == 0) && (nCoord & 0x40000000)) {
  35. nCoord |= 0x10000000;
  36. }
  37. return nCoord;
  38. }
  39. LPRECT
  40. Fix_Coordinates(
  41. LPRECT lpRect
  42. )
  43. {
  44. //
  45. // Check bit 32, if it is on and bit 31 is off or bit 32 is off and
  46. // bit 31 is on, flip bit 32.
  47. //
  48. lpRect->left = Fix_Coordinate(lpRect->left);
  49. lpRect->right = Fix_Coordinate(lpRect->right);
  50. lpRect->top = Fix_Coordinate(lpRect->top);
  51. lpRect->bottom= Fix_Coordinate(lpRect->bottom);
  52. return lpRect;
  53. }
  54. int
  55. APIHOOK(DrawTextA)(
  56. HDC hDC, // handle to DC
  57. LPCSTR lpString, // text to draw
  58. int nCount, // text length
  59. LPRECT lpRect, // formatting dimensions
  60. UINT uFormat // text-drawing options
  61. )
  62. {
  63. return ORIGINAL_API(DrawTextA)(
  64. hDC,
  65. lpString,
  66. (__int16) nCount,
  67. Fix_Coordinates(lpRect),
  68. uFormat);
  69. }
  70. int
  71. APIHOOK(DrawTextW)(
  72. HDC hDC, // handle to DC
  73. LPCWSTR lpString, // text to draw
  74. int nCount, // text length
  75. LPRECT lpRect, // formatting dimensions
  76. UINT uFormat // text-drawing options
  77. )
  78. {
  79. return ORIGINAL_API(DrawTextW)(
  80. hDC,
  81. lpString,
  82. (__int16) nCount,
  83. Fix_Coordinates(lpRect),
  84. uFormat);
  85. }
  86. /*++
  87. Register hooked functions
  88. --*/
  89. HOOK_BEGIN
  90. APIHOOK_ENTRY(USER32.DLL, DrawTextA)
  91. APIHOOK_ENTRY(USER32.DLL, DrawTextW)
  92. HOOK_END
  93. IMPLEMENT_SHIM_END