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.

159 lines
3.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: himetric.cpp
  4. //
  5. // Module: Connection Manager
  6. //
  7. // Synopsis: Routines to convert Pixels to Himetric and vice versa
  8. //
  9. // Copyright (c) 1998 Microsoft Corporation
  10. //
  11. // Author: nickball Created 02/10/98
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include "cmmaster.h"
  15. #pragma hdrstop
  16. #define HIMETRIC_PER_INCH 2540L
  17. SIZE g_sizePixelsPerInch;
  18. //+------------------------------------------------------------------------
  19. //
  20. // Function: InitPixelsPerInch
  21. //
  22. // Synopsis: Initializing coordinate mapping for screen pixels
  23. //
  24. // Returns: HRESULT; S_OK on success, E_OUTOFMEMORY otherwise
  25. //
  26. //-------------------------------------------------------------------------
  27. void
  28. InitPixelsPerInch(VOID)
  29. {
  30. HDC hdc;
  31. hdc = GetDC(NULL);
  32. if (!hdc)
  33. goto Error;
  34. g_sizePixelsPerInch.cx = GetDeviceCaps(hdc, LOGPIXELSX);
  35. g_sizePixelsPerInch.cy = GetDeviceCaps(hdc, LOGPIXELSY);
  36. ReleaseDC(NULL, hdc);
  37. Cleanup:
  38. return;
  39. Error:
  40. g_sizePixelsPerInch.cx = 96;
  41. g_sizePixelsPerInch.cy = 96;
  42. goto Cleanup;
  43. }
  44. //+---------------------------------------------------------------
  45. //
  46. // Function: HimetricFromHPix
  47. //
  48. // Synopsis: Converts horizontal pixel units to himetric units.
  49. //
  50. //----------------------------------------------------------------
  51. long
  52. HimetricFromHPix(int iPix)
  53. {
  54. if (!g_sizePixelsPerInch.cx)
  55. InitPixelsPerInch();
  56. return MulDiv(iPix, HIMETRIC_PER_INCH, g_sizePixelsPerInch.cx);
  57. }
  58. //+---------------------------------------------------------------
  59. //
  60. // Function: HimetricFromVPix
  61. //
  62. // Synopsis: Converts vertical pixel units to himetric units.
  63. //
  64. //----------------------------------------------------------------
  65. long
  66. HimetricFromVPix(int iPix)
  67. {
  68. if (!g_sizePixelsPerInch.cy)
  69. InitPixelsPerInch();
  70. return MulDiv(iPix, HIMETRIC_PER_INCH, g_sizePixelsPerInch.cy);
  71. }
  72. //+---------------------------------------------------------------
  73. //
  74. // Function: HPixFromHimetric
  75. //
  76. // Synopsis: Converts himetric units to horizontal pixel units.
  77. //
  78. //----------------------------------------------------------------
  79. int
  80. HPixFromHimetric(long lHi)
  81. {
  82. if (!g_sizePixelsPerInch.cx)
  83. InitPixelsPerInch();
  84. return MulDiv(g_sizePixelsPerInch.cx, lHi, HIMETRIC_PER_INCH);
  85. }
  86. //+---------------------------------------------------------------
  87. //
  88. // Function: VPixFromHimetric
  89. //
  90. // Synopsis: Converts himetric units to vertical pixel units.
  91. //
  92. //----------------------------------------------------------------
  93. int
  94. VPixFromHimetric(long lHi)
  95. {
  96. if (!g_sizePixelsPerInch.cy)
  97. InitPixelsPerInch();
  98. return MulDiv(g_sizePixelsPerInch.cy, lHi, HIMETRIC_PER_INCH);
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Function: PixelFromHMRect
  103. //
  104. // Synopsis: Converts a Himetric RECTL to a Pixel RECT
  105. //
  106. //----------------------------------------------------------------------------
  107. void
  108. PixelFromHMRect(RECT *prcDest, RECTL *prcSrc)
  109. {
  110. prcDest->left = HPixFromHimetric(prcSrc->left);
  111. prcDest->top = VPixFromHimetric(prcSrc->top);
  112. prcDest->right = HPixFromHimetric(prcSrc->right);
  113. prcDest->bottom = VPixFromHimetric(prcSrc->bottom);
  114. }
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Function: HMFromPixelRect
  118. //
  119. // Synopsis: Converts a Pixel RECT to a Himetric RECTL
  120. //
  121. //----------------------------------------------------------------------------
  122. void
  123. HMFromPixelRect(RECTL *prcDest, RECT *prcSrc)
  124. {
  125. prcDest->left = HimetricFromHPix(prcSrc->left);
  126. prcDest->top = HimetricFromVPix(prcSrc->top);
  127. prcDest->right = HimetricFromHPix(prcSrc->right);
  128. prcDest->bottom = HimetricFromVPix(prcSrc->bottom);
  129. }