SliderWindow.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #ifndef __SliderWindow_h__
  2. #define __SliderWindow_h__
  3. /////////////////////////////////////////////////////////////////////////////
  4. // SliderWindow.h | Declaration of the TCSliderWindow class.
  5. #include <TCLib.h>
  6. /////////////////////////////////////////////////////////////////////////////
  7. // TCSliderWindow
  8. class TCSliderWindow : public CWindowImpl<TCSliderWindow>
  9. {
  10. // Declarations
  11. public:
  12. DECLARE_WND_SUPERCLASS(NULL, TRACKBAR_CLASS)
  13. // Message Map
  14. public:
  15. BEGIN_MSG_MAP(TCSliderWindow)
  16. END_MSG_MAP()
  17. // Construction
  18. public:
  19. TCSliderWindow();
  20. // Attributes / Operations
  21. public:
  22. BOOL SubclassWindow(HWND hWnd);
  23. int GetPos() const;
  24. void GetRange(int& nMin, int& nMax) const;
  25. int GetRangeMin() const;
  26. int GetRangeMax() const;
  27. int GetTic(int nTic) const;
  28. bool SetTic(int nTic);
  29. void SetPos(int nPos);
  30. void SetRange(int nMin, int nMax, bool bRedraw = false);
  31. void SetRangeMin(int nMin, bool bRedraw = false);
  32. void SetRangeMax(int nMax, bool bRedraw = false);
  33. void ClearTics(bool bRedraw = false);
  34. void SetSelection(int nStart, int nEnd, bool bRedraw = true);
  35. void SetSel(int nStart, int nEnd, bool bRedraw = true);
  36. void SetSelStart(int nStart, bool bRedraw = false);
  37. void SetSelEnd(int nEnd, bool bRedraw = false);
  38. DWORD* GetTicArray() const;
  39. int GetTicPos(int nTic) const;
  40. UINT GetNumTics() const;
  41. void GetSelection(int& nStart, int& nEnd) const;
  42. void GetSel(int& nStart, int& nEnd) const;
  43. int GetSelStart() const;
  44. int GetSelEnd() const;
  45. void ClearSel(bool bRedraw = false);
  46. void SetTicFreq(int nFreq);
  47. int SetPageSize(int nSize);
  48. int GetPageSize() const;
  49. int SetLineSize(int nSize);
  50. int GetLineSize() const;
  51. void GetThumbRect(LPRECT lprc) const;
  52. void GetChannelRect(LPRECT lprc) const;
  53. void SetThumbLength(int nLength);
  54. int GetThumbLength() const;
  55. void SetToolTips(HWND hwndTT);
  56. HWND GetToolTips() const;
  57. int SetTipSide(int fLocation);
  58. HWND SetBuddy(bool bAboveOrLeft, HWND hwndBuddy);
  59. HWND GetBuddy(bool bAboveOrLeft) const;
  60. // Operators
  61. public:
  62. const TCSliderWindow& operator=(HWND hwnd);
  63. };
  64. /////////////////////////////////////////////////////////////////////////////
  65. // Construction
  66. inline TCSliderWindow::TCSliderWindow()
  67. {
  68. // Initialize the slider common control
  69. INITCOMMONCONTROLSEX icce = {sizeof(icce), ICC_BAR_CLASSES};
  70. _VERIFYE(TCCommonControls().InitEx(&icce));
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // Attributes / Operations
  74. inline BOOL TCSliderWindow::SubclassWindow(HWND hWnd)
  75. {
  76. // Perform default processing
  77. if (!CWindowImpl<TCSliderWindow>::SubclassWindow(hWnd))
  78. return FALSE;
  79. // Fix the slider thumb size
  80. FixSliderThumbSize(hWnd);
  81. // Indicate success
  82. return TRUE;
  83. }
  84. inline int TCSliderWindow::GetPos() const
  85. {
  86. assert(::IsWindow(m_hWnd));
  87. return (int) ::SendMessage(m_hWnd, TBM_GETPOS, 0, 0l);
  88. }
  89. inline void TCSliderWindow::GetRange(int& nMin, int& nMax) const
  90. {
  91. nMin = GetRangeMin();
  92. nMax = GetRangeMax();
  93. }
  94. inline int TCSliderWindow::GetRangeMin() const
  95. {
  96. assert(::IsWindow(m_hWnd));
  97. return (int) ::SendMessage(m_hWnd, TBM_GETRANGEMIN, 0, 0l);
  98. }
  99. inline int TCSliderWindow::GetRangeMax() const
  100. {
  101. assert(::IsWindow(m_hWnd));
  102. return (int) ::SendMessage(m_hWnd, TBM_GETRANGEMAX, 0, 0l);
  103. }
  104. inline int TCSliderWindow::GetTic(int nTic) const
  105. {
  106. assert(::IsWindow(m_hWnd));
  107. return (int) ::SendMessage(m_hWnd, TBM_GETTIC, nTic, 0L);
  108. }
  109. inline bool TCSliderWindow::SetTic(int nTic)
  110. {
  111. assert(::IsWindow(m_hWnd));
  112. return !!::SendMessage(m_hWnd, TBM_SETTIC, 0, nTic);
  113. }
  114. inline void TCSliderWindow::SetPos(int nPos)
  115. {
  116. assert(::IsWindow(m_hWnd));
  117. ::SendMessage(m_hWnd, TBM_SETPOS, TRUE, nPos);
  118. }
  119. inline void TCSliderWindow::SetRange(int nMin, int nMax, bool bRedraw)
  120. {
  121. SetRangeMin(nMin, false);
  122. SetRangeMax(nMax, bRedraw);
  123. }
  124. inline void TCSliderWindow::SetRangeMin(int nMin, bool bRedraw)
  125. {
  126. assert(::IsWindow(m_hWnd));
  127. ::SendMessage(m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
  128. }
  129. inline void TCSliderWindow::SetRangeMax(int nMax, bool bRedraw)
  130. {
  131. assert(::IsWindow(m_hWnd));
  132. ::SendMessage(m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
  133. }
  134. inline void TCSliderWindow::ClearTics(bool bRedraw)
  135. {
  136. assert(::IsWindow(m_hWnd));
  137. ::SendMessage(m_hWnd, TBM_CLEARTICS, bRedraw, 0l);
  138. }
  139. inline void TCSliderWindow::SetSelection(int nStart, int nEnd, bool bRedraw)
  140. {
  141. SetSel(nStart, nEnd);
  142. }
  143. inline void TCSliderWindow::SetSel(int nStart, int nEnd, bool bRedraw)
  144. {
  145. assert(::IsWindow(m_hWnd));
  146. SetSelStart(nStart, false);
  147. SetSelEnd(nEnd, bRedraw);
  148. }
  149. inline void TCSliderWindow::SetSelStart(int nStart, bool bRedraw)
  150. {
  151. assert(::IsWindow(m_hWnd));
  152. ::SendMessage(m_hWnd, TBM_SETSELSTART, (WPARAM)bRedraw, nStart);
  153. }
  154. inline void TCSliderWindow::SetSelEnd(int nEnd, bool bRedraw)
  155. {
  156. assert(::IsWindow(m_hWnd));
  157. ::SendMessage(m_hWnd, TBM_SETSELEND, (WPARAM)bRedraw, nEnd);
  158. }
  159. inline DWORD* TCSliderWindow::GetTicArray() const
  160. {
  161. assert(::IsWindow(m_hWnd));
  162. return (DWORD*) ::SendMessage(m_hWnd, TBM_GETPTICS, 0, 0l);
  163. }
  164. inline int TCSliderWindow::GetTicPos(int nTic) const
  165. {
  166. assert(::IsWindow(m_hWnd));
  167. return (int) ::SendMessage(m_hWnd, TBM_GETTICPOS, nTic, 0L);
  168. }
  169. inline UINT TCSliderWindow::GetNumTics() const
  170. {
  171. assert(::IsWindow(m_hWnd));
  172. return (UINT) ::SendMessage(m_hWnd, TBM_GETNUMTICS, 0, 0l);
  173. }
  174. inline void TCSliderWindow::GetSelection(int& nStart, int& nEnd) const
  175. {
  176. GetSel(nStart, nEnd);
  177. }
  178. inline void TCSliderWindow::GetSel(int& nStart, int& nEnd) const
  179. {
  180. assert(::IsWindow(m_hWnd));
  181. nStart = GetSelStart();
  182. nEnd = GetSelEnd();
  183. }
  184. inline int TCSliderWindow::GetSelStart() const
  185. {
  186. assert(::IsWindow(m_hWnd));
  187. return (int) ::SendMessage(m_hWnd, TBM_GETSELSTART, 0, 0);
  188. }
  189. inline int TCSliderWindow::GetSelEnd() const
  190. {
  191. assert(::IsWindow(m_hWnd));
  192. return (int) ::SendMessage(m_hWnd, TBM_GETSELEND, 0, 0);
  193. }
  194. inline void TCSliderWindow::ClearSel(bool bRedraw)
  195. {
  196. assert(::IsWindow(m_hWnd));
  197. ::SendMessage(m_hWnd, TBM_CLEARSEL, bRedraw, 0l);
  198. }
  199. inline void TCSliderWindow::SetTicFreq(int nFreq)
  200. {
  201. assert(::IsWindow(m_hWnd));
  202. ::SendMessage(m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
  203. }
  204. inline int TCSliderWindow::SetPageSize(int nSize)
  205. {
  206. assert(::IsWindow(m_hWnd));
  207. return (int) ::SendMessage(m_hWnd, TBM_SETPAGESIZE, 0, nSize);
  208. }
  209. inline int TCSliderWindow::GetPageSize() const
  210. {
  211. assert(::IsWindow(m_hWnd));
  212. return (int) ::SendMessage(m_hWnd, TBM_GETPAGESIZE, 0, 0l);
  213. }
  214. inline int TCSliderWindow::SetLineSize(int nSize)
  215. {
  216. assert(::IsWindow(m_hWnd));
  217. return (int) ::SendMessage(m_hWnd, TBM_SETLINESIZE, 0, nSize);
  218. }
  219. inline int TCSliderWindow::GetLineSize() const
  220. {
  221. assert(::IsWindow(m_hWnd));
  222. return (int) ::SendMessage(m_hWnd, TBM_GETLINESIZE, 0, 0l);
  223. }
  224. inline void TCSliderWindow::GetThumbRect(LPRECT lprc) const
  225. {
  226. assert(::IsWindow(m_hWnd));
  227. ::SendMessage(m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
  228. }
  229. inline void TCSliderWindow::GetChannelRect(LPRECT lprc) const
  230. {
  231. assert(::IsWindow(m_hWnd));
  232. ::SendMessage(m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
  233. }
  234. inline void TCSliderWindow::SetThumbLength(int nLength)
  235. {
  236. assert(::IsWindow(m_hWnd));
  237. ::SendMessage(m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0);
  238. }
  239. inline int TCSliderWindow::GetThumbLength() const
  240. {
  241. assert(::IsWindow(m_hWnd));
  242. return (int) ::SendMessage(m_hWnd, TBM_GETTHUMBLENGTH, 0, 0);
  243. }
  244. inline void TCSliderWindow::SetToolTips(HWND hwndTT)
  245. {
  246. assert(::IsWindow(m_hWnd));
  247. ::SendMessage(m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hwndTT, 0);
  248. }
  249. inline HWND TCSliderWindow::GetToolTips() const
  250. {
  251. assert(::IsWindow(m_hWnd));
  252. return (HWND) ::SendMessage(m_hWnd, TBM_GETTOOLTIPS, 0, 0);
  253. }
  254. inline int TCSliderWindow::SetTipSide(int fLocation)
  255. {
  256. assert(::IsWindow(m_hWnd));
  257. return (int) ::SendMessage(m_hWnd, TBM_SETTIPSIDE, fLocation, 0);
  258. }
  259. inline HWND TCSliderWindow::SetBuddy(bool bAboveOrLeft, HWND hwndBuddy)
  260. {
  261. assert(::IsWindow(m_hWnd));
  262. return (HWND) ::SendMessage(m_hWnd, TBM_SETBUDDY, (WPARAM)bAboveOrLeft,
  263. LPARAM(hwndBuddy));
  264. }
  265. inline HWND TCSliderWindow::GetBuddy(bool bAboveOrLeft) const
  266. {
  267. assert(::IsWindow(m_hWnd));
  268. return (HWND) ::SendMessage(m_hWnd, TBM_GETBUDDY, (WPARAM)bAboveOrLeft, 0);
  269. }
  270. /////////////////////////////////////////////////////////////////////////////
  271. // Operators
  272. inline const TCSliderWindow& TCSliderWindow::operator=(HWND hwnd)
  273. {
  274. SubclassWindow(hwnd);
  275. return *this;
  276. }
  277. /////////////////////////////////////////////////////////////////////////////
  278. #endif // !__SliderWindow_h__