在ListView win32 API中获取所选项目

nXq*_*Xqd 6 winapi listview

我尝试创建像资源管理器一样的列表视图项.当我双击它时,我想获得所选项目.

所以我可以使用它来获取路径并找到要显示的文件.我可以通过senddlgmessage在treeview中完成它.但看起来它在listview上不起作用.

Gra*_*ian 16

如果您只是在C++中使用原始ListView控件,则需要执行以下操作:

// Get the first selected item
int iPos = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);
while (iPos != -1) {
    // iPos is the index of a selected item
    // do whatever you want with it

    // Get the next selected item
    iPos = ListView_GetNextItem(hListView, iPos, LVNI_SELECTED);
}
Run Code Online (Sandbox Code Playgroud)

  • 使用ListView_GetItem宏,传入LVITEM结构,并将iItem设置为您感兴趣的项目的索引.出于好奇,为什么要在原始的winapi中执行此操作?如果你必须使用c ++,mfc是一个很大的帮助?如果你可以使用c#,WinForms是一个更大的帮助 (2认同)