[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1092
  • Last Modified:

Drag and Drop to Listbox

Hi all,

I need to be able to Drag and Drop multiple files from explorer to the listbox.

When the files are dropped on the listbox I need the path+exe name of the files on the listbox added.

Hope you can help!

Thanks

ST3VO
0
ST3VO
Asked:
ST3VO
  • 3
1 Solution
 
diniludCommented:
Unit1.dfm
==========

object Form1: TForm1
  Left = 74
  Top = 101
  Width = 502
  Height = 316
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object ListBox1: TListBox
    Left = 8
    Top = 8
    Width = 473
    Height = 257
    ItemHeight = 13
    TabOrder = 0
  end
end

Unit1.pas
========

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
     originalPanelWindowProc : TWndMethod;
     procedure ListBoxWindowProc (var Msg : TMessage) ;
     procedure ListBoxDrop (var Msg : TWMDROPFILES) ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses ShellApi;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
   originalPanelWindowProc := ListBox1.WindowProc;
   ListBox1.WindowProc := ListBoxWindowProc;

   DragAcceptFiles(ListBox1.Handle,true) ;
end;

procedure TForm1.ListBoxWindowProc(var Msg: TMessage) ;
begin
   if Msg.Msg = WM_DROPFILES then
     ListBoxDrop(TWMDROPFILES(Msg))
   else
     originalPanelWindowProc(Msg) ;
end;

procedure TForm1.ListBoxDrop(var Msg: TWMDROPFILES) ;
var
   i,numFiles : longInt;
   buffer : array[0..MAX_PATH] of char;
begin
   numFiles := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0) ;
    for i:=0 to numFiles-1 do
    begin
     DragQueryFile(Msg.Drop, i, @buffer, sizeof(buffer)) ;
     ListBox1.Items.Add(buffer);
    end;
end;

end.
0
 
diniludCommented:
is my eg is not working?
0
 
ST3VOAuthor Commented:
hI dinilud,

Yes, it works to perfection...thanks!!!

-ST3VO
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now