程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 技術-MFC實現一個SDI程序,要求

技術-MFC實現一個SDI程序,要求

編輯:編程綜合問答
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;
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved