如何区分某些LVITEMS(文件或目录)?

发布于 2024-12-19 22:49:06 字数 252 浏览 7 评论 0原文

因此,我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九八野马 2024-12-26 22:49:06

您可以使用 LVITEM 结构为您的列表项设置自定义数据:

// custom structure to hold some information
struct listItem {
   int value;
   char path[MAX_PATH];
};

// initialize a custom object to hold a value and a path
LVITEM lvi;
listItem* pItem = new listItem();
pItem->value = 666;
sprintf(pItem->path,"c:\\\\xampp\\htdocs");

// initialize a LVITEM object
memset(&lvi, 0, sizeof(lvi)),
lvi.pszText = "My Folder";
lvi.mask = LVIF_PARAM | LVIF_TEXT;
// lParam points to our custom object
lvi.lParam = (LPARAM)pItem;
SendMessage(g_hwndLV, LVM_INSERTITEM, 0, (LPARAM)&lvi);

注意: 在这种情况下,您应该释放由lParam 使用删除

You can use the lParam member of the LVITEM structure to set custom data for you list item:

// custom structure to hold some information
struct listItem {
   int value;
   char path[MAX_PATH];
};

// initialize a custom object to hold a value and a path
LVITEM lvi;
listItem* pItem = new listItem();
pItem->value = 666;
sprintf(pItem->path,"c:\\\\xampp\\htdocs");

// initialize a LVITEM object
memset(&lvi, 0, sizeof(lvi)),
lvi.pszText = "My Folder";
lvi.mask = LVIF_PARAM | LVIF_TEXT;
// lParam points to our custom object
lvi.lParam = (LPARAM)pItem;
SendMessage(g_hwndLV, LVM_INSERTITEM, 0, (LPARAM)&lvi);

Note: In this case you should free the memory pointed to by lParam using delete.

你怎么这么可爱啊 2024-12-26 22:49:06

您可以使用 CListCtrl 设置任意数据: :SetItemData,但您应该使用方法 CListCtrl::InsertItem 而不是使用 PostMessage (这是一个低级的Win32 调用,而不是 MFC)。

You can set arbitrary data with CListCtrl::SetItemData, but you should use the method CListCtrl::InsertItem instead of using PostMessage (which is a low-level Win32 call, not MFC).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文