步骤/方法
向文本文件写入内容应该不难,学C++时专门讲过。 #include ofstream ofs("test.txt");
现在关键是如何获取指定编辑框中的内容。
全部代码如下: CString str; ofstream ofs("test.txt"); CStatic *pst=(CStatic*)GetDlgItem(IDC_EDIT1); //你的控件ID pst->GetWindowText(str); ofs<<str; //另存为对话框 void COutputDlg::OnButton1() { CString str; CFileDialog FileDlg(FALSE,".txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT); FileDlg.m_ofn.lpstrInitialDir="c:\\"; if(FileDlg.DoModal()==IDOK) { ofstream ofs(FileDlg.GetPathName()); CStatic*pst=(CStatic*)GetDlgItem(IDC_EDIT4);//你的控件ID pst->GetWindowText(str); ofs<<str; MessageBox("保存成功"); } }
ps:我的编译器是VC6.0