Re: drag & drop from other apps
From: Peter Below (TeamB) (100113.1101_at_compuXXserve.com)
Date: 11/22/03
- Previous message: Olivier Beltrami: "Re: Using WMI to launch an app on another PC"
- In reply to: P.Mach: "drag & drop from other apps"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 Nov 2003 23:38:04 +0100
In article <3fbfa188$1@newsgroups.borland.com>, P.Mach wrote:
> Is there an easy way to drag something from other app and drop it in my app?
> For instance, to drag a file-icon from the Windows Explorer, drop it in my
> app so that my app gets the file name? I have read a few articles on the
> subject, but it seems quite complex. Are there any published samples?
> Thanks for your help.
Making a drop target for files is fairly easy, you call the DragAcceptFiles
API function for a window that should accept dragged files from Explorer and
handle the WM_DROPFILES message to actually get the file(s). A full OLE
drag&drop implementation (needed for things other than files or when you want
to create a drag source) is more involved. Here are a couple of URLs for that.
http://www.melander.dk ( http://users.on.net/johnson/delphi/ as alternative)
http://www.undu.com/LIBS/DnD.zip
http://www.wideman-one.com/gw/tech/Delphi/dragdrop/
OLE Drag and Drop Components http://www.unitoops.com/
Dropping files on a memo.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMemo = class( StdCtrls.TMemo )
private
{ Private declarations }
procedure wmDropFiles( Var msg: TWMDropFiles );
message WM_DROPFILES;
protected
procedure CreateWnd; override;
procedure DestroyWnd; override;
end;
TForm1 = class(TForm)
Memo1: TMemo;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses shellapi;
{$R *.DFM}
{ TMemo }
procedure TMemo.CreateWnd;
begin
inherited;
DragAcceptFiles( handle, true );
end;
procedure TMemo.DestroyWnd;
begin
DragAcceptFiles( handle, false );
inherited;
end;
procedure TMemo.wmDropFiles(var msg: TWMDropFiles);
var
filename: Array [0..MAX_PATH] of Char;
begin
DragQueryFile( msg.Drop, 0, filename, sizeof( filename ));
Lines.Loadfromfile( filename );
DragFinish( msg.Drop );
end;
>
-- Peter Below (TeamB) Use the newsgroup archives : http://www.mers.com/searchsite.html http://www.tamaracka.com/search.htm http://groups.google.com http://www.prolix.be
- Previous message: Olivier Beltrami: "Re: Using WMI to launch an app on another PC"
- In reply to: P.Mach: "drag & drop from other apps"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|