如何区分某些LVITEMS(文件或目录)?
因此,我使用 PostMessage(LVN_INSERTITEM,0,(LPARAM) lvitem) 实现 CListCtrl。我需要一种方法来区分 lvitem,以便稍后当我得到 lvitem 时,可以判断它是文件还是目录。我需要使用 PostMessage
来实现,所以我不知道该项目何时插入。我正在动态分配该项目(将动态分配的内存指针存储在 LVITEM 结构的 lParam 属性中,因此在插入该项目后,我会处理它的通知并释放从该项目获取地址的内存)。
So I am implementing a CListCtrl using PostMessage(LVN_INSERTITEM,0,(LPARAM) lvitem)
. And I need a way to differentiate lvitems, so that later on when I will get a lvitem, to tell if it's a file or directory. I need to implement using PostMessage
, so I don't know exactly when the item is inserted. I am allocating the item dynamically (storing the dynamically allocated memory pointer in the lParam attribute of the LVITEM structure, so after it is inserted I treat it's notification and deallocate the memory getting the address from the item).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
LVITEM
结构为您的列表项设置自定义数据:注意: 在这种情况下,您应该释放由
lParam
使用删除
。You can use the
lParam
member of theLVITEM
structure to set custom data for you list item:Note: In this case you should free the memory pointed to by
lParam
usingdelete
.您可以使用
CListCtrl 设置任意数据: :SetItemData
,但您应该使用方法CListCtrl::InsertItem
而不是使用PostMessage
(这是一个低级的Win32 调用,而不是 MFC)。You can set arbitrary data with
CListCtrl::SetItemData
, but you should use the methodCListCtrl::InsertItem
instead of usingPostMessage
(which is a low-level Win32 call, not MFC).