您的位置:首页 > 其它

MFC写一个简单记事本

2016-11-21 20:31 176 查看






void CLinjtlDlg::OnClickedOpen()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"ALL Files(*.TXT)|*.TXT||",AfxGetMainWnd());
CString strPath,strText="";
if(dlg.DoModal()==IDOK)
{
strPath =dlg.GetPathName();
m_OP.SetWindowText(strPath);
CFile file(strPath,CFile::modeRead);
char read[10000];
file.Read(read,10000);
for(int i=0;i<file.GetLength();i++)
{
strText+=read[i];
}
file.Close();
m_Edit1.SetWindowText(strText);
}
}

void CLinjtlDlg::OnBnClickedSave()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"ALL Files(*.TXT)|*.TXT||",AfxGetMainWnd());
CString strPath,strText="";
char write[1000];
if(dlg.DoModal()==IDOK)
{
strPath=dlg.GetPathName();
if(strPath.Right(4)!=".txt")
strPath+=".txt";
m_SP.SetWindowText(strPath);
CFile file(_T(strPath),CFile::modeCreate|CFile::modeWrite);
m_Edit1.GetWindowText(strText);
strcpy(write,strText);
file.Write(write,strText.GetLength());
file.Close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mfc