StudentDlg.cpp
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // StudentDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Student.h"
  5. #include "StudentDlg.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. // CStudentDlg dialog
  50. CStudentDlg::CStudentDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CStudentDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CStudentDlg)
  54. m_strEditName = _T("");
  55. m_nRadioSex = -1;
  56. m_bChkMusic = FALSE;
  57. m_bChkDance = FALSE;
  58. m_bChkSport = FALSE;
  59. m_bChkTour = FALSE;
  60. m_strSpecial = _T("");
  61. //}}AFX_DATA_INIT
  62. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  63. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  64. }
  65. void CStudentDlg::DoDataExchange(CDataExchange* pDX)
  66. {
  67. CDialog::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(CStudentDlg)
  69. DDX_Control(pDX, IDC_INFORMATION, m_ctrlLBInfo);
  70. DDX_Text(pDX, IDC_NAME, m_strEditName);
  71. DDX_Radio(pDX, IDC_SEX, m_nRadioSex);
  72. DDX_Check(pDX, IDC_MUSIC, m_bChkMusic);
  73. DDX_Check(pDX, IDC_DANCE, m_bChkDance);
  74. DDX_Check(pDX, IDC_SPORT, m_bChkSport);
  75. DDX_Check(pDX, IDC_TOUR, m_bChkTour);
  76. DDX_CBString(pDX, IDC_SPECIALTY, m_strSpecial);
  77. //}}AFX_DATA_MAP
  78. }
  79. BEGIN_MESSAGE_MAP(CStudentDlg, CDialog)
  80. //{{AFX_MSG_MAP(CStudentDlg)
  81. ON_WM_SYSCOMMAND()
  82. ON_WM_PAINT()
  83. ON_WM_QUERYDRAGICON()
  84. ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
  85. //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CStudentDlg message handlers
  89. BOOL CStudentDlg::OnInitDialog()
  90. {
  91. CDialog::OnInitDialog();
  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. return TRUE;  // return TRUE  unless you set the focus to a control
  113. }
  114. void CStudentDlg::OnSysCommand(UINT nID, LPARAM lParam)
  115. {
  116. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  117. {
  118. CAboutDlg dlgAbout;
  119. dlgAbout.DoModal();
  120. }
  121. else
  122. {
  123. CDialog::OnSysCommand(nID, lParam);
  124. }
  125. }
  126. // If you add a minimize button to your dialog, you will need the code below
  127. //  to draw the icon.  For MFC applications using the document/view model,
  128. //  this is automatically done for you by the framework.
  129. void CStudentDlg::OnPaint() 
  130. {
  131. if (IsIconic())
  132. {
  133. CPaintDC dc(this); // device context for painting
  134. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  135. // Center icon in client rectangle
  136. int cxIcon = GetSystemMetrics(SM_CXICON);
  137. int cyIcon = GetSystemMetrics(SM_CYICON);
  138. CRect rect;
  139. GetClientRect(&rect);
  140. int x = (rect.Width() - cxIcon + 1) / 2;
  141. int y = (rect.Height() - cyIcon + 1) / 2;
  142. // Draw the icon
  143. dc.DrawIcon(x, y, m_hIcon);
  144. }
  145. else
  146. {
  147. CDialog::OnPaint();
  148. }
  149. }
  150. // The system calls this to obtain the cursor to display while the user drags
  151. //  the minimized window.
  152. HCURSOR CStudentDlg::OnQueryDragIcon()
  153. {
  154. return (HCURSOR) m_hIcon;
  155. }
  156. void CStudentDlg::OnDisplay() 
  157. {
  158. UpdateData(TRUE);
  159. m_ctrlLBInfo.AddString("姓名:"+m_strEditName);
  160. if(m_nRadioSex==0)
  161. m_ctrlLBInfo.AddString("性别:男");
  162. else
  163. m_ctrlLBInfo.AddString("性别:女");
  164. m_ctrlLBInfo.AddString("专业:"+m_strSpecial);
  165. m_ctrlLBInfo.AddString("爱好:");
  166. if(m_bChkMusic)
  167. m_ctrlLBInfo.AddString("       音乐");
  168. if(m_bChkDance)
  169. m_ctrlLBInfo.AddString("       舞蹈");
  170. if(m_bChkSport)
  171. m_ctrlLBInfo.AddString("       体育");
  172. if(m_bChkTour)
  173. m_ctrlLBInfo.AddString("       旅游");
  174. }