digitalcounterDlg.cpp
上传用户:cbxyz2008
上传日期:2007-01-02
资源大小:45k
文件大小:5k
源码类别:

Static控件

开发平台:

Visual C++

  1. // digitalcounterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "digitalcounter.h"
  5. #include "digitalcounterDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public cdxCSizingDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : cdxCSizingDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. cdxCSizingDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, cdxCSizingDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDigitalcounterDlg dialog
  50. CDigitalcounterDlg::CDigitalcounterDlg(CWnd* pParent /*=NULL*/)
  51. : cdxCSizingDialog(CDigitalcounterDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CDigitalcounterDlg)
  54. m_dVal = 123.45;
  55. //}}AFX_DATA_INIT
  56. m_dNew = m_dVal;
  57. m_csQuote = _T("A KIND OF MAGIC");
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void CDigitalcounterDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. cdxCSizingDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CDigitalcounterDlg)
  65. DDX_Control(pDX, IDC_QUOTE_STATIC, m_QuoteText);
  66. DDX_Control(pDX, IDC_COUNT4, m_Count4);
  67. DDX_Control(pDX, IDC_COUNT3, m_Count3);
  68. DDX_Control(pDX, IDC_COUNT2, m_Count2);
  69. DDX_Control(pDX, IDC_COUNT1, m_Count1);
  70. DDX_Control(pDX, IDC_TIME_STATIC, m_TimeStatic);
  71. DDX_Text(pDX, IDC_EDIT1, m_dVal);
  72. //}}AFX_DATA_MAP
  73. DDX_DigiDisplay(pDX, IDC_COUNT1, "A:%6.2lf", m_dNew);
  74. DDX_DigiDisplay(pDX, IDC_COUNT2, "B:%6.2lf", m_dNew);
  75. DDX_DigiDisplay(pDX, IDC_COUNT3, "C:%6.2lf", m_dNew);
  76. DDX_DigiDisplay(pDX, IDC_COUNT4, "D:%6.2lf", m_dNew);
  77. DDX_DigiDisplay(pDX, IDC_QUOTE_STATIC, m_csQuote);
  78. }
  79. BEGIN_MESSAGE_MAP(CDigitalcounterDlg, cdxCSizingDialog)
  80. //{{AFX_MSG_MAP(CDigitalcounterDlg)
  81. ON_WM_SYSCOMMAND()
  82. ON_WM_PAINT()
  83. ON_WM_QUERYDRAGICON()
  84. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  85. //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CDigitalcounterDlg message handlers
  89. BOOL CDigitalcounterDlg::OnInitDialog()
  90. {
  91. cdxCSizingDialog::OnInitDialog(0);
  92. // Add "About..." menu item to system menu.
  93. // IDM_ABOUTBOX must be in the system command range.
  94. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  95. ASSERT(IDM_ABOUTBOX < 0xF000);
  96. CMenu* pSysMenu = GetSystemMenu(FALSE);
  97. if (pSysMenu != NULL)
  98. {
  99. CString strAboutMenu;
  100. strAboutMenu.LoadString(IDS_ABOUTBOX);
  101. if (!strAboutMenu.IsEmpty())
  102. {
  103. pSysMenu->AppendMenu(MF_SEPARATOR);
  104. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  105. }
  106. }
  107. // Set the icon for this dialog.  The framework does this automatically
  108. //  when the application's main window is not a dialog
  109. SetIcon(m_hIcon, TRUE); // Set big icon
  110. SetIcon(m_hIcon, FALSE); // Set small icon
  111. // TODO: Add extra initialization here
  112. m_Count1.SetBackColor(LIGHTGRAY);
  113. m_Count1.SetColor(LIGHTGRAY, BLACK);
  114. m_Count2.SetBackColor(BLACK);
  115. m_Count2.SetColor(DARKBLUE, LIGHTBLUE);
  116. m_Count3.SetBackColor(DARKGREEN);
  117. m_Count3.SetColor(BLACK, YELLOW);
  118. m_Count4.SetBackColor(BLACK);
  119. m_Count4.SetColor(BLACK, WHITE);
  120. m_QuoteText.SetBackColor(BLACK);
  121. m_QuoteText.SetColor(DARKCYAN, LIGHTCYAN);
  122. AddSzControl(m_TimeStatic, mdResize, mdResize); 
  123. return TRUE;  // return TRUE  unless you set the focus to a control
  124. }
  125. void CDigitalcounterDlg::OnSysCommand(UINT nID, LPARAM lParam)
  126. {
  127. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  128. {
  129. CAboutDlg dlgAbout;
  130. dlgAbout.DoModal();
  131. }
  132. else
  133. {
  134. cdxCSizingDialog::OnSysCommand(nID, lParam);
  135. }
  136. }
  137. // If you add a minimize button to your dialog, you will need the code below
  138. //  to draw the icon.  For MFC applications using the document/view model,
  139. //  this is automatically done for you by the framework.
  140. void CDigitalcounterDlg::OnPaint() 
  141. {
  142. if (IsIconic())
  143. {
  144. CPaintDC dc(this); // device context for painting
  145. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  146. // Center icon in client rectangle
  147. int cxIcon = GetSystemMetrics(SM_CXICON);
  148. int cyIcon = GetSystemMetrics(SM_CYICON);
  149. CRect rect;
  150. GetClientRect(&rect);
  151. int x = (rect.Width() - cxIcon + 1) / 2;
  152. int y = (rect.Height() - cyIcon + 1) / 2;
  153. // Draw the icon
  154. dc.DrawIcon(x, y, m_hIcon);
  155. }
  156. else
  157. {
  158. cdxCSizingDialog::OnPaint();
  159. }
  160. }
  161. // The system calls this to obtain the cursor to display while the user drags
  162. //  the minimized window.
  163. HCURSOR CDigitalcounterDlg::OnQueryDragIcon()
  164. {
  165. return (HCURSOR) m_hIcon;
  166. }
  167. void CDigitalcounterDlg::OnButton1() 
  168. {
  169. // TODO: Add your control notification handler code here
  170. UpdateData(TRUE);
  171. m_dNew = m_dVal;
  172. UpdateData(FALSE);
  173. }