1、OnCreate(LPCREATESTRUCT lpCreateStruct)if (CFrameWnd:OnCreate(lpCreateStruct) = -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY|CBRS_SIZE_DYNAMIC)|!m_wndToolBar.LoadToolBar(IDR_MAINFRAME) TRACE0(Failed to create
2、toolbarn); return -1; / fail to createIf(!m_wndStatusBar.Create(this)|!m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)Failed to create status barnm_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);return 0;void CMainFrame:On
3、Menuitemadd() CMyDlgAdd dlg1; dlg1.DoModal();OnMenuitemmodify() CMyDlgModify dlg2; dlg2.DoModal();OnMenuitemseek() CMyDlgSeek dlg3; dlg3.DoModal();2.录入消息对话框的消息映射:HBRUSH CMyDlgAdd:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) HBRUSH hbr = CDialog:OnCtlColor(pDC, pWnd, nCtlColor);if(nCtlColor = CTL
4、COLOR_BTN | nCtlColor = CTLCOLOR_STATIC)pDC-SetTextColor(RGB(0,0,255);SetBkMode(TRANSPARENT); return hbr;void CMyDlgAdd:OnPaint() CPaintDC dc(this); / device context for painting LOGFONT lf; memset(&lf,0,sizeof(LOGFONT); lf.lfHeight=28; lf.lfCharSet=GB2312_CHARSET; strcpy(LPSTR)&(lf.lfFaceName),华文新魏
5、 CFont cf; cf.CreateFontIndirect(&lf); m_Title.SetFont(&cf);OnOK() UpdateData(); struct Record *re=per; fstream file; CFile file1; file.open(record.txt,ios:in|ios:out|ios:app); int nIndex=m_Speciality.GetCurSel(); int i=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2); const int size=sizeof(struct Recor
6、d); if(re)-id=0|(re)-name=0|re-speciality=0|re-grade=0|i=0) MessageBox(输入不完整,不能提交! else strcpy(re)-id,m_Num);name,m_Name); CString str; int y,m,d; y=m_Birth.GetYear(); m=m_Birth.GetMonth(); d=m_Birth.GetDay(); str.Format(%d-%d-%d,y,m,d); strcpy(re-date,str); if(i=IDC_RADIO1) strcpy(re-sex,男 if(i=IDC
7、_RADIO2) 女 if(nIndex=0) speciality,计算机 if(nIndex=1) 数学grade,m_Grade); fileid namesexspecialitygradedateendl; file.close(); CDialog:OnOK();MessageBox(添加成功!,MB_OK,MB_ICONASTERISK);2.学生信息修改对话框消息映射:BOOL CMyDlgModify:OnInitDialog() OnInitDialog(); UpdateData(false); const int nColumns=6; m_list1.InsertCo
8、lumn(0,学号 m_list1.InsertColumn(1,姓名 m_list1.InsertColumn(2,性别 m_list1.InsertColumn(3,专业 m_list1.InsertColumn(4,年级 m_list1.InsertColumn(5,出生日期 CRect rect4; m_list1.GetClientRect(rect4); for(int i=0;iper.idper.nameper.sexper.specialityper.gradeper.date; m_list1.InsertItem(j,per.id); m_list1.SetItemTex
9、t(j,1,per.name); m_list1.SetItemText(j,2,per.sex); m_list1.SetItemText(j,3,per.speciality); m_list1.SetItemText(j,4,per.grade); m_list1.SetItemText(j,5,per.date); strcpy(per.id, strcpy(per.name, strcpy(per.sex, strcpy(per.speciality, strcpy(per.grade, strcpy(per.date, ListView_SetExtendedListViewSty
10、le(m_list1.m_hWnd,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); /设置可以选整行 return TRUE;void CMyDlgModify:OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) CListCtrl* pListCtrl = (CListCtrl*) GetDlgItem(IDC_LIST1); ASSERT(pListCtrl != NULL); POSITION pos = m_list1.GetFirstSelectedItemPosition(); if(pos!=NULL) nI
11、tem = m_list1.GetNextSelectedItem(pos); m_Id=m_list1.GetItemText(nItem,0); m_Name=m_list1.GetItemText(nItem,1); if(m_list1.GetItemText(nItem,2)=) CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1); elseCheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO2); m_Speciality=m_list1.GetItemText(nItem,3); m_G
12、rade=m_list1.GetItemText(nItem,4); m_Date=m_list1.GetItemText(nItem,5);m_Num.Format(%d,nItem+1); UpdateData(false); *pResult = 0; if(IDNO = MessageBox(确定要修改吗?,提问,MB_YESNO|MB_ICONQUESTION) return ; fstream file1,file2; file1.open(in); file2.open(record1.txtfile1|!file2) MessageBox( int n =0 , m = 0;
13、while(!file1.eof() n+ ;file1 n-; m = n ; file1.close();int nIndex = m_list1.GetSelectionMark();char id20=0;strcpy(id,m_list1.GetItemText(nIndex,0);memset(&while(n) if(strcmp(per.id,id) != 0 ) file2per.idper.nameper.sexper.specialityper.gradeper.date else /要修改的记录 strcpy(per.id,m_Id); strcpy(per.name,
14、m_Name); int i=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2); if(i=IDC_RADIO1) strcpy(per.sex, if(i=IDC_RADIO2) strcpy(per.speciality,m_Speciality); strcpy(per.grade,m_Grade); strcpy(per.date,m_Date); file2 n-; file2.close(); remove( rename( m_Num = m_Name = m_Speciality = m_Grade = UpdateData(FALSE)
15、; RefreshData(m);RefreshData(int m ) m_list1.DeleteAllItems(); m_list1.SetRedraw(FALSE); int i = 0 ; while( i if(strcmp(per.id,id) ! 确定要删除吗? m_Speciality = m_Birth = OnButton2() CDialog:OnCancel(); int flag;Error! flag=0;file.eof()&flag) if(m_Num=per.id) m_Name=per.name; if(strcmp(per.sex,)=0) else
16、m_Speciality=per.speciality; m_Grade=per.grade; m_Birth=per.date; flag=1; if(flag=0)查无此人!五 心得体会和参考资料工程中还存在很多不足,不是很完善。通过工程的构思,构建,到模块的实现,最后代码的编写,以及令人头痛的改错过程。制作中不断遇到新问题,自己努力去看书,去图书馆查询资料,实在不会就去请教学的比较好的同学,大家一起思考怎么解决一个个难题,不断的错误,不断的更正,有点摸着石头过河的意思。自己也发现了自己还存在许多问题,但是在工程的制作中,我觉得我很有收获,对各方面的知识有了新的认识,有了更加深刻的理解,增加了自己的构建工程能力,提高自己解决问题的能力。在以后的生活中,要自己主动去做一些工程,因为我觉得在工程项目中可以学习到很多知识和经验,可以实实在在得提高自己的能力。参考资料:Visual C+ 郑阿奇主编 清华大学出版社
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1