WinapiExtension
 All Classes Files Functions Variables Typedefs Pages
rect.h
1 #ifndef WINAPI_EX_RECT_H
2 #define WINAPI_EX_RECT_H
3 
7 struct Point : public POINT
8 {
10  Point(LONG px = 0, LONG py = 0)
11  {
12  x = px;
13  y = py;
14  }
15 
17  Point(const POINT& other)
18  {
19  x = other.x;
20  y = other.y;
21  }
22 
24  void operator=(const POINT& other)
25  {
26  x = other.x;
27  y = other.y;
28  }
29 
31  bool operator==(const POINT& other) const { return x == other.x && y == other.y; }
32 
34  Point& ClientToScreen(HWND window)
35  {
36  ::ClientToScreen(window, this);
37  return *this;
38  }
39 
41  Point& ScreenToClient(HWND window)
42  {
43  ::ScreenToClient(window, this);
44  return *this;
45  }
46 
48  Point operator+(const POINT& other) { return Point(x + other.x, y + other.y); }
49 
51  Point operator-(const POINT& other) { return Point(x - other.x, y - other.y); }
52 
54  Point& operator+=(const POINT& other)
55  {
56  x += other.x;
57  y += other.y;
58  return *this;
59  }
60 
62  Point& operator-=(const POINT& other)
63  {
64  x -= other.x;
65  y -= other.y;
66  return *this;
67  }
68 };
69 
73 struct Size : public SIZE
74 {
76  Size(LONG width = 0, LONG height = 0)
77  {
78  cx = width;
79  cy = height;
80  }
81 
83  Size(const SIZE& other)
84  {
85  cx = other.cx;
86  cy = other.cy;
87  }
88 
90  void operator=(const SIZE& other)
91  {
92  cx = other.cx;
93  cy = other.cy;
94  }
95 
97  bool operator==(const SIZE& other) const { return cx == other.cx && cy == other.cy; }
98 };
99 
103 struct Rect : public RECT
104 {
107  {
108  left = top = right = bottom = 0;
109  }
110 
111  Rect(LONG x, LONG y, LONG width, LONG height)
112  {
113  left = x;
114  top = y;
115  right = left + width;
116  bottom = top + height;
117  }
118 
120  Rect(const POINT& topleft, const SIZE& size)
121  {
122  Set(topleft, size);
123  }
124 
126  Rect(const POINT& topleft, const POINT& bottomright)
127  {
128  Set(topleft, bottomright);
129  }
130 
132  Rect(const RECT& other)
133  {
134  left = other.left;
135  top = other.top;
136  right = other.right;
137  bottom = other.bottom;
138  }
139 
141  void operator=(const RECT& other)
142  {
143  left = other.left;
144  top = other.top;
145  right = other.right;
146  bottom = other.bottom;
147  }
148 
150  void Set(const POINT& topleft, const SIZE& size)
151  {
152  left = topleft.x;
153  top = topleft.y;
154  right = left + size.cx;
155  bottom = top + size.cy;
156  }
157 
159  void Set(const POINT& topleft, const POINT& bottomright)
160  {
161  left = topleft.x;
162  top = topleft.y;
163  right = bottomright.x;
164  bottom = bottomright.y;
165  }
166 
168  bool operator==(const RECT& other) const { return EqualRect(this, &other) == TRUE; }
169 
171  Point TopLeft() const { return Point(left, top); }
172 
174  LONG Width() const { return right - left; }
176  LONG Height() const { return bottom - top; }
178  Size GetSize() const { return ::Size(Width(), Height()); }
179 
181  BOOL IsEmpty() const { return IsRectEmpty(this); }
182 
184  BOOL PtInRect(const POINT& p) const { return ::PtInRect(this, p); }
185 
187  Rect& Offset(int dx, int dy)
188  {
189  OffsetRect(this, dx, dy);
190  return *this;
191  }
192 
194  Rect& Inflate(int dx, int dy)
195  {
196  InflateRect(this, dx, dy);
197  return *this;
198  }
199 
201  BOOL Intersect(const RECT& r1, const RECT& r2)
202  {
203  return IntersectRect(this, &r1, &r2);
204  }
205 
207  Rect Intersect(const RECT& other) const
208  {
209  Rect r;
210  IntersectRect(&r, this, &other);
211  return r;
212  }
213 
215  BOOL Union(const RECT& r1, const RECT& r2)
216  {
217  return UnionRect(this, &r1, &r2);
218  }
219 
221  Rect Union(const RECT& other) const
222  {
223  Rect r;
224  UnionRect(&r, this, &other);
225  return r;
226  }
227 
229  Rect& ClientToScreen(HWND window)
230  {
231  Set(Point(left, top).ClientToScreen(window), GetSize());
232  return *this;
233  }
234 
236  Rect& ScreenToClient(HWND window)
237  {
238  Set(Point(left, top).ScreenToClient(window), GetSize());
239  return *this;
240  }
241 
243  static Rect DesktopRect()
244  {
245  return Rect(
246  GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_XVIRTUALSCREEN),
247  GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN));
248  }
249 };
250 
251 #endif