unit dragf; (* dragf - example to show how to accept filenames form other application. This form accepts draggin from other program cabable to drag filenames (f.ex Explorer). The names are just shown in a listbox. In real application replace ListBox.Items.Add(name) by something real, like opening the file. Vesa Lappalainen 18.7.1999 See also the component version of this same: kDragTarget.pas *) interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFormDrag = class(TForm) ListBoxNames: TListBox; ButtonClear: TButton; procedure FormCreate(Sender: TObject); procedure ButtonClearClick(Sender: TObject); private procedure HandleDrag(var Message: TMessage); message WM_DROPFILES; public end; var FormDrag: TFormDrag; implementation {$R *.DFM} uses ShellApi; procedure TFormDrag.FormCreate(Sender: TObject); begin DragAcceptFiles(Handle,true); // Needed so that the form accepts files end; procedure TFormDrag.HandleDrag(var Message: TMessage); var hd : HDROP; i,n:integer; name:string; begin hd := Message.WParam; n := DragQueryFile(hd,UINT(-1),nil,0); // Get number of items for i:=0 to n-1 do begin SetLength(name,500); // Enough space for name DragQueryFile(hd,i,PChar(name),500); // Ask the next name name := StrPas(PChar(name)); // NULL-trem string to Pascal ListBoxNames.Items.Add(name); // Add the name to listbox end; DragFinish(hd); // Release the memory! end; procedure TFormDrag.ButtonClearClick(Sender: TObject); begin ListBoxNames.Clear; end; end.