G
Guest
Hi, all.
I want my program act as an drag source and do drag and drop asynchronously.
So, I created a class CDataObject which implements interfaces IDataObject and IAsyncOperation.
To begin drag and drop, I wrote the following code:
CDataObject* pDataObj = new CDataObject(...);
if (pDataObj)
{
OleFlushClipboard();
HRESULT hr = pDataObj->QueryInterface(IID_IDataObject,(LPVOID*)&m_pMyDataObj);
pDataObj->Release();
if (SUCCEEDED(hr) && m_pMyDataObj){
HRESULT hr = pDataObj->QueryInterface(IID_IAsyncOperation,(LPVOID*)&m_pAsyncOp);
if(SUCCEEDED(hr)){
m_pAsyncOp->SetAsyncMode(VARIANT_TRUE);
IDropSource *pDropSrc = (IDropSource *) new CDropSource;
DWORD dwEffect = 0;
DoDragDrop(m_pMyDataObj,
pDropSrc,
DROPEFFECT_COPY | DROPEFFECT_MOVE,
&dwEffect);
m_pMyDataObj->Release();
pDropSrc->Release();
...
}
}
}
According to MSDN, if AsyncMode is set to VARIANT_TRUE, The drop target (In my program, the only possible target
is Windows explorer) will do drag and drop asynchronously.
Yet, although I set this flag, windows always do drag and drop in the same thread as the UI of my program.
What's wrong with my code? Can any one help me?
Thank you very much!
p.s. I can not understand this line in MSDN, section IAsyncOperation::SetAsyncMode, is this the key problem?
If fDoOpAsync is set to VARIANT_TRUE, SetAsyncMode must call IAsyncOperation::AddRef,
and store the interface pointer for use by IAsyncOperation::EndOperation.
I want my program act as an drag source and do drag and drop asynchronously.
So, I created a class CDataObject which implements interfaces IDataObject and IAsyncOperation.
To begin drag and drop, I wrote the following code:
CDataObject* pDataObj = new CDataObject(...);
if (pDataObj)
{
OleFlushClipboard();
HRESULT hr = pDataObj->QueryInterface(IID_IDataObject,(LPVOID*)&m_pMyDataObj);
pDataObj->Release();
if (SUCCEEDED(hr) && m_pMyDataObj){
HRESULT hr = pDataObj->QueryInterface(IID_IAsyncOperation,(LPVOID*)&m_pAsyncOp);
if(SUCCEEDED(hr)){
m_pAsyncOp->SetAsyncMode(VARIANT_TRUE);
IDropSource *pDropSrc = (IDropSource *) new CDropSource;
DWORD dwEffect = 0;
DoDragDrop(m_pMyDataObj,
pDropSrc,
DROPEFFECT_COPY | DROPEFFECT_MOVE,
&dwEffect);
m_pMyDataObj->Release();
pDropSrc->Release();
...
}
}
}
According to MSDN, if AsyncMode is set to VARIANT_TRUE, The drop target (In my program, the only possible target
is Windows explorer) will do drag and drop asynchronously.
Yet, although I set this flag, windows always do drag and drop in the same thread as the UI of my program.
What's wrong with my code? Can any one help me?
Thank you very much!
p.s. I can not understand this line in MSDN, section IAsyncOperation::SetAsyncMode, is this the key problem?
If fDoOpAsync is set to VARIANT_TRUE, SetAsyncMode must call IAsyncOperation::AddRef,
and store the interface pointer for use by IAsyncOperation::EndOperation.