MFC CListCtrl中的setitemtext和LVN_ITEMCHANGED问题 [英] setitemtext and LVN_ITEMCHANGED problem in MFC CListCtrl

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

问题描述

大家好,

我在窗体视图上有一个列表控件.由于各种原因,我正在表单视图中处理LVN_ITEMCHANGED消息.在特定情况下,我想更改第二行第0列的文本,因此我使用了setItemText()来做到这一点.这一次,我再次收到LVN_ITEMCHANGED消息,引起了一个大问题(递归调用).
如何停止第二条消息?

Hello all,

I have a list control on a form view. I am handling LVN_ITEMCHANGED message in form view for various reasons. In a particular case, I want to change the text of a 2nd row, 0th column, so I used setItemText() to do that. At this time, again I am receiving LVN_ITEMCHANGED message, causing a big problem(recursive call).
How can I stop this second message?

推荐答案

您可以尝试根据 ^ ]
You could try checking the uChanged parameter of the message as per http://msdn.microsoft.com/en-us/library/bb774845(v=vs.85).aspx[^]
void CMyClass::OnItemChanged(NMHDR *pNMHDR, LRESULT *pResult) {
	*pResult = 1; //or =0 if you want the message to continue to be processed
	pNMLV = (LPNMLISTVIEW)pNMHDR;
	if (!(pNMLV->uChanged & LVIF_TEXT)) {
		//SetItemText();
	}
}



我不确定这是否行得通,您可能需要尝试一下并检查pNMLV的值,以查看第一次调用和递归调用之间的变化.



Im not sure if that will work, you may need to experiment with it a little and check the values of pNMLV to see what is changing between the first call and the recursive call.


实现目标的一种方法是在调用setItemText()之前先设置boolean成员("internalListChange"或类似名称),然后再对其进行重置.然后在您的消息处理程序中,从头开始,测试internalListChange = true并返回是否为它.
One way to achieve your aims is to have a boolean member (''internalListChange'' or similar) set it before your call to setItemText() and reset it after. Then in your message handler, right at the beginning, test for internalListChange = true and return if it is.


这篇关于MFC CListCtrl中的setitemtext和LVN_ITEMCHANGED问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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