Slave104_DemoDlg.cpp
上传用户:tengfei
上传日期:2014-02-20
资源大小:423k
文件大小:5k
源码类别:

邮电通讯系统

开发平台:

Visual C++

  1. // Slave104_DemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Slave104_Demo.h"
  5. #include "Slave104real.h"
  6. #include "Slave104_DemoDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CSlave104_DemoDlg dialog
  51. CSlave104_DemoDlg::CSlave104_DemoDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CSlave104_DemoDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CSlave104_DemoDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CSlave104_DemoDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CSlave104_DemoDlg)
  64. DDX_Control(pDX, IDC_LIST1, m_list);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CSlave104_DemoDlg, CDialog)
  68. //{{AFX_MSG_MAP(CSlave104_DemoDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. ON_WM_TIMER()
  73. ON_BN_CLICKED(IDC_BUTTONstart, OnBUTTONstart)
  74. ON_BN_CLICKED(IDC_BUTTONclose, OnBUTTONclose)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CSlave104_DemoDlg message handlers
  79. BOOL CSlave104_DemoDlg::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. // Add "About..." menu item to system menu.
  83. // IDM_ABOUTBOX must be in the system command range.
  84. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  85. ASSERT(IDM_ABOUTBOX < 0xF000);
  86. CMenu* pSysMenu = GetSystemMenu(FALSE);
  87. if (pSysMenu != NULL)
  88. {
  89. CString strAboutMenu;
  90. strAboutMenu.LoadString(IDS_ABOUTBOX);
  91. if (!strAboutMenu.IsEmpty())
  92. {
  93. pSysMenu->AppendMenu(MF_SEPARATOR);
  94. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  95. }
  96. }
  97. // Set the icon for this dialog.  The framework does this automatically
  98. //  when the application's main window is not a dialog
  99. SetIcon(m_hIcon, TRUE); // Set big icon
  100. SetIcon(m_hIcon, FALSE); // Set small icon
  101. // TODO: Add extra initialization here
  102. real=0;
  103. return TRUE;  // return TRUE  unless you set the focus to a control
  104. }
  105. void CSlave104_DemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  106. {
  107. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  108. {
  109. CAboutDlg dlgAbout;
  110. dlgAbout.DoModal();
  111. }
  112. else
  113. {
  114. CDialog::OnSysCommand(nID, lParam);
  115. }
  116. }
  117. // If you add a minimize button to your dialog, you will need the code below
  118. //  to draw the icon.  For MFC applications using the document/view model,
  119. //  this is automatically done for you by the framework.
  120. void CSlave104_DemoDlg::OnPaint() 
  121. {
  122. if (IsIconic())
  123. {
  124. CPaintDC dc(this); // device context for painting
  125. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  126. // Center icon in client rectangle
  127. int cxIcon = GetSystemMetrics(SM_CXICON);
  128. int cyIcon = GetSystemMetrics(SM_CYICON);
  129. CRect rect;
  130. GetClientRect(&rect);
  131. int x = (rect.Width() - cxIcon + 1) / 2;
  132. int y = (rect.Height() - cyIcon + 1) / 2;
  133. // Draw the icon
  134. dc.DrawIcon(x, y, m_hIcon);
  135. }
  136. else
  137. {
  138. CDialog::OnPaint();
  139. }
  140. }
  141. // The system calls this to obtain the cursor to display while the user drags
  142. //  the minimized window.
  143. HCURSOR CSlave104_DemoDlg::OnQueryDragIcon()
  144. {
  145. return (HCURSOR) m_hIcon;
  146. }
  147. void CSlave104_DemoDlg::OnTimer(UINT nIDEvent) 
  148. {
  149. // TODO: Add your message handler code here and/or call default
  150. static BYTE YXval=0;
  151. static WORD YCval=0;
  152. static float YCfval=0;
  153. static WORD ITval=0;
  154. if(real)
  155. {
  156. SYSTEMTIME systime;
  157. YXval^=1;
  158. GetLocalTime(&systime);
  159. real->slave_SP_SetData(3,YXval,&systime);
  160. YCval+=7;
  161. for(int i=0;i<10;i++)
  162. real->slave_ME_NA_SetData(i,YCval);
  163. YCfval+=2.34;
  164. for( i=0;i<10;i++)
  165. real->slave_ME_NC_SetData(i,YCfval);
  166. ITval+=5;
  167. for( i=0;i<10;i++)
  168. real->slave_IT_NA_SetData(i,ITval);
  169. }
  170. CDialog::OnTimer(nIDEvent);
  171. }
  172. void CSlave104_DemoDlg::OnBUTTONstart() 
  173. {
  174. // TODO: Add your control notification handler code here
  175. if(real) return;
  176. real=new CSlave104real();
  177. real->dlg=this;
  178. real->slave_start();
  179. SetTimer(1,3000,NULL);
  180. }
  181. void CSlave104_DemoDlg::OnBUTTONclose() 
  182. {
  183. // TODO: Add your control notification handler code here
  184. if(real)
  185. {
  186. real->slave_close();
  187. delete real;
  188. real=NULL;
  189. KillTimer(1);
  190. }
  191. }