1、高级程序设计项目训练汇报 指导老师:黄欢 时间 年 7 月 27 日 专业年级: 姓名: 学号: 汇报分 程序功效:1) 学生基础信息录入功效 2) 学生信息查询功效 3) 学生信息删除 学生信息包含: 姓名、性别、学号、班级、出生年月、手机号码、已经取得学分等 输入输出数据说明:输入学生信息点击确定,在“学生信息查询”中输入姓名,就能够在“查询结果”中输出对应信息。 汇报内容 一、 分析 设计是一个基于MFC对话框C++应用程序,创建了一个主对话框,和部分必需子
2、对话框。在主对话框中添加列表控件用来显示学生基础信息。关键用到了在MFC中利用编辑框只是,还有插入位图。 二、 操作 运行后点击“学生信息录入”显示: 输入相关信息在确定。在选中信息点击删除,可进行删除操作。 点击“学生信息查询”显示: 输入名字,若有信息储存,则在查询结果中显示,若无信息储存则显示: 主代码: // zxyDlg.cpp : implementation file // #include "stdafx.h" #include "zxy.h" #include "zxyDlg.h" #ifdef _DEBUG #define
3、new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAbout
4、Dlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg)
5、//}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_M
6、ESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CZxyDlg dialog CZxyDlg::CZxyDlg(CWnd* pParent /*=NULL*/) : CDialog(CZxyDlg::IDD, pParen
7、t) { //{{AFX_DATA_INIT(CZxyDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CZxyDlg::DoDataExchange(CDataExchange* pDX)
8、{ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CZxyDlg) DDX_Control(pDX, IDC_BUTTON3, m_button_change); DDX_Control(pDX, IDC_BUTTON2, m_button_del); DDX_Control(pDX, IDC_BUTTON1, m_button_enter); DDX_Control(pDX, IDC_LIST4, m_list_ctrl); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CZxyD
9、lg, CDialog) //{{AFX_MSG_MAP(CZxyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////
10、////////////////////////////////////// // CZxyDlg message handlers BOOL CZxyDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_A
11、BOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
12、 } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_list_ctrl.SetExtende
13、dStyle(LVS_EX_FULLROWSELECT); CRect rect; m_list_ctrl.GetClientRect(&rect); int nColInterval=rect.Width()/16; m_list_ctrl.InsertColumn(0,_T("学号"),LVCFMT_LEFT,nColInterval*3); m_list_ctrl.InsertColumn(1,_T("姓名"),LVCFMT_LEFT,nColInterval*2); m_list_ctrl.InsertColumn(2,_T("性别"),LVCFMT_CENTE
14、R,nColInterval*1+5); m_list_ctrl.InsertColumn(3,_T("班级"),LVCFMT_LEFT,nColInterval*2); m_list_ctrl.InsertColumn(4,_T("出生日期"),LVCFMT_LEFT,nColInterval*3); m_list_ctrl.InsertColumn(5,_T("电话号码"),LVCFMT_LEFT,nColInterval*3); m_list_ctrl.InsertColumn(6,_T("已获学分"),LVCFMT_LEFT,nColInterval*2);
15、return TRUE; // return TRUE unless you set the focus to a control } void CZxyDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a min
16、imize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CZxyDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting
17、 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Heigh
18、t() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CZxyDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }
19、 #include "MyDialog_enter.h" void CZxyDlg::OnButton1() { // TODO: Add your control notification handler code here CMyDialog_enter *pwd=new CMyDialog_enter(this); pwd->Create(IDD_DIALOG1,this); pwd->ShowWindow(1); } #include "student.h" void CZxyDlg::List_Show(void) { m_list_ctr
20、l.DeleteAllItems();
int nItem = m_list_ctrl.GetItemCount();
for (int i=0;i 21、m_list_ctrl.SetItemText(nItem, 3,people[i].inst);
m_list_ctrl.SetItemText(nItem, 4,people[i].brondata);
m_list_ctrl.SetItemText(nItem, 5,people[i].phone);
m_list_ctrl.SetItemText(nItem, 6,people[i].grade);
}
}
void CZxyDlg::OnButton2()
{
// TODO: Add your control notification ha 22、ndler code here
int nItem=m_list_ctrl.GetSelectionMark();
//AfxMessageBox(people[nItem].sname,MB_OK);
if (nItem==-1)
{
AfxMessageBox("您未选择任何内容!",MB_OK);
}
else
{
if (AfxMessageBox("确定删除学生"+people[nItem].sname+"信息?",MB_YESNO)==IDYES)
{
for (;nItem 23、)
{
people[nItem].All_Copy(people[nItem+1]);
}
people[0].AllNumber--;
List_Show();
}
}
}
#include "MyDialog_2.h"
void CZxyDlg::OnButton3()
{
// TODO: Add your control notification handler code here
CMyDialog_2 *pwnd=new CMyDialog_2(this);
pwnd->Create(IDD 24、DIALOG2,this);
pwnd->ShowWindow(1);
}
BOOL CZxyDlg::PreTranslateMessage(MSG* pMsg) //屏蔽回车和ESC按键
{
// TODO: 在此添加专用代码和/或调用基类
{
// 屏蔽 回车和ESC 键
// 屏蔽ESC 键退出
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x1b)
return TRUE;
// 回车
if 25、 (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x0d )
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
碰到问题及处理方法(编译错误提醒及怎样处理)
1、关键碰到了部分组员变量添加错误问题,在经过Ctrl+W操作显示窗口中重新添加后得以更正,是缺乏组员变量问题。
2、还有做作业过程中数次碰到缺乏定义现象,在同学帮助下找到并添加更正。
3、在实施时出现“计算机中缺乏.DLL文件,无法运行”问题在工程常规中在了连接方法后运行。






