MFC 单文档中OnDraw和OnNewDocument()的运行先后

lxc122103 2016-03-14 10:14:18
我程序中OnDraw先运行,OnNewDocument()却后运行,我看其他工程时,运行顺序确是相反的。请问是什么影响这个运行顺序?onDraw是View类中,OnNewDocument是Doc类中的。
...全文
360 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2016-03-15
  • 打赏
  • 举报
回复
void CxxxxView::OnDraw(CDC* pDC) { CxxxxDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // 测试 doc里 有没有 数据 if(pDOC->m_data /* int m_data[100] */ ==NULL) DoNothing(); else DoFuction();
schlafenhamster 2016-03-15
  • 打赏
  • 举报
回复

BOOL CxxxxDoc::OnNewDocument()
{
	afxDump << "OnNewDocument\n";
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}
BOOL CxxxxDoc::OnNewDocument() 是doc的 虚函数 不是 消息,
lxc122103 2016-03-15
  • 打赏
  • 举报
回复
引用 5 楼 schlafenhamster 的回复:
// 启动时不自动打开一个空文档 cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; enum { FileNew, FileOpen, FilePrint, FilePrintTo, FileDDE, AppUnregister, FileNothing = -1 } m_nShellCommand; m_nShellCommand 默认是 FileNew, 所以 一开始 OnNewDocument()
谢谢大神,我理解了, 请问大神,在MFC 单文档中,onnewdocument函数和ondraw函数,我想在onnewdocument函数中读取数据,在ondraw函数中画图,但是在程序中不是先执行onnewdocument,所以在ondraw函数中读取不了数据,就会出错。请问大神有什么解决办法?
lxc122103 2016-03-15
  • 打赏
  • 举报
回复
大神,请问MFC 单文档中,onnewdocument函数和ondraw函数,我想在onnewdocument函数中读取数据,在ondraw函数中画图,但是在程序中不是先执行onnewdocument,所以在ondraw函数中读取不了数据,就会出错。请问大神有什么解决办法?
lm_whales 2016-03-14
  • 打赏
  • 举报
回复
OnDraw 一直在运行 OnNewDocument() 偶尔运行一次
schlafenhamster 2016-03-14
  • 打赏
  • 举报
回复
// 启动时不自动打开一个空文档 cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; enum { FileNew, FileOpen, FilePrint, FilePrintTo, FileDDE, AppUnregister, FileNothing = -1 } m_nShellCommand; m_nShellCommand 默认是 FileNew, 所以 一开始 OnNewDocument()
lxc122103 2016-03-14
  • 打赏
  • 举报
回复
引用 2 楼 schlafenhamster 的回复:
如果 程序 启动时 有 NewDocument , 即 cmdInfo.m_nShellCommand 不是 FileNothing // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;// no empty document ParseCommandLine(cmdInfo); 则会有 BOOL CxxxxDoc::OnNewDocument() { afxDump << "OnNewDocument\n"; 。。。。
大神,什么意思?这样做可以让onnewdocument先运行,ondraw后运行吗?
lxc122103 2016-03-14
  • 打赏
  • 举报
回复
引用 1 楼 lm_whales 的回复:
OnDraw 一直在运行 OnNewDocument() 偶尔运行一次
我调试不同的程序。设置相同的断点。结果不知道为什么一个是先运行OnNewDocument() ,后运行ondraw。我打算在OnNewDocument() 中读取数据,然后在ondraw函数中画图。那可以有什么办法吗?我把读取数据的函数放到ondraw函数中,但是有内存泄露。
schlafenhamster 2016-03-14
  • 打赏
  • 举报
回复
如果 程序 启动时 有 NewDocument , 即 cmdInfo.m_nShellCommand 不是 FileNothing // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;// no empty document ParseCommandLine(cmdInfo); 则会有 BOOL CxxxxDoc::OnNewDocument() { afxDump << "OnNewDocument\n"; 。。。。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧