void Ctemp1Dlg::OnBnClickedWrite()
{
// TODO: 在此添加控件通知处理程序代码
CStdioFile m_File;
CString m_stredit1;
CString m_stredit2;
GetDlgItemText(IDC_EDIT1,m_stredit1);
GetDlgItemText(IDC_EDIT2,m_stredit2);
m_File.Open("c:\\data.txt", CFile::modeCreate| CFile::modeWrite);
//m_File.Seek(0, CFile::begin);
m_File.WriteString(m_stredit1+"\n");
m_File.WriteString(m_stredit2+"\n");
m_File.Close();
GetDlgItem(IDC_EDIT1)->SetWindowText("");
GetDlgItem(IDC_EDIT2)->SetWindowText("");
AfxMessageBox("写入OK!");
}
void Ctemp1Dlg::OnBnClickedRead()
{
// TODO: 在此添加控件通知处理程序代码
CStdioFile m_File;
CString m_stredit1;
CString m_stredit2;
m_File.Open("c:\\data.txt", CFile::modeRead);
m_File.Seek(0, CFile::begin);
m_File.ReadString(m_stredit1);
m_File.ReadString(m_stredit2);
SetDlgItemText(IDC_EDIT1,m_stredit1);
SetDlgItemText(IDC_EDIT2,m_stredit2);
m_File.Close();
}
退出时保存
打开时载入而已
本人是新手,求代码!求大虾给力啊!!!
BOOL CMy20130615mfcDlg::OnInitDialog()
{
。。。省略。。。。
// 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
//打开时加载数据
FILE *fp;
if ((fp= fopen("config.ini","r"))!=NULL)
{
char str[128]={0};
fgets(str,sizeof(str),fp);
fclose(fp);
SetDlgItemText(IDC_EDIT1,(LPCSTR)str);
UpdateData(TRUE);
AfxMessageBox("加载上次数据完成!");
}else
{
AfxMessageBox("第一次运行!");
}
return TRUE; // return TRUE unless you set the focus to a control
}
//退出时保存数据
void CMy20130615mfcDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
FILE *fp=fopen("config.ini","w");
CString str;
GetDlgItemText(IDC_EDIT1,str);
fprintf(fp,"%s",(LPCTSTR)str);
fclose(fp);
AfxMessageBox("成功保存本次数据!");
CDialog::OnClose();
}