SLIDCTRL.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:8k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // SlidCtrl.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "CmnCtrl2.h"
  14. #include "SlidCtrl.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CSliderCtrlPage property page
  21. IMPLEMENT_DYNCREATE(CSliderCtrlPage, CPropertyPage)
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #endif
  25. CSliderCtrlPage::CSliderCtrlPage() : CPropertyPage(CSliderCtrlPage::IDD)
  26. {
  27. //{{AFX_DATA_INIT(CSliderCtrlPage)
  28. m_bAutoticks = TRUE;
  29. m_bEnablesel = FALSE;
  30. m_bFixed = FALSE;
  31. m_uiLine = 10;
  32. m_bNothumb = FALSE;
  33. m_bNoticks = FALSE;
  34. m_iOrientation = 0;
  35. m_uiPage = 50;
  36. m_iTickpos = 0;
  37. m_uiRangeFrom = 0;
  38. m_uiRangeTo = 100;
  39. m_uiSelRangeFrom = 20;
  40. m_uiSelRangeTo = 80;
  41. m_uiTickFreq = 20;
  42. //}}AFX_DATA_INIT
  43. m_psp.dwFlags &= ~PSP_HASHELP;  // Lose the Help button
  44. }
  45. CSliderCtrlPage::~CSliderCtrlPage()
  46. {
  47. }
  48. void CSliderCtrlPage::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CPropertyPage::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CSliderCtrlPage)
  52. DDX_Control(pDX, IDC_NOTIFICATIONS, m_Notifications);
  53. DDX_Check(pDX, IDC_SLIDER_AUTOTICKS, m_bAutoticks);
  54. DDX_Check(pDX, IDC_SLIDER_ENABLESEL, m_bEnablesel);
  55. DDX_Check(pDX, IDC_SLIDER_FIXED, m_bFixed);
  56. DDX_Text(pDX, IDC_SLIDER_LINE, m_uiLine);
  57. DDV_MinMaxUInt(pDX, m_uiLine, 0, 65535);
  58. DDX_Check(pDX, IDC_SLIDER_NOTHUMB, m_bNothumb);
  59. DDX_Check(pDX, IDC_SLIDER_NOTICKS, m_bNoticks);
  60. DDX_CBIndex(pDX, IDC_SLIDER_ORIENTATION, m_iOrientation);
  61. DDX_Text(pDX, IDC_SLIDER_PAGE, m_uiPage);
  62. DDV_MinMaxUInt(pDX, m_uiPage, 0, 65535);
  63. DDX_CBIndex(pDX, IDC_SLIDER_POINT, m_iTickpos);
  64. DDX_Text(pDX, IDC_SLIDER_RANGEFROM, m_uiRangeFrom);
  65. DDV_MinMaxUInt(pDX, m_uiRangeFrom, 0, 65535);
  66. DDX_Text(pDX, IDC_SLIDER_RANGETO, m_uiRangeTo);
  67. DDV_MinMaxUInt(pDX, m_uiRangeTo, 0, 65535);
  68. DDX_Text(pDX, IDC_SLIDER_SELRANGEFROM, m_uiSelRangeFrom);
  69. DDV_MinMaxUInt(pDX, m_uiSelRangeFrom, 0, 65535);
  70. DDX_Text(pDX, IDC_SLIDER_SELRANGETO, m_uiSelRangeTo);
  71. DDV_MinMaxUInt(pDX, m_uiSelRangeTo, 0, 65535);
  72. DDX_Text(pDX, IDC_SLIDER_TICKFREQ, m_uiTickFreq);
  73. DDV_MinMaxUInt(pDX, m_uiTickFreq, 0, 65535);
  74. //}}AFX_DATA_MAP
  75. }
  76. BOOL CSliderCtrlPage::OnInitDialog()
  77. {
  78. CPropertyPage::OnInitDialog();
  79. // Initially create slider control in horizontal position
  80. CWnd* pWnd =
  81. GetDlgItem( IDC_SLIDER_HORZPOS );
  82. CRect rect;
  83. pWnd->GetWindowRect( &rect );
  84. ScreenToClient( &rect );
  85. // Initialise controls
  86. m_Slider.Create( WS_VISIBLE|WS_CHILD|TBS_HORZ|TBS_BOTH|TBS_AUTOTICKS,
  87.  rect, this, IDC_SLIDER );
  88. m_Slider.SetTicFreq( m_uiTickFreq );    // Send TBM_SETTICFREQ
  89. m_Slider.SetLineSize( m_uiLine );       // Send TBM_SETLINESIZE
  90. m_Slider.SetPageSize( m_uiPage );       // Send TBM_SETPAGESIZE
  91. m_Slider.SetRange( m_uiRangeFrom, m_uiRangeTo, TRUE );
  92. // Send TBM_SETRANGE
  93. return TRUE;
  94. }
  95. void CSliderCtrlPage::ChangeCtrlStyle( long lStyle, BOOL bSetBit)
  96. {
  97. long    lStyleOld;
  98. CRect   rect;
  99. lStyleOld = GetWindowLong( m_Slider.GetSafeHwnd(), GWL_STYLE );
  100. if ( bSetBit )
  101. lStyleOld |= lStyle;
  102. else
  103. lStyleOld &= ~lStyle;
  104. SetWindowLong( m_Slider.GetSafeHwnd(), GWL_STYLE, lStyleOld );
  105. m_Slider.GetWindowRect(&rect);
  106. m_Slider.InvalidateRect(&rect);
  107. }
  108. BEGIN_MESSAGE_MAP(CSliderCtrlPage, CPropertyPage)
  109. //{{AFX_MSG_MAP(CSliderCtrlPage)
  110. ON_BN_CLICKED(IDC_SLIDER_AUTOTICKS, OnAutoticks)
  111. ON_EN_KILLFOCUS(IDC_SLIDER_TICKFREQ, OnTickfreq)
  112. ON_BN_CLICKED(IDC_SLIDER_NOTICKS, OnNoticks)
  113. ON_BN_CLICKED(IDC_SLIDER_NOTHUMB, OnNothumb)
  114. ON_BN_CLICKED(IDC_SLIDER_FIXED, OnFixed)
  115. ON_BN_CLICKED(IDC_SLIDER_ENABLESEL, OnEnablesel)
  116. ON_EN_KILLFOCUS(IDC_SLIDER_LINE, OnLine)
  117. ON_EN_KILLFOCUS(IDC_SLIDER_PAGE, OnPage)
  118. ON_EN_KILLFOCUS(IDC_SLIDER_RANGEFROM, OnRangefrom)
  119. ON_EN_KILLFOCUS(IDC_SLIDER_RANGETO, OnRangeto)
  120. ON_CBN_SELCHANGE(IDC_SLIDER_ORIENTATION, OnOrientation)
  121. ON_CBN_SELCHANGE(IDC_SLIDER_POINT, OnPoint)
  122. ON_EN_KILLFOCUS(IDC_SLIDER_SELRANGEFROM, OnSelrangefrom)
  123. ON_EN_KILLFOCUS(IDC_SLIDER_SELRANGETO, OnSelrangeto)
  124. //  ON_WM_HSCROLL()
  125. //}}AFX_MSG_MAP
  126. END_MESSAGE_MAP()
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CSliderCtrlPage message handlers
  129. void CSliderCtrlPage::OnAutoticks()
  130. {
  131. UpdateData();
  132. // Shows tick marks according to increment/frequency when set (default frequency is 1)
  133. ChangeCtrlStyle( TBS_AUTOTICKS, m_bAutoticks );
  134. // Enable/disable edit controls
  135. GetDlgItem( IDC_SLIDER_TICKFREQ )->EnableWindow( m_bAutoticks );
  136. if ( m_bAutoticks )
  137. // Set tick marks with given frequency (1 = tick at every increment)
  138. m_Slider.SetTicFreq( m_uiTickFreq );    // Send TBM_SETTICFREQ - need TBS_AUTOTICKS
  139. else
  140. // Clear tick marks
  141. m_Slider.ClearTics( TRUE );
  142. }
  143. void CSliderCtrlPage::OnTickfreq()
  144. {
  145. UpdateData();
  146. if ( m_bAutoticks )
  147. // Set tick marks at given frequency (1 = tick at every increment)
  148. m_Slider.SetTicFreq( m_uiTickFreq );    // Send TBM_SETTICFREQ - need TBS_AUTOTICKS
  149. }
  150. void CSliderCtrlPage::OnNoticks()
  151. {
  152. UpdateData();
  153. // Removes tick marks when set
  154. ChangeCtrlStyle( TBS_NOTICKS, m_bNoticks );
  155. }
  156. void CSliderCtrlPage::OnNothumb()
  157. {
  158. UpdateData();
  159. // Removes thumb from slider control when set
  160. ChangeCtrlStyle( TBS_NOTHUMB, m_bNothumb );
  161. }
  162. void CSliderCtrlPage::OnFixed()
  163. {
  164. UpdateData();
  165. // Fixes length of slider thumb when set (
  166. ChangeCtrlStyle( TBS_FIXEDLENGTH, m_bFixed );
  167. }
  168. void CSliderCtrlPage::OnEnablesel()
  169. {
  170. UpdateData();
  171. ChangeCtrlStyle( TBS_ENABLESELRANGE, m_bEnablesel );
  172. // Enable/disable edit controls
  173. GetDlgItem( IDC_SLIDER_SELRANGEFROM )->EnableWindow( m_bEnablesel );
  174. GetDlgItem( IDC_SLIDER_SELRANGETO )->EnableWindow( m_bEnablesel );
  175. if ( m_bEnablesel )
  176. // Set selection range
  177. m_Slider.SetSelection( m_uiSelRangeFrom, m_uiSelRangeTo );  // Send TBM_SETSEL
  178. else
  179. // Clear selection range
  180. m_Slider.ClearSel( TRUE );
  181. }
  182. void CSliderCtrlPage::OnLine()
  183. {
  184. UpdateData();
  185. // Set line size (determines effect of arrow keys)
  186. m_Slider.SetLineSize( m_uiLine );       // Send TBM_SETLINESIZE
  187. }
  188. void CSliderCtrlPage::OnPage()
  189. {
  190. UpdateData();
  191. // Set page size (determines effect of PageUp/PageDown keys)
  192. m_Slider.SetPageSize( m_uiPage );       // Send TBM_SETPAGESIZE
  193. }
  194. void CSliderCtrlPage::OnRangefrom()
  195. {
  196. UpdateData();
  197. // Set range of slider control
  198. m_Slider.SetRangeMin( m_uiRangeFrom, TRUE );    // Send TBM_SETRANGE
  199. }
  200. void CSliderCtrlPage::OnRangeto()
  201. {
  202. UpdateData();
  203. // Set range of slider control
  204. m_Slider.SetRangeMax( m_uiRangeTo, TRUE );  // Send TBM_SETRANGE
  205. }
  206. void CSliderCtrlPage::OnOrientation()
  207. {
  208. UpdateData();
  209. // Obtain horz/vert place marker (static control)
  210. CWnd* pWnd =
  211. GetDlgItem( (0==m_iOrientation)?IDC_SLIDER_HORZPOS:IDC_SLIDER_VERTPOS );
  212. CRect rect;
  213. pWnd->GetWindowRect( &rect );
  214. ScreenToClient( &rect );
  215. // Set slider control style
  216. ChangeCtrlStyle( TBS_HORZ, (0 == m_iOrientation) );
  217. ChangeCtrlStyle( TBS_VERT, (1 == m_iOrientation) );
  218. // Move control to horz/vert position
  219. m_Slider.SetWindowPos( NULL,
  220.    rect.left, rect.top,
  221.    rect.Width(), rect.Height(),
  222.    SWP_NOZORDER|SWP_SHOWWINDOW );
  223. Invalidate();
  224. }
  225. void CSliderCtrlPage::OnPoint()
  226. {
  227. UpdateData();
  228. switch ( m_iTickpos )
  229. {
  230. case 0:
  231. ChangeCtrlStyle( TBS_BOTH );
  232. break;
  233. case 1:
  234. ChangeCtrlStyle( TBS_TOP );     // Same as TBS_LEFT
  235. ChangeCtrlStyle( TBS_BOTH, FALSE );
  236. ChangeCtrlStyle( TBS_BOTTOM, FALSE );
  237. break;
  238. case 2:
  239. ChangeCtrlStyle( TBS_BOTTOM );  // Same as TBS_RIGHT
  240. ChangeCtrlStyle( TBS_BOTH, FALSE );
  241. ChangeCtrlStyle( TBS_TOP, FALSE );
  242. break;
  243. default:
  244. break;
  245. }
  246. }
  247. void CSliderCtrlPage::OnSelrangefrom()
  248. {
  249. UpdateData();
  250. m_Slider.ClearSel();
  251. m_Slider.SetSelection( m_uiSelRangeFrom, m_uiSelRangeTo );  // Send TBM_SETSEL
  252. }
  253. void CSliderCtrlPage::OnSelrangeto()
  254. {
  255. UpdateData();
  256. m_Slider.ClearSel();
  257. m_Slider.SetSelection( m_uiSelRangeFrom, m_uiSelRangeTo );  // Send TBM_SETSEL
  258. }