//-------------------------------------------------------------------------
// Copyright (c) 1999 - Sortland Automasjon <automasjon@sortland.net>
//
// All Rights Reserved
//
// fax: +47 5342 0281   web : http://www.sortland.net
//
// Delphi Snippets : http://www.sortland.net/Delphi/Snippets.htm
//-------------------------------------------------------------------------
unit DropFiles;  //    

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TFormDropFiles = class(TForm)
    Memo1: TMemo;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
  public
    { Public declarations }
  end;

var
  FormDropFiles: TFormDropFiles;

resourcestring
  NoOfFiles='Antall filer :';

implementation

uses
  ShellAPI;

{$R *.DFM}

procedure TFormDropFiles.FormShow(Sender: TObject);
  begin
    DragAcceptFiles(Handle, True);
  end;

procedure TFormDropFiles.WMDropFiles(var Msg: TWMDropFiles);
  var
    FilesDropped, ln, i : Cardinal;
    CFileName: array[0..MAX_PATH] of Char;  // Buffer for filename
  begin
    try
      Memo1.Lines.Clear;
      FilesDropped:= DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
      Memo1.Lines.Add(NoOfFiles + IntToStr(FilesDropped));
      if FilesDropped > 0 then
        for i:=0 to FilesDropped do
          begin
            // ln:= DragQueryFile(Msg.Drop, i, nil, 0); // return required ln
            ln:= DragQueryFile(Msg.Drop, i, CFileName, MAX_PATH);
            if ln > 0 then
              begin
                // Do something with the file, directory, shortcut !
                Memo1.Lines.Add('ln:'+IntToStr(ln)+' <- '+CFileName);
              end;
          end;
      Msg.Result := 0;
    finally
      DragFinish(Msg.Drop);
    end;
  end;

end.

Delphi Snippets - may 1999 - Arnulf Sortland