简体   繁体   English

Invalidate()调试断言失败消息(MFC,VC ++)

[英]Invalidate() debug assertion failed message (MFC, VC++)

I've made a custom control, and when I want it to repaint on the screen I call Invalidate(), and afterwards UpdateWindow(), but i get message: 我做了一个自定义控件,当我想让它在屏幕上重新绘制时,我调用了Invalidate(),然后调用了UpdateWindow(),但是我得到了消息:

debug assertion failed for a file afxwin2.inl in line 150 which is: 第150行中的文件axxwin2.inl的调试断言失败:

AFXWIN_INLINE void CWnd::Invalidate(BOOL bErase)

    { ASSERT(::IsWindow(m_hWnd)); ::InvalidateRect(m_hWnd, NULL, bErase); }

The thing is that when I run the same app in release mode, it doesn't report any message! 问题是,当我在发布模式下运行同一应用程序时,它不会报告任何消息! So this clue makes me think it's about some environment configuration I should change. 因此,这个线索使我认为这是我应该更改的某些环境配置。

What do you think? 你怎么看?

Thanks. 谢谢。

Well, 好,

ASSERT(::IsWindow(m_hWnd));

is an assertion. 是一个断言。 Assertions are statements which verify that something is true and kill your program if it's not. 断言是用于验证某些内容正确的语句,否则将杀死您的程序。 They're intended to be used for debugging and development rather than for being in the program once it has been released, so they are normally only compiled in in debug builds. 它们旨在用于调试和开发,而不是一旦发布就可用于程序中,因此它们通常仅在调试版本中进行编译。 So, it wouldn't be there in a release build, and you wouldn't get the error message. 因此,它不会在发布版本中存在,并且您不会收到错误消息。 That does not mean that there isn't a problem in the release build. 这并不意味着发行版本中没有问题。 It just means that that it's not running the statement to check whether there's a problem. 这只是意味着它没有运行语句来检查是否存在问题。

I don't know a lot about the error in question, but looking at it, 我对所涉及的错误了解不多,但是看着它,

::IsWindow(m_hWnd)

is obviously false (hence the error message). 显然是错误的(因此出现错误信息)。 The documentation for IsWindow() would appear to indicate that the problem is that the window handle in question is not a handle for a valid window. IsWindow()的文档似乎表明该问题是所讨论的窗口句柄不是有效窗口的句柄。 Perhaps it hasn't been created properly, or it has already been destroyed. 可能尚未正确创建,或者已被销毁。 You'll have to figure out why your window handle is invalid. 您必须弄清楚为什么窗口句柄无效。

A quick google search for "mfc iswindow" brings up this thread on msdn which might be of help to you. 谷歌快速搜索“ mfc iswindow”会在msdn上显示该线程 ,可能对您有帮助。

You call Invalidate before window is created or after window is destroyed. 您可以在创建窗口之前或销毁窗口之后调用Invalidate。 Quick fix is to test for ::IsWindow(m_hWnd) before Invalidate call. 快速解决方案是在Invalidate调用之前测试:: IsWindow(m_hWnd)。 To really fix this bug, find why Invalidate is called when window doesn't exist. 要真正修复此错误,请查找为什么在不存在窗口时调用Invalidate的原因。 For example, attempt to invalidate window from its constructor causes this assertion. 例如,尝试从其构造函数中使窗口无效会导致此断言。

You have called Invalidate() on an CWnd-derived class, but that window's m_hWnd member has not been built yet. 您已经在CWnd派生的类上调用了Invalidate(),但是尚未构建该窗口的m_hWnd成员。 You should call the Create (or CreateEx) method first, in order to build it (or use a method that does all that for you, like DoModal() ). 为了构建它,您应该首先调用Create(或CreateEx)方法(或使用为您完成所有工作的方法,如DoModal())。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM