我现在想用visual c++编写一个记事本程序,如何实现它的新建功能.我首先建立一个单文档应用程序,然后在程序中加入CFormView类,在该类中添加一个编辑框,用来显示文本,通过文档序列化,点击"新建"按钮,将编辑框原来的内容清空,我按照文档序列化的内容去操作,有问题,这是BOOL CText1Doc::OnNewDocument()
的代码
BOOL CText1Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE; // TODO: add reinitialization code here
// (SDI documents will reuse this document)
CText1Doc pDoc;
pDoc.DeleteContents ();
pDoc.UpdateAllViews (NULL,1,(CObject*)&m_Text);
CMainFrame* pWnd=(CMainFrame*)AfxGetApp()->m_pMainWnd ;
pWnd->ActivateFrame (1);
return TRUE;
}
请看一下,谢谢
的代码
BOOL CText1Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE; // TODO: add reinitialization code here
// (SDI documents will reuse this document)
CText1Doc pDoc;
pDoc.DeleteContents ();
pDoc.UpdateAllViews (NULL,1,(CObject*)&m_Text);
CMainFrame* pWnd=(CMainFrame*)AfxGetApp()->m_pMainWnd ;
pWnd->ActivateFrame (1);
return TRUE;
}
请看一下,谢谢
另外CText1Doc::OnNewDocument是在新的文档建立以后被调用的,管好自己的数据就行了,不要去修改什么窗口的东西。
上面也说了,象你这样
CText1Doc pDoc;
pDoc.DeleteContents ();
真不知道在干什么,这个pDoc算什么东西?
再说一遍:CText1Doc::OnNewDocument是在新的文档建立以后被调用的。你点击菜单或者工具栏上的“新建”不就建立新的文档了吗?
{
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
中加入了这段代码
CText1Doc pDoc;
pDoc.DeleteContents ();
pDoc.UpdateAllViews (NULL,1,(CObject*)&m_Text);
CMainFrame* pWnd=(CMainFrame*)AfxGetApp()-> m_pMainWnd ;
pWnd-> ActivateFrame (1);
目的就是实现记事本的"新建"功能,