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.

90 lines
2.2 KiB

  1. //+---------------------------------------------------------------------
  2. //
  3. // File: himetric.cxx
  4. //
  5. // Contents: Routines to convert Pixels to Himetric and vice versa
  6. //
  7. //----------------------------------------------------------------------
  8. #include "headers.hxx"
  9. #pragma hdrstop
  10. #define HIMETRIC_PER_INCH 2540L
  11. //+---------------------------------------------------------------
  12. //
  13. // Function: HimetricFromHPix
  14. //
  15. // Synopsis: Converts horizontal pixel units to himetric units.
  16. //
  17. //----------------------------------------------------------------
  18. long
  19. HimetricFromHPix(int iPix)
  20. {
  21. HDC hdc = GetDC(NULL);
  22. if (!hdc)
  23. return 0;
  24. int iPPLI = GetDeviceCaps(hdc, LOGPIXELSX);
  25. ReleaseDC(NULL, hdc);
  26. return (HIMETRIC_PER_INCH * (long)iPix)/(long)iPPLI;
  27. }
  28. //+---------------------------------------------------------------
  29. //
  30. // Function: HimetricFromVPix
  31. //
  32. // Synopsis: Converts vertical pixel units to himetric units.
  33. //
  34. //----------------------------------------------------------------
  35. long
  36. HimetricFromVPix(int iPix)
  37. {
  38. HDC hdc = GetDC(NULL);
  39. if (!hdc)
  40. return 0;
  41. int iPPLI = GetDeviceCaps(hdc, LOGPIXELSY);
  42. ReleaseDC(NULL, hdc);
  43. return (HIMETRIC_PER_INCH * (long)iPix)/(long)iPPLI;
  44. }
  45. //+---------------------------------------------------------------
  46. //
  47. // Function: HPixFromHimetric
  48. //
  49. // Synopsis: Converts himetric units to horizontal pixel units.
  50. //
  51. //----------------------------------------------------------------
  52. int
  53. HPixFromHimetric(long lHi)
  54. {
  55. HDC hdc = GetDC(NULL);
  56. if (!hdc)
  57. return 0;
  58. int iPPLI = GetDeviceCaps(hdc, LOGPIXELSX);
  59. ReleaseDC(NULL, hdc);
  60. return (int)(( (iPPLI * lHi) + (HIMETRIC_PER_INCH / 2) )/HIMETRIC_PER_INCH);
  61. }
  62. //+---------------------------------------------------------------
  63. //
  64. // Function: VPixFromHimetric
  65. //
  66. // Synopsis: Converts himetric units to vertical pixel units.
  67. //
  68. //----------------------------------------------------------------
  69. int
  70. VPixFromHimetric(long lHi)
  71. {
  72. HDC hdc = GetDC(NULL);
  73. if (!hdc)
  74. return 0;
  75. int iPPLI = GetDeviceCaps(hdc, LOGPIXELSY);
  76. ReleaseDC(NULL, hdc);
  77. return (int)(( (iPPLI * lHi) + (HIMETRIC_PER_INCH / 2) )/HIMETRIC_PER_INCH);
  78. }