CDigitST_demoDlg.cpp
上传用户:dhjcdma
上传日期:2007-01-02
资源大小:102k
文件大小:3k
源码类别:

Static控件

开发平台:

Visual C++

  1. // CDigitST_demoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CDigitST_demo.h"
  5. #include "CDigitST_demoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCDigitST_demoDlg dialog
  13. CCDigitST_demoDlg::CCDigitST_demoDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CCDigitST_demoDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CCDigitST_demoDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  20. m_bRunning = FALSE;
  21. }
  22. void CCDigitST_demoDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CCDigitST_demoDlg)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(CCDigitST_demoDlg, CDialog)
  30. //{{AFX_MSG_MAP(CCDigitST_demoDlg)
  31. ON_BN_CLICKED(IDC_ZEROPAD, OnZeroPad)
  32. ON_BN_CLICKED(IDB_ABOUT, OnAbout)
  33. ON_WM_TIMER()
  34. ON_BN_CLICKED(IDC_RESETPARTIAL, OnResetPartial)
  35. ON_BN_CLICKED(IDC_GO, OnGo)
  36. ON_WM_DESTROY()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CCDigitST_demoDlg message handlers
  41. BOOL CCDigitST_demoDlg::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. SetIcon(m_hIcon, TRUE); // Set big icon
  45. SetIcon(m_hIcon, FALSE); // Set small icon
  46. // Create IDC_DIGIT_SPEED control
  47. m_dgtSpeed.SubclassDlgItem(IDC_DIGIT_SPEED, this);
  48. m_dgtSpeed.SetStyle(IDB_BIG1, 5);
  49. m_dgtSpeed.SetValue(0);
  50. // Create IDC_DIGIT_TOTALKM control
  51. m_dgtTotal.SubclassDlgItem(IDC_DIGIT_TOTALKM, this);
  52. m_dgtTotal.SetStyle(IDB_SMALL1, 6);
  53. m_dgtTotal.SetValue(1055);
  54. // Create IDC_DIGIT_PARTIALKM control
  55. m_dgtPartial.SubclassDlgItem(IDC_DIGIT_PARTIALKM, this);
  56. m_dgtPartial.SetStyle(IDB_SMALL2, 5);
  57. m_dgtPartial.SetValue(0);
  58. // Show zeroes
  59. m_dgtPartial.SetZeroPadding(TRUE);
  60. // Write class version
  61. CString sVersion;
  62. sVersion.Format("CDigitST v%s", CDigitST::GetVersionC());
  63. SetWindowText(sVersion);
  64. return TRUE;
  65. } // End of OnInitDialog
  66. void CCDigitST_demoDlg::OnZeroPad() 
  67. {
  68. m_dgtTotal.SetZeroPadding(!m_dgtTotal.GetZeroPadding());
  69. } // End of OnZeroPad
  70. void CCDigitST_demoDlg::OnAbout() 
  71. {
  72. CAboutDlg about;
  73. about.DoModal();
  74. } // End of OnAbout
  75. void CCDigitST_demoDlg::OnTimer(UINT nIDEvent) 
  76. {
  77. if (nIDEvent == 1)
  78. {
  79. m_dgtTotal.Inc();
  80. m_dgtPartial.Inc();
  81. }
  82. else
  83. CDialog::OnTimer(nIDEvent);
  84. } // End of OnTimer
  85. void CCDigitST_demoDlg::OnResetPartial() 
  86. {
  87. m_dgtPartial.SetValue(0);
  88. } // End of OnResetPartial
  89. void CCDigitST_demoDlg::OnGo() 
  90. {
  91. m_bRunning ^= TRUE;
  92. if (m_bRunning == TRUE)
  93. {
  94. SetTimer(1, 250, NULL);
  95. m_dgtSpeed.SetValue(90);
  96. SetDlgItemText(IDC_GO, "Stop moving!");
  97. }
  98. else
  99. {
  100. KillTimer(1);
  101. m_dgtSpeed.SetValue(0);
  102. SetDlgItemText(IDC_GO, "Go somewhere");
  103. }
  104. } // End of OnGo
  105. void CCDigitST_demoDlg::OnDestroy() 
  106. {
  107. KillTimer(1);
  108. CDialog::OnDestroy();
  109. } // End of OnDestroy