473,511 Members | 13,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to do drag and drop asynchronously?

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_pMyDat aObj);
pDataObj->Release();
if (SUCCEEDED(hr) && m_pMyDataObj){
HRESULT hr = pDataObj->QueryInterface(IID_IAsyncOperation,(LPVOID*)&m_pA syncOp);
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.
Nov 17 '05 #1
6 4799
Wei Junping,
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.
I think MSDN says something else. MSDN says that if AsyncMode is set to
VARIANT_TRUE, then the drop target has the *option* of performing data
transfer asychronously. The drop target is not *required* to perform
data transfer 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?
I think there is nothing wrong with your code. "Asynchronous" does not
necessarily mean: "in another thread". It just means that DoDragDrop
does not wait for the data transfer to finish before returning. In any
case, DoDragDrop does not return before the mouse button is released.

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 do not understand this either, but I do not think it is essential.

Greetings

Bart Jacobs

Nov 17 '05 #2
Thank you very much.
But how can I do drag and drop in a new thread?
Nov 17 '05 #3
Wei Junping wrote:
Thank you very much.
But how can I do drag and drop in a new thread?


What do you mean?

Do you want to call DoDragDrop in a thread that is different from the
thread that receives the mouse button down message? That would not make
sense, I think.

Or do you want to handle incoming IDataObject calls in a different
thread? I don't know how to achieve that. But I think in most scenarios
it is possible to handle each such incoming call in such a short amount
of time that the responsiveness of the user interface is not impaired.

Or something else?

Nov 17 '05 #4
I want to handle incoming IDataObject calls in a different thread.
Because In my program, I need to download many files from a remote computer via bluetooth.
Thank you!
Nov 17 '05 #5
COM delivers calls to an object in the apartment in which the object is
created. If the object is created in a single-threaded apartment (such
as the OLE GUI thread in which you call DoDragDrop), then calls are
dispatched on that thread, which is not what you want for your
CDataObject instance. Therefore, create the CDataObject on another
thread and marshal the interface pointer to the GUI thread, so that you
can pass it to DoDragDrop.

I wonder how well drop targets, such as Windows Explorer, cope with
IDataObject calls that take a very long time. Perhaps a better design
would be to offer a separate command in your application to "download"
the file, and to allow only completely downloaded files to be dragged
and dropped. Note that Internet Explorer also does not allow one to
drag-and-drop a remote file directly, and this does not seem to have
been fatal to its acceptance :-)

Nov 17 '05 #6
I follow your suggestion
Yet, DoDragDrop doesn't return until the transfer finishes(I do the tranfer in CDataObject::GetData) even if I have set asyncmode to VARINT_TRUE
What's wrong with it
Can you give me some sample code
Thank you very much!
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2589
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
2
4301
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
10390
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
6
3528
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
3
10561
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
0
1901
by: Rajiv Gupta | last post by:
Hi, We are using Web Parts in ASP.NET 2.0 and also use there drag and drop feature extensively. The issue we are unable to resolve is that we need to avoid is that when a drag and drop happens...
1
4687
by: Darren | last post by:
I'm trying to create a file using drag and drop. I want to be able to select a listview item drag it to the shell and create a file. Each icon in the listview represents a blob in a database. When...
5
13728
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
3461
by: Tom Bean | last post by:
I wrote an C# application that uses drag and drop to copy the contents of one ListViewItem to another. I call DoDragDrop() in the ItemDrag event handler, however, the ItemDrag event is being fired...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.