Link to home
Start Free TrialLog in
Avatar of DanishB
DanishB

asked on

Tricky drag&drop problem

How do you get the path where the fileobject was dropped ?

The WinZip program does it. You can drag files from a ZIP file and drop them to the Windows Explorer. It can't do this with out knowing the destination path !

Maybe one could use :

DragQueryPoint -> WindowFromPoint -> GetWindowText

BUT

you can only get the directory name that way NOT the full path plus what if you drop the object on a directory not just inside a directory.


Thanks
Avatar of Madshi
Madshi

Hmm. Perhaps this helps:

http://www.wideman-one.com/tech/Delphi/index.htm

There's an explanation about how to use Drag&Drop functions.

Regards, Madshi.
ASKER CERTIFIED SOLUTION
Avatar of williams2
williams2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunally I coudn't find my code of it. I think you have to use the IDragDrop interface of the windows shell. There you can get even more information about the drag'n'drop operation.

regards ptm.
ptm: This is exactly what the drag'n'drop components will do, but there's a lot of stuff to take care of when doing the implementation directly.

Cheers,
Williams
Avatar of DanishB

ASKER

Thanks. I have tried the drag&drop components BUT I still can't
get the destination drop path. With the components I can program
the same thing WinZip does but I can't do any postprocessing in
that path because I don't know where the files where dropped.

DanishB

I think you can. You can use the TDropSource1.OnDrop event procedure to get the files (with paths). It sure works for me.

I think you should do like i do for example like:

procedure TForm1.DropFileSource1Drop(Sender: TObject; DragType: TDragType;
  var ContinueDrop: Boolean);
begin
  ShowMessage(DropFileSource1.Files[0]);
end;

procedure TForm1.DropFileTarget1Drop(Sender: TObject; DragType: TDragType;
  X, Y: Integer);
begin
  ShowMessage(DropFileTarget1.Files[0]);
end;


remember to use the register(Self) methods on creation and  Unregister on desctruction (.OnDestroy) ..else nothing will work at all.

Regards,
Williams
Avatar of DanishB

ASKER

You are right :) Thanks alot.

DanishB

Avatar of DanishB

ASKER

To Williams2 :

I must have been sleeping when I wrote the above. It does not
work. If I drag a file from my program ex. "C:\backup\test.txt" to Windows Explorer in "e:\testdir\" I can only get the "C:\backup\test.txt" NOT the destination drop path "e:\testdir\" !

DropFileSource1.Files[0] gives me "C:\backup\test.txt".


DanishB

Wait, I'll have to do some more experiementing with this ..but anyway, you don't have to worry much about this, because, you will only need to do the handling of building the file, then release the drop and let the OLE COM do the rest.

BTW: What exxactly are you planning to do?
Avatar of DanishB

ASKER

I need it for a installation program. The "things" you can install are all represented by a little picture. So as an alternative to asking the user to enter a directory (browse)
he can just drag&drop the little picture to the path where
he wants it. A installation script has to be executed in the installation directory (postprocessing).




I see.. I'll see what I can do about it..

Regards,
Williams
Hej drenge...

I'm the author of the Drag and Drop Component Suite.

I assume that you found the Extract demo on my home page - the one that uses the same technique as WinZip.

Unfortunately, as you correctly concluded, this alone can not solve your problem. To my knowledge (and I know a lot <g>), it is not possible for the drop source to get any information at all about the drop destination.

The only solution I can think of is to install a temporary copy hook handler which monitors the file you have created in the temp directory (using the WinZip technique). When the file is dropped and the explorer moves the files to its new destination (the folder where the user dropped it), you will receive notification of the new path.

To learn about copy hook handlers, check out Delphi's ShellExt demo application (delphi\demos\ActiveX\ShellExt) and specifically the ICopyHook interface.
Hey, and another Delphi homepage / component creator!! Anders, welcome to the EE family...   :-)

Regards, Madshi.
Velkommen Anders !

Oh yeah,

Quite an honor to see some real gurus around this place :-)

...I hope to see you around this area in the future as I can promise, that you will get lot's of challenges. This board is the very reason why I know as much as I know today about programming Delphi.. So say hello to my friends here, I'm sure they will make you feel comfortable ..and busy! ;-)

Regards,
Williams
Thanks.

I don't think I'll be here much. I just followed a link in the referrer log of my web server.

I use most of my spare (computer) time on my components and on the Delphi newsgroups.
I hope you got no problem with me posting the link to your site as I do not find it suitable to dumb them inside a mail. But else I could refer to your website instead.

Regdards,
Williams
No problem at all.