WinapiExtension
 All Classes Files Functions Variables Typedefs Pages
IWindow.h
1 #ifndef WINAPI_EX_WINDOWBASE_H
2 #define WINAPI_EX_WINDOWBASE_H
3 
9 class IWindow
10 {
11 public:
12  virtual ~IWindow() {}
13 
18  virtual HWND _InternalGetHandle() = 0;
19 
23  void Destroy() { DestroyWindow(_InternalGetHandle()); }
24 
29  {
30  HWND handle = _InternalGetHandle();
31 
32  int length = GetWindowTextLength(handle) + 1;
33 
34  std::vector<TCHAR> buffer;
35  buffer.resize(length);
36  GetWindowText(handle, &buffer[0], length);
37  return &buffer[0];
38  }
42  void SetText(const tstring& text) { SetWindowText(_InternalGetHandle(), text.c_str()); }
43 
45  BOOL IsEnabled() { return IsWindowEnabled(_InternalGetHandle()); }
47  void Enable(BOOL enable) { EnableWindow(_InternalGetHandle(), enable); }
48 
50  BOOL IsVisible() { return IsWindowVisible(_InternalGetHandle()); }
52  BOOL Show(int cmdShow) { return ShowWindow(_InternalGetHandle(), cmdShow); }
53 
57  void SetRedraw(BOOL allowRedraw) { SendMessage(_InternalGetHandle(), WM_SETREDRAW, allowRedraw, 0); }
58 
60  HFONT GetFont() { return (HFONT)SendMessage(_InternalGetHandle(), WM_GETFONT, 0, 0); }
62  void SetFont(HFONT font, BOOL redraw = TRUE) { SendMessage(_InternalGetHandle(), WM_SETFONT, (WPARAM)font, redraw); }
63 
67  HICON GetIcon(BOOL bigIcon) { return (HICON)SendMessage(_InternalGetHandle(), WM_GETICON, bigIcon ? ICON_BIG : ICON_SMALL, 0); }
73  HICON SetIcon(HICON icon, BOOL bigIcon) { return (HICON)SendMessage(_InternalGetHandle(), WM_GETICON, bigIcon ? ICON_BIG : ICON_SMALL, (LPARAM)icon); }
74 
78  DWORD GetStyle() { return GetWindowLong(_InternalGetHandle(), GWL_STYLE); }
82  DWORD GetExStyle() { return GetWindowLong(_InternalGetHandle(), GWL_EXSTYLE); }
83 
87  DWORD GetID() { return GetWindowLong(_InternalGetHandle(), GWL_ID); }
88 
92  HWND ParentHandle() { return (HWND)GetWindowLongPtr(_InternalGetHandle(), GWLP_HWNDPARENT); }
93 
97  UINT_PTR SetTimer(UINT_PTR timerID, UINT interval, TIMERPROC proc = NULL) { return ::SetTimer(_InternalGetHandle(), timerID, interval, proc); }
101  void KillTimer(UINT_PTR timerID) { ::KillTimer(_InternalGetHandle(), timerID); }
102 
108  {
109  Rect r;
110  GetClientRect(_InternalGetHandle(), &r);
111  return r;
112  }
113 
119  {
120  Rect r;
121  GetWindowRect(_InternalGetHandle(), &r);
122  return r;
123  }
124 
130  {
131  HWND handle = _InternalGetHandle();
132 
133  Rect r;
134  GetWindowRect(handle, &r);
135 
136  // convert to window coordinates to parent coordinates
137  return r.ScreenToClient(ParentHandle());
138  }
139 
141  void Move(int x, int y, BOOL redraw = TRUE)
142  {
143  Rect r;
144  GetWindowRect(_InternalGetHandle(), &r);
145  Move(x, y, r.Width(), r.Height(), redraw);
146  }
148  void Move(const POINT& p, BOOL redraw = TRUE) { Move(p.x, p.y, redraw); }
150  void Move(int x, int y, int width, int height, BOOL redraw = TRUE) { MoveWindow(_InternalGetHandle(), x, y, width, height, redraw); }
152  void Move(const POINT& p, const SIZE& s, BOOL redraw = TRUE) { Move(p.x, p.y, s.cx, s.cy, redraw); }
154  void Move(const RECT& r, BOOL redraw = TRUE) { Move(r.left, r.top, r.right - r.left, r.bottom - r.top, redraw); }
155 
157  BOOL Invalidate(const RECT* rect = NULL, BOOL eraseBkgnd = TRUE) { return InvalidateRect(_InternalGetHandle(), rect, eraseBkgnd); }
159  BOOL Redraw(const RECT* rect = NULL, HRGN region = NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE) { return RedrawWindow(_InternalGetHandle(), rect, region, flags); }
160 
164  HWND SetFocus() { return ::SetFocus(_InternalGetHandle()); }
165 
170  void ModifyStyle(DWORD add, DWORD remove)
171  {
172  DWORD style = (GetStyle() | add) & ~remove;
173  SetWindowLong(_InternalGetHandle(), GWL_STYLE, style);
174  }
175 
177  void DragAcceptFiles(BOOL accept = TRUE) { ::DragAcceptFiles(_InternalGetHandle(), accept); }
178 };
179 
180 #endif