MFC错误:CListCtrl中的断言错误 [英] MFC Error: Assertion Error in CListCtrl

查看:134
本文介绍了MFC错误:CListCtrl中的断言错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在MFC中开发一个基于对话框的应用程序,并且有一个带有复选框的CListCtrl.代码如下:

Hi everyone there,

I am developing a dialog based application in MFC and I have a CListCtrl with checkboxes. Code is as follows:

CListCtrl m_gridOutput;
m_gridOutput.SetExtendedStyle(m_gridCtrlEx.GetExtendedStyle() | LVS_EX_CHECKBOXES);


我可以跟踪ListControl中的更改,但是现在我试图更改项目复选框的状态.不幸的是,当我尝试使用以下代码时,我遇到断言错误.


I can track the changes in the ListControl but now I am trying to change the status of the Checkbox of an item. Unfortunately I am getting Assertion errors, when I try to use the following piece of code.

m_gridOutput.SetItem(1,0,LVIF_STATE,NULL,0,dwFlags,dwFlags,0);
(or)
ListView_SetItemState(m_gridOutput.GetSafeHwnd(),VarId,INDEXTOSTATEIMAGEMASK((fCheck)+ 1), LVIS_STATEIMAGEMASK);
(or)
ListView_SetCheckState((m_gridOutput.GetSafeHwnd(),Id,TRUE);



我想在这里再添加一件事.如果我在OnInitDialog()中使用SetCheck(或)ListView_SetCheckState,它可以正常工作.但是,如果我尝试在单独的函数中使用它,则会产生断言错误.如何处理?.

任何帮助将不胜感激.

Shiva



I want to add one more thing here. If i use SetCheck (or) ListView_SetCheckState in OnInitDialog(), it works fine. But if i try to use it in a seperate function, it gives assertion error. How to handle this?.

Any help is greatly appreciated.

Shiva

推荐答案

根据 ^ ]应该使用CListCtrl::SetCheck()方法.
According to MSDN[^] you should use the CListCtrl::SetCheck() method.


断言是什么意思?如果您闯入代码(使用重试"按钮)以查看其声明位置,则通常会有注释来帮助理解问题.

检查项目索引是否正确.
检查GetSafeHwnd不返回NULL.如果返回值为NULL,则表示该控件尚未完全创建(覆盖OnInitDialog并将您的代码放在此处).
What does the assertion say? If you break into the code (with the Retry button) to see where it asserted, you usually have comments to help understand the problem.

Check that the item index is correct.
Check that GetSafeHwnd doesn''t return NULL. If the return value is NULL, then it means the control is not fully created yet (override OnInitDialog and put your code there).


OnInitDialog()是一种立即被调用的方法创建父级CWnd及其所有子级之后.通常是您要对所有GUI组件进行初始化的地方(甚至在此之后的任何点都是有效的,但是框架指定您应该这样做).

当您说它在任何其他函数中导致断言时,...如果在调用该函数时未创建该特定窗口(例如在构造函数中),则将导致错误,但是如果该窗口未创建,则将导致错误已经创建(例如在事件处理程序中,该事件处理程序将仅称为窗口创建后).
OnInitDialog() is a method that is called immediately after the creation of the parent CWnd and all of its children. That''s usually the place where you want to do initialization of all GUI components (or even any point after that would be valid, but that''s where the framework specifies you should do it).

When you say that it causes an assert in any other function, well... it will cause an error if that particular window hasn''t been created when you called that function (such as in a constructor), but not if the window has already been created (such as in an event handler that will only be called post window creation).


这篇关于MFC错误:CListCtrl中的断言错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆