DynaArrayDlg.cpp
上传用户:dyt128
上传日期:2022-06-23
资源大小:1845k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // DynaArrayDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DynaArray.h"
  5. #include "DynaArrayDlg.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 CDialog
  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() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CDynaArrayDlg dialog
  50. CDynaArrayDlg::CDynaArrayDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CDynaArrayDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CDynaArrayDlg)
  54. m_index = 0;
  55. m_num1 = 0;
  56. m_num2 = 0;
  57. m_num3 = 0;
  58. m_num4 = 0;
  59. m_showindex = 0;
  60. m_shownum1 = 0;
  61. m_shownum2 = 0;
  62. m_shownum3 = 0;
  63. m_shownum4 = 0;
  64. //}}AFX_DATA_INIT
  65. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  66. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  67. }
  68. void CDynaArrayDlg::DoDataExchange(CDataExchange* pDX)
  69. {
  70. CDialog::DoDataExchange(pDX);
  71. //{{AFX_DATA_MAP(CDynaArrayDlg)
  72. DDX_Text(pDX, IDC_INDEX, m_index);
  73. DDX_Text(pDX, IDC_NUM1, m_num1);
  74. DDX_Text(pDX, IDC_NUM2, m_num2);
  75. DDX_Text(pDX, IDC_NUM3, m_num3);
  76. DDX_Text(pDX, IDC_NUM4, m_num4);
  77. DDX_Text(pDX, IDC_SHOWINDEX, m_showindex);
  78. DDX_Text(pDX, IDC_SHOWNUM1, m_shownum1);
  79. DDX_Text(pDX, IDC_SHOWNUM2, m_shownum2);
  80. DDX_Text(pDX, IDC_SHOWNUM3, m_shownum3);
  81. DDX_Text(pDX, IDC_SHOWNUM4, m_shownum4);
  82. //}}AFX_DATA_MAP
  83. }
  84. BEGIN_MESSAGE_MAP(CDynaArrayDlg, CDialog)
  85. //{{AFX_MSG_MAP(CDynaArrayDlg)
  86. ON_WM_SYSCOMMAND()
  87. ON_WM_PAINT()
  88. ON_WM_QUERYDRAGICON()
  89. ON_BN_CLICKED(IDC_ADD, OnAdd)
  90. ON_BN_CLICKED(IDC_DELATE, OnDelate)
  91. ON_BN_CLICKED(IDC_SHOW, OnShow)
  92. ON_BN_CLICKED(IDC_EDIT, OnEdit)
  93. //}}AFX_MSG_MAP
  94. END_MESSAGE_MAP()
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CDynaArrayDlg message handlers
  97. BOOL CDynaArrayDlg::OnInitDialog()
  98. {
  99. CDialog::OnInitDialog();
  100. // Add "About..." menu item to system menu.
  101. // IDM_ABOUTBOX must be in the system command range.
  102. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  103. ASSERT(IDM_ABOUTBOX < 0xF000);
  104. CMenu* pSysMenu = GetSystemMenu(FALSE);
  105. if (pSysMenu != NULL)
  106. {
  107. CString strAboutMenu;
  108. strAboutMenu.LoadString(IDS_ABOUTBOX);
  109. if (!strAboutMenu.IsEmpty())
  110. {
  111. pSysMenu->AppendMenu(MF_SEPARATOR);
  112. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  113. }
  114. }
  115. // Set the icon for this dialog.  The framework does this automatically
  116. //  when the application's main window is not a dialog
  117. SetIcon(m_hIcon, TRUE); // Set big icon
  118. SetIcon(m_hIcon, FALSE); // Set small icon
  119. // TODO: Add extra initialization here
  120. return TRUE;  // return TRUE  unless you set the focus to a control
  121. }
  122. void CDynaArrayDlg::OnSysCommand(UINT nID, LPARAM lParam)
  123. {
  124. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  125. {
  126. CAboutDlg dlgAbout;
  127. dlgAbout.DoModal();
  128. }
  129. else
  130. {
  131. CDialog::OnSysCommand(nID, lParam);
  132. }
  133. }
  134. // If you add a minimize button to your dialog, you will need the code below
  135. //  to draw the icon.  For MFC applications using the document/view model,
  136. //  this is automatically done for you by the framework.
  137. void CDynaArrayDlg::OnPaint() 
  138. {
  139. if (IsIconic())
  140. {
  141. CPaintDC dc(this); // device context for painting
  142. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  143. // Center icon in client rectangle
  144. int cxIcon = GetSystemMetrics(SM_CXICON);
  145. int cyIcon = GetSystemMetrics(SM_CYICON);
  146. CRect rect;
  147. GetClientRect(&rect);
  148. int x = (rect.Width() - cxIcon + 1) / 2;
  149. int y = (rect.Height() - cyIcon + 1) / 2;
  150. // Draw the icon
  151. dc.DrawIcon(x, y, m_hIcon);
  152. }
  153. else
  154. {
  155. CDialog::OnPaint();
  156. }
  157. }
  158. // The system calls this to obtain the cursor to display while the user drags
  159. //  the minimized window.
  160. HCURSOR CDynaArrayDlg::OnQueryDragIcon()
  161. {
  162. return (HCURSOR) m_hIcon;
  163. }
  164. void CDynaArrayDlg::OnAdd() 
  165. {
  166. // TODO: Add your control notification handler code here
  167. UpdateData(true);
  168. struct data temp={m_num1,m_num2,m_num3,m_num4};
  169. data1.InsertAt(m_index,temp);
  170. }
  171. void CDynaArrayDlg::OnDelate() 
  172. {
  173. // TODO: Add your control notification handler code here
  174. data1.RemoveAt(m_showindex);
  175. }
  176. void CDynaArrayDlg::OnShow() 
  177. {
  178. // TODO: Add your control notification handler code here
  179.    UpdateData(true);
  180.    m_shownum1=data1[m_showindex].n1;
  181.    m_shownum2=data1[m_showindex].n2;
  182.    m_shownum3=data1[m_showindex].n3;
  183.    m_shownum4=data1[m_showindex].n4;
  184.    UpdateData(false);
  185. }
  186. void CDynaArrayDlg::OnEdit() 
  187. {
  188. // TODO: Add your control notification handler code here
  189. UpdateData(true);
  190. data1.RemoveAt(m_showindex);
  191. struct data temp={m_shownum1,m_shownum2,m_shownum3,m_shownum4};
  192.     data1.InsertAt(m_showindex,temp);
  193. }