在主线程中如下代码能正常:
HRESULT hRetSource = DropSource.QueryInterface(IID_IDropSource, (void**)&pDropSource);
HRESULT hRetObject = DataObject.QueryInterface(IID_IDataObject, (void**)&pDataObject);
if ((hRetSource == S_OK) && (hRetObject == S_OK))
{
// DROPEFFECT_XXXX 效果取决于目标
DoDragDrop(pDataObject,
pDropSource,
DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK | DROPEFFECT_SCROLL,
&dwEffect);
}
if (hRetObject == S_OK)
{
DataObject.Release();
}
if (hRetSource == S_OK)
{
DropSource.Release();
}
但上面对于拖放大文件时,用户响应要等到文件操作完成,想改用如下线程,但为什么不能正常,请高手看看。
//开启线程
unsigned threadID = 0;
HANDLE hThread = (HANDLE)_beginthreadex(0, 0, DragDropThread, 0, 0, &threadID);
if (0 != hThread)
{
CloseHandle(hThread);
}
//线程部分
unsigned __stdcall CTreeViewEx::DragDropThread(PVOID lpDragInfo)
{
DWORD dwEffect = 0;
CDataObjectEx DataObject;
CDropSourceEx DropSource;
IDataObject* pDataObject = NULL;
IDropSource* pDropSource = NULL;
HRESULT hRetSource = DropSource.QueryInterface(IID_IDropSource, (void**)&pDropSource);
HRESULT hRetObject = DataObject.QueryInterface(IID_IDataObject, (void**)&pDataObject);
if ((hRetSource == S_OK) && (hRetObject == S_OK))
{
// DROPEFFECT_XXXX 效果取决于目标
DoDragDrop(pDataObject,
pDropSource,
DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_LINK | DROPEFFECT_SCROLL,
&dwEffect);
}
if (hRetObject == S_OK)
{
DataObject.Release();
}
if (hRetSource == S_OK)
{
DropSource.Release();
}
_endthreadex(0);
return 0;
}