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.

121 lines
2.7 KiB

  1. #ifndef __SIMRECT_H_INCLUDED
  2. #define __SIMRECT_H_INCLUDED
  3. /*******************************************************************************
  4. *
  5. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  6. *
  7. * TITLE: SIMRECT.H
  8. *
  9. * VERSION: 1.0
  10. *
  11. * AUTHOR: ShaunIv
  12. *
  13. * DATE: 7/31/1999
  14. *
  15. * DESCRIPTION: Simple rect derived class. Especially handy for window coords.
  16. *
  17. *******************************************************************************/
  18. #include <windows.h>
  19. class CSimpleRect : public RECT
  20. {
  21. public:
  22. enum CWndRectType
  23. {
  24. ClientRect,
  25. WindowRect
  26. };
  27. CSimpleRect(void)
  28. {
  29. Assign(0,0,0,0);
  30. }
  31. CSimpleRect( const CSimpleRect &other )
  32. {
  33. Assign(other);
  34. }
  35. CSimpleRect( HWND hWnd, CWndRectType type = ClientRect )
  36. {
  37. Assign(0,0,0,0);
  38. if (ClientRect == type)
  39. GetClientRect(hWnd);
  40. else GetWindowRect(hWnd);
  41. }
  42. CSimpleRect( int nLeft, int nTop, int nRight, int nBottom )
  43. {
  44. Assign(nLeft,nTop,nRight,nBottom);
  45. }
  46. CSimpleRect &Assign( const CSimpleRect &other )
  47. {
  48. return(Assign(other.left,other.top,other.right,other.bottom));
  49. }
  50. CSimpleRect &Assign( int nLeft, int nTop, int nRight, int nBottom )
  51. {
  52. left = nLeft;
  53. top = nTop;
  54. right = nRight;
  55. bottom = nBottom;
  56. return(*this);
  57. }
  58. CSimpleRect &operator=( const CSimpleRect &other )
  59. {
  60. if (this == &other)
  61. return(*this);
  62. return(Assign(other));
  63. }
  64. static bool ScreenToClient( HWND hwnd, RECT &rc )
  65. {
  66. return (::MapWindowPoints( NULL, hwnd, reinterpret_cast<POINT*>(&rc), 2 ) != 0);
  67. }
  68. static bool ClientToScreen( HWND hwnd, RECT &rc )
  69. {
  70. return (::MapWindowPoints( hwnd, NULL, reinterpret_cast<POINT*>(&rc), 2 ) != 0);
  71. }
  72. CSimpleRect ScreenToClient( HWND hWnd ) const
  73. {
  74. CSimpleRect rc(*this);
  75. ScreenToClient( hWnd, rc );
  76. return(rc);
  77. }
  78. CSimpleRect ClientToScreen( HWND hWnd ) const
  79. {
  80. CSimpleRect rc(*this);
  81. ClientToScreen( hWnd, rc );
  82. return(rc);
  83. }
  84. CSimpleRect &GetWindowRect( HWND hWnd )
  85. {
  86. ::GetWindowRect( hWnd, this );
  87. return(*this);
  88. }
  89. CSimpleRect &GetClientRect( HWND hWnd )
  90. {
  91. ::GetClientRect( hWnd, this );
  92. return(*this);
  93. }
  94. int Width(void) const
  95. {
  96. return(right - left);
  97. }
  98. int Height(void) const
  99. {
  100. return(bottom - top);
  101. }
  102. CSimpleRect &Inflate( int cx, int cy )
  103. {
  104. InflateRect( this, cx, cy );
  105. return *this;
  106. }
  107. CSimpleRect &Offset( int cx, int cy )
  108. {
  109. OffsetRect( this, cx, cy );
  110. return *this;
  111. }
  112. };
  113. #endif //__SIMRECT_H_INCLUDED