Today, Delphi is one of the popular desktop programming tool. There are thousand even million programmer in this world using delphi as their favorit tool. This site try to collect the examples, tips and tricks of Delphi programming. We collect, test them and redistribute the collection of delphi programming for you.

Accept the Dropped Files From Windows Explorer

Author: Mike Skholnik | Category: System

// If you need accept the dropped files from the some external application (for
// example, from Windows Explorer), you must call the DragAcceptFiles for your
// form (in which you want to accept) and handle the WM_DROPFILES message.
// I used this algoritm when I wrote the small editor.
// I post the next code as simple example: 
 
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
  protected
    procedure WMDROPFILES (var Msg: TWMDropFiles); message WM_DROPFILES;
  private
  public
  end; 
 
var
  Form1: TForm1; 
 
implementation
uses ShellApi; 
 
{$R *.DFM} 
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Handle, True);
end; 
 
procedure TForm1.WMDROPFILES(var Msg: TWMDropFiles);
var
  i, amount: Integer;
  FileName: array[0..MAX_PATH] of Char;
begin
  inherited; 
 
  try
    Amount := DragQueryFile(Msg.Drop, $FFFFFFFF, FileName, MAX_PATH);
    for i := 0 to (Amount - 1) do
    begin
      DragQueryFile(Msg.Drop, i, FileName, MAX_PATH);
      listbox1.items.add(FileName);
    end;
  finally
    DragFinish(Msg.Drop);
  end;
end;

Tags: ,