英文:
How is the lParam of LVITEM stored in virtual list control?
问题
在虚拟列表控件中,我可以通过函数“OnGetdispinfoList”获取“LVITEM”。但是,如果我通过“lParam”在此处添加附加信息并将其分配给“LVITEM”,这个指向数据的指针(我目前的猜测)是否真的存储在“LVITEM”中?因为虚拟列表控件不维护数据,只显示所需的数据。那么“lParam”中的信息的生命周期是如何管理的?
谢谢
英文:
In a virtual list control, I can obtain a LVITEM
by a function OnGetdispinfoList
. But if I add additional information here through lParam
and assign this to LVITEM
, Is this pointer-to-data (my guess so far) really stored in the LVITEM
? Because virtual list control doesn't maintain the data but only display what is needed. So how is the lifecycle of the information in lParam?
Thank you
答案1
得分: 2
虚拟列表视图控件确实不维护任何数据,因此不调用ListView_InsertItem()
(或LVM_INSERTITEM
),而是调用ListView_SetItemCountEx()
(或LVM_SETITEMCOUNT
)。
LVN_GETDISPINFO
通知是一个回调函数(实际上是消息)。您必须提供被请求的信息。您的代码应该检查LVITEM
结构的mask
成员并填充所请求的数据。这个结构存储在哪里以及它的生存期无关紧要,反正你无法控制。它可能存储在堆栈或一些临时数组中,但你不应该做出任何假设。当然,不要将句柄或指针之类的东西存储在虚拟列表视图控件的LVITEM
结构的lParam
成员中,并期望它们会被保留。我会非常惊讶地发现对于虚拟列表视图控件(即系统要求您填写lParam
成员的情况),mask
的LVIF_PARAM
位被设置,这对我来说毫无意义;你可以添加一些代码来测试它,但我不认为它会被设置。
英文:
Virtual list-view controls indeed do not maintain any data, hence you don't call ListView_InsertItem()
(or LVM_INSERTITEM
) but you call ListView_SetItemCountEx()
(or LVM_SETITEMCOUNT
) instead .
The LVN_GETDISPINFO
notification is a call-back function (well, message). You have to provide the information you are being asked. Your code should examine the mask
member of the LVITEM
srtucture and fill-in the data requested. It doesn't matter where this structure is stored and its lifetime, you don't have any control over it anyway. It's probably stored in the stack or some temporary array into the memory, but you should make no assumptions. And of course do not store things like a handle or pointer in the lParam
member of the LVITEM
srtucture for a virtual list-view control and expect them to be stored. I would actually be very surprised to find that the LVIF_PARAM
bit of the mask
is set for virtual list-view control (ie the system is asking you to fill-in the lParam
member), it makes no sense to me; you can add some code to test it, but I don't think it will ever be set.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论