MFC CListCtrl中的setitemtext和LVN_ITEMCHANGED问题 [英] setitemtext and LVN_ITEMCHANGED problem in MFC CListCtrl
问题描述
大家好,
我在窗体视图上有一个列表控件.由于各种原因,我正在表单视图中处理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 aboolean
member (''internalListChange'' or similar) set it before your call tosetItemText()
and reset it after. Then in your message handler, right at the beginning, test forinternalListChange = true
and return if it is.
这篇关于MFC CListCtrl中的setitemtext和LVN_ITEMCHANGED问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!