Reputation: 179
I wrote a demo containing a TListView (m_ListView
). It shows my files on the D:\
drive. If I drag a TListItem in m_ListView
and drop it on the E:\
drive, the selected file will be copied to E:\
. This works well, but something is wrong with the end of the drag.
When I do the drag&drop and release my left button when the mouse is hovering over E:\
, there will be a shade like in this picture (the file has been copied!):
To perform another drag&drop action, I have to click on my TListView again.
What should I do to eliminate this?
I tried using ReleaseCapture()
, but that didn't work (or I didn't use it correctly).
Main code:
void _fastcall MC_OLEDragHelper::MyListStartDrag(TObject* vSender, TDragObject*& vDragObject)
{
int tCount = (int)m_ListView->Items->Count;
MT_FileList tFileList;
for(int i=0; i<tCount; i++)
{
TListItem* tItem = m_ListView->Items->Item[i];
if(false == tItem->Selected)
continue;
KKSTR tFileName = m_ListViewDragKit->OnItemDragOut(tItem);
if(true == tFileName.empty())
continue;
tFileList.push_back(tFileName);
}
//Call DoDragDrop
DropFiles(&tFileList, DROPEFFECT_COPY);
return;
}
DropFiles()
function:
bool MC_OLEDragHelper::DropFiles(MT_FileList* vFileList, DWORD vDesireEffect)
{
if(false == m_Available)
return false;
if(0 == vFileList->size())
return false;
void* tDropfiles = (DROPFILES*)CreateFileDespListItem(vFileList);
FORMATETC tFormatEtc = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
STGMEDIUM tStorageMedium = {TYMED_HGLOBAL, {(HBITMAP)tDropfiles}, 0};
m_DragItemList->Add(&tFormatEtc, &tStorageMedium, 1);
DWORD tDropEffect;
DWORD tDragResult = DoDragDrop(m_DragItemList, m_DropSource, vDesireEffect, &tDropEffect);
bool tRetVal = false;
if(tDragResult != DRAGDROP_S_DROP)
goto WORK_END;
if(tDropEffect == DROPEFFECT_NONE)
goto WORK_END;
tRetVal = true;
WORK_END:
ReleaseStgMedium(&tStorageMedium);
DestroyFileDespListItem(HGLOBAL(tDropfiles));
m_ListView->EndDrag(true);
return tRetVal;
}
Upvotes: 0
Views: 189