Drag from a Windows Form and Drop in a non-dotNet application.

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I need to add the ability to drag from a Windows Form and drop into a
non dotNet application. For example, having a generated image in my
app that I wish to drag out into explorer as a friendly way to save
it.

I have tried creating the object that I place into the DoDragDrop() by
inheriting the COM interfaces IDropSource and IDataObject with no
luck. If anyone can help I am very much open to suggestions.

Thanks in advance!
Dave
 
Hi Dave,
I need to add the ability to drag from a Windows Form and drop into a
non dotNet application.

Yes, you can do that. .NET applications use the same technology of dragging
and dropping as the others non-.NET applications
For example, having a generated image in my
app that I wish to drag out into explorer as a friendly way to save
it.

IMHO this is not completely possible. Objects D&D over windows explorer or
the desktop may be saved in a so called *shell scrap* files. Those *scarp*
files can contain embedded or linked objects, which afterwards can be linked
or embedded in some container, but IMHO you cannot save the data in some
native format (say if you D&D images in BMP or JPG). To have the explorer
create *scrap* file from data your dragged the datao bject has to carry
CF_EMBEDEDSOURCE and/or CF_LINKSOURCE data on it. But to open *scarp* files
your application has to be OLE container. There are other options for
*cached data formats* and *delay rendering* of course but anyways you cannot
save the data in any format you want. The data will be saved in *shell
scrap* files.
I have tried creating the object that I place into the DoDragDrop() by
inheriting the COM interfaces IDropSource and IDataObject with no
luck.

You don't need to create your own classes and inherit IDataObject You can
use DataObject class provided by the framework. This class is all you need
to make D&D and store data in the clipboard.

If you want to read more for *shell scrap* files you can find some info in
MSDN
ms-help://MS.MSDNQTR.2003FEB.1033/shellcc/platform/shell/programmersguide/sh
ell_basics/shell_basics_programming/transferring/datascenarios.htm#scrap

HTH
B\rgds
100
 
Thank you 100 for your response. =) The ms-help isn't registered on
the computer I am currently on, but I believe I did find a similar, if
not the same article on MSDN.
http://msdn.microsoft.com/library/d...cs_programming/transferring/datascenarios.asp

I have read it and gained a some valuable insight.

The dragging of the image to the desktop was really just an example
that I thought of when asking the question. It may not have been as
proper of an example as I thought.

What I am trying to do is to use the mshtml stuff inside my .Net
application. I currently have it doing quite a bit, but the one thing
I cannot get it to do is accept a dragged string from my application.
Strings from non-dotNet apps are accepted just fine by it, but not
from any dotNet app that I have tried. This is the reason I was
attempting to use the COM IDropSource and IDataObject to create a
somewhat non-dotNet object to drop. One of the first things that I
tried was the .net DataObject that you spoke of, but that did not
help. =(

Thank you,
Dave
 
Hi Dave,
Thank you 100 for your response. =) The ms-help isn't registered on
the computer I am currently on, but I believe I did find a similar, if
not the same article on MSDN.
http://msdn.microsoft.com/library/d...cs_programming/transferring/datascenarios.asp

Yes, this is the same article I was talking about.
What I am trying to do is to use the mshtml stuff inside my .Net
application. I currently have it doing quite a bit, but the one thing
I cannot get it to do is accept a dragged string from my application.
Strings from non-dotNet apps are accepted just fine by it, but not
from any dotNet app that I have tried. This is the reason I was
attempting to use the COM IDropSource and IDataObject to create a
somewhat non-dotNet object to drop. One of the first things that I
tried was the .net DataObject that you spoke of, but that did not
help. =(

Actually what the drop target sees is COM interfaces so using DataObject or
not should be the same.

Reading you post I guess that the problem is in the data formats you
receive. It looks like your program is looking for format that don't exist
when you drag out from you application. Usually, programs like MSWord or
WordPad provide very rich dataobjects in terms of data formats. Thus the
chances that you find the format you want are big.

For example when I look at what the DataObject has when I set simple text I
get:
- System.String - this won't be understand by non-.NET application
- Unknown Clipboard Format
- CF_TEXT - almost all application will understand that

If you are not looking for any of the formats above you will not be able to
accept anything dropped form .NET application.

So, my suggestion is to use IDataObject-Viewer tool to check what the
differences in the formats comming form .NET and non-.NET applications are.
In cases that you haven't use that tool you can find it in the VS .NET
folder
in my computer it is located in
C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\Bin\dobjview.exe

Just drag and drop some stuff on the tool window and it will show formats
the data carries.
And then you can make sure that your .NET application puts the same format
in the DataObject.
You said *mshtml stuff* if you are looking for HTML data format you'll find
such data comming from MSWord or IE for example but you won't find it if you
have string containing na HTML page and just do
new DataObject(str);
You should do
new DataObject(DataFormats,Html, str);

So make sure that the format(s) you are looking for comes when the drag is
originated from your application

HTH
B\rgds
100
 
100, Thank you again for your post. I was not aware of the tool you
mentioned. I briefly looked into it, and at first glance appears to be
exactly what I need to figure this out. Thank you again for all your
help. =)

Dave
 
Back
Top