MFC实现一个SDI程序,要求

MFC实现一个SDI程序,要求包含一个对话框,输入文字,运用文件读写技术,将文字画在窗体上

 新建一个叫CSDIDlgApp的程序

在你的Doc里面加入
public:
    CString text;

void CSDIDlgAppView::OnDraw(CDC* pDC)
{
    CSDIDlgAppDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    pDC->TextOut(0, 0, pDoc->text);
}

新建一个对话框叫CEditDlg
映射文本框m_text

void CEditDlg::OnOK() 
{
    // TODO: Add extra validation here
    this->UpdateData();
    CDialog::OnOK();
}

新建一个菜单
ID_EDITDLG

在Frame中
#include "editdlg.h"
#include "SDIDlgAppDoc.h"


void CMainFrame::OnEditdlg() 
{
    // TODO: Add your command handler code here
    CEditDlg dlg;
    if (dlg.DoModal() == IDOK)
    {
        ((CSDIDlgAppDoc *)this->GetActiveDocument())->text = dlg.m_text;
        this->GetActiveDocument()->UpdateAllViews(NULL);
    }
}

void CMainFrame::OnFileSave() 
{
    // TODO: Add your command handler code here
    CFileDialog dlg(FALSE);
    dlg.DoModal();
    CFile file(dlg.GetFileName(), CFile::modeCreate | CFile::modeWrite); 
    CArchive ar(&file, CArchive::store);
    ar << ((CSDIDlgAppDoc *)this->GetActiveDocument())->text;
}


新建一个叫CSDIDlgApp的程序

在你的Doc里面加入
public:
CString text;

void CSDIDlgAppView::OnDraw(CDC* pDC)
{
CSDIDlgAppDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(0, 0, pDoc->text);
}

新建一个对话框叫CEditDlg
映射文本框m_text

void CEditDlg::OnOK()
{
// TODO: Add extra validation here
this->UpdateData();
CDialog::OnOK();
}

新建一个菜单
ID_EDITDLG

在Frame中
#include "editdlg.h"
#include "SDIDlgAppDoc.h"

void CMainFrame::OnEditdlg()
{
// TODO: Add your command handler code here
CEditDlg dlg;
if (dlg.DoModal() == IDOK)
{
((CSDIDlgAppDoc *)this->GetActiveDocument())->text = dlg.m_text;
this->GetActiveDocument()->UpdateAllViews(NULL);
}
}

void CMainFrame::OnFileSave()
{
// TODO: Add your command handler code here
CFileDialog dlg(FALSE);
dlg.DoModal();
CFile file(dlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
CArchive ar(&file, CArchive::store);
ar << ((CSDIDlgAppDoc *)this->GetActiveDocument())->text;
}