我正在尝试将ListView项目从我的程序拖放到另一个项目(例如将路径拖到VLC的某个位置,然后播放视频文件).我正在使用CF_HDROP剪贴板格式.CopySelection是将STGMEDIUM hglobal变量设置为DROPFILES结构的原因.
void CopySelection(HWND hwndList, STGMEDIUM &stgmed)
{
HGLOBAL hMem;
DROPFILES *ptr;
DROPFILES dfiles;
POINT p;
// get the selection inside the list control
int iPos = SendMessage(hwndList, LVM_GETNEXTITEM, (WPARAM)-1,(LPARAM)LVNI_SELECTED);
cout << "iPos: " << iPos << endl;
LVITEM item;
char buffer[256];
string fileDir = "";
item.iItem = iPos;
item.iSubItem = 1;
item.cchTextMax = 256;
item.pszText = buffer;
item.mask = LVIF_TEXT;
ListView_GetItem(hwndList, &item);
fileDir += string(item.pszText);
fileDir += "\\";
item.iItem = iPos;
item.iSubItem = 0;
ListView_GetItem(hwndList, &item);
fileDir += string(item.pszText); …Run Code Online (Sandbox Code Playgroud)