断言错误:ASSERT(ContinueModal())

49 篇文章 0 订阅
35 篇文章 0 订阅

在MFC中做一个小程序,调试的时候总是出现如下错误:

Debug Assertion Failed!

原因未知,然后按提示点击“调试”,然后进入代码:

ASSERT(ContinueModal());

也就是说在这儿产生了断言错误,即程序的某部分不符合对程序的设想,一般是条件不满足或错误而导致这类错误。

后来在CSDN(http://topic.csdn.net/t/20060308/15/4600918.html)上面查到一个线索,也是我的程序产生错误的原因。

错误原因:

我在后台开了一个线程,然后用它来处理信息,并通过函数SendMessage()给对话框传递一个信息;而此时,对话框尚未初始化完成。

错误分析:

分析下面的两个函数:(MSDN解释如下)

CWnd::SendMessage

This method sends the specified message to this window. The SendMessage method calls the window procedure directly and does not return until that windows procedure has processed the message. This is in contrast to the PostMessage method, which places the message into the window message queue and returns immediately.

即,SendMessage()等待处理完发送的信息后才返回;

CWnd::PostMessage

This method places a message in the window message queue. This method returns without waiting for the corresponding window to process the message. Messages in a message queue are retrieved by calls to the GetMessage or PeekMessage Windows CE function.

The Windows CE PostMessage function can be used to access another application.

即,PostMessage()把消息发送到窗口的消息队列之后立即返回;

解决办法:

换SendMessage()函数为PostMessage()函数

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值