c++ mfc CFile+CArchive 简单实践( 二 )

< 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);}}// Set the icon for this dialog.The framework does this automatically//when the application's main window is not a dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small icon// TODO: Add extra initialization herereturn TRUE;// return TRUEunless you set the focus to a control}void CCFileTestDlg::OnSysCommand(UINT nID, LPARAM lParam){if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID, lParam);}}// If you add a minimize 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 CCFileTestDlg::OnPaint() {if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icondc.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 CCFileTestDlg::OnQueryDragIcon(){return (HCURSOR) m_hIcon;}double g_data1 = 0.0;double g_data2 = 0.0;double g_data3 = 0.0;int g_ndata = http://www.kingceram.com/post/0;void CCFileTestDlg::OnButton1() {// TODO: Add your control notification handler code hereCString data1,data2,data3,data4;CFile SetFile;if(SetFile.Open(_T("setfujiandata.ini"),CFile::modeRead)){ CArchive ar(&SetFile,CArchive::load);try{ar >> data1;ar >> data2;ar >> data3;ar >> data4;}catch(CArchiveException* e){e->ReportError();e->Delete();ar.Close();SetFile.Close();}ar.Close();SetFile.Close();g_data1 = atof(data1);g_data2 = atof(data2);g_data3 = atof(data3);g_ndata = http://www.kingceram.com/post/atoi(data4);SetDlgItemText(IDC_EDIT1,data1);SetDlgItemText(IDC_EDIT2,data2);SetDlgItemText(IDC_EDIT3,data3);SetDlgItemText(IDC_EDIT4,data4);}}void CCFileTestDlg::OnButton2() {// TODO: Add your control notification handler code here// TODO: 在此添加控件通知处理程序代码CString data1,data2,data3,data4;GetDlgItemText(IDC_EDIT1,data1);GetDlgItemText(IDC_EDIT2,data2);GetDlgItemText(IDC_EDIT3,data3);GetDlgItemText(IDC_EDIT4,data4);CFile SetFile;if(SetFile.Open(_T("setfujiandata.ini"),CFile::modeCreate|CFile::modeWrite)){ CArchive ar(&SetFile,CArchive::store);try{ar << data1;ar << data2;ar << data3;ar << data4;}catch(CArchiveException* e){e->ReportError();e->Delete();ar.Close();SetFile.Close();}g_data1 = atof(data1);g_data2 = atof(data2);g_data3 = atof(data3);g_ndata = http://www.kingceram.com/post/atof(data4);ar.Close();SetFile.Close();//g_bSet = true;MessageBox(_T("保存成功!"));}else{MessageBox(_T("保存失败!"));}}void CCFileTestDlg::OnButton4() {// TODO: Add your control notification handler code hereSetDlgItemText(IDC_EDIT1,"");SetDlgItemText(IDC_EDIT2,"");SetDlgItemText(IDC_EDIT3,"");SetDlgItemText(IDC_EDIT4,"");}
3. 运行
4.引用
4.1 CFile
【c++ mfc CFile+CArchive 简单实践】4.2