如何编写一个支持拖放操作的ListBox,就是把文件拖放入ListBox时,ListBox显示这些文件的全路径+文件名 处理一个windows消息就行了,对不起,我忘了... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //componet pasunit DropFiles;//E-Mail: [email protected] Messages, Windows, SysUtils, Controls, Forms, Classes, Menus, Graphics, StdCtrls, ShellApi, ComCtrls;type TDropFilesEvent = procedure(Sender: TObject; X, Y: Integer; FileNames: TStrings) of object;type TDropFilesMemo = class(TCustomMemo) private FCanDropFiles: Boolean; FOnDropFiles: TDropFilesEvent; procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES; procedure SetCanDropFiles(const Value: Boolean); published property Align; property Alignment; property Anchors; property BevelEdges; property BevelInner; property BevelKind default bkNone; property BevelOuter; property BiDiMode; property BorderStyle; property Color; property Constraints; property Ctl3D; property DragCursor; property DragKind; property DragMode; property Enabled; property Font; property HideSelection; property ImeMode; property ImeName; property Lines; property MaxLength; property OEMConvert; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PopupMenu; property ReadOnly; property ScrollBars; property ShowHint; property TabOrder; property TabStop; property Visible; property WantReturns; property WantTabs; property WordWrap; property OnChange; property OnClick; property OnContextPopup; property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnStartDock; property OnStartDrag; property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles; property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles; end; TDropFilesEdit = class(TCustomEdit) private FCanDropFiles: Boolean; FOnDropFiles: TDropFilesEvent; procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES; procedure SetCanDropFiles(const Value: Boolean); published property Anchors; property AutoSelect; property AutoSize; property BevelEdges; property BevelInner; property BevelKind default bkNone; property BevelOuter; property BiDiMode; property BorderStyle; property CharCase; property Color; property Constraints; property Ctl3D; property DragCursor; property DragKind; property DragMode; property Enabled; property Font; property HideSelection; property ImeMode; property ImeName; property MaxLength; property OEMConvert; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PasswordChar; property PopupMenu; property ReadOnly; property ShowHint; property TabOrder; property TabStop; property Text; property Visible; property OnChange; property OnClick; property OnContextPopup; property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnStartDock; property OnStartDrag; property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles; property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles; end; TDropFilesRichEdit = class(TCustomRichEdit) private FCanDropFiles: Boolean; FOnDropFiles: TDropFilesEvent; procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES; procedure SetCanDropFiles(const Value: Boolean); published property Align; property Alignment; property Anchors; property BevelEdges; property BevelInner; property BevelOuter; property BevelKind default bkNone; property BevelWidth; property BiDiMode; property BorderStyle; property BorderWidth; property Color; property Ctl3D; property DragCursor; property DragKind; property DragMode; property Enabled; property Font; property HideSelection; property HideScrollBars; property ImeMode; property ImeName; property Constraints; property Lines; property MaxLength; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PlainText; property PopupMenu; property ReadOnly; property ScrollBars; property ShowHint; property TabOrder; property TabStop default True; property Visible; property WantTabs; property WantReturns; property WordWrap; property OnChange; property OnContextPopup; property OnDragDrop; property OnDragOver; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnMouseWheel; property OnMouseWheelDown; property OnMouseWheelUp; property OnProtectChange; property OnResizeRequest; property OnSaveClipboard; property OnSelectionChange; property OnStartDock; property OnStartDrag; property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles; property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles; end; TDropFilesListBox = class(TCustomListBox) procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES; procedure SetCanDropFiles(const Value: Boolean); private FCanDropFiles: Boolean; FOnDropFiles: TDropFilesEvent; published property Style; property AutoComplete; property Align; property Anchors; property BevelEdges; property BevelInner; property BevelKind default bkNone; property BevelOuter; property BiDiMode; property BorderStyle; property Color; property Columns; property Constraints; property Ctl3D; property DragCursor; property DragKind; property DragMode; property Enabled; property ExtendedSelect; property Font; property ImeMode; property ImeName; property IntegralHeight; property ItemHeight; property Items; property MultiSelect; property ParentBiDiMode; property ParentColor; property ParentCtl3D; property ParentFont; property ParentShowHint; property PopupMenu; property ScrollWidth; property ShowHint; property Sorted; property TabOrder; property TabStop; property TabWidth; property Visible; property OnClick; property OnContextPopup; property OnData; property OnDataFind; property OnDataObject; property OnDblClick; property OnDragDrop; property OnDragOver; property OnDrawItem; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMeasureItem; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnStartDock; property OnStartDrag; property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles; property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles; end;procedure Register;implementationprocedure Register;begin RegisterComponents('Zsoft', [TDropFilesMemo, TDropFilesEdit, TDropFilesRichEdit]);end;{ TDropFilesMemo }procedure TDropFilesMemo.SetCanDropFiles(const Value: Boolean);begin FCanDropFiles := Value; DragAcceptFiles(Handle, FCanDropFiles);end;procedure TDropFilesMemo.WMDropFiles(var Msg: TMessage);var I, FilesCount: Integer; FileName: array[0..MAX_PATH] of Char; Point: TPoint; FilesNames: TStringList;begin if Assigned(FOnDropFiles) then begin FilesNames := TStringList.Create; try FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0); DragQueryPoint(THandle(Msg.wParam), Point); for I := 0 to FilesCount - 1 do begin DragQueryFile(THandle(Msg.wParam), I, FileName, SizeOf(FileName)); FilesNames.Add(FileName); end; FOnDropFiles(Self, Point.X, Point.Y, FilesNames); finally FilesNames.Free; end; end; Msg.Result := 0; DragFinish(THandle(Msg.wParam));end;{ TDropFilesEdit }procedure TDropFilesEdit.SetCanDropFiles(const Value: Boolean);begin FCanDropFiles := Value; DragAcceptFiles(Handle, FCanDropFiles);end;procedure TDropFilesEdit.WMDropFiles(var Msg: TMessage);var I, FilesCount: Integer; FileName: array[0..MAX_PATH] of Char; Point: TPoint; FilesNames: TStringList;begin if Assigned(FOnDropFiles) then begin FilesNames := TStringList.Create; try FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0); DragQueryPoint(THandle(Msg.wParam), Point); for I := 0 to FilesCount - 1 do begin DragQueryFile(THandle(Msg.wParam), I, FileName, SizeOf(FileName)); FilesNames.Add(FileName); end; FOnDropFiles(Self, Point.X, Point.Y, FilesNames); finally FilesNames.Free; end; end; Msg.Result := 0; DragFinish(THandle(Msg.wParam));end;{ TDropFilesRichEdit }procedure TDropFilesRichEdit.SetCanDropFiles(const Value: Boolean);begin FCanDropFiles := Value; DragAcceptFiles(Handle, FCanDropFiles);end;procedure TDropFilesRichEdit.WMDropFiles(var Msg: TMessage);var I, FilesCount: Integer; FileName: array[0..MAX_PATH] of Char; Point: TPoint; FilesNames: TStringList;begin if Assigned(FOnDropFiles) then begin FilesNames := TStringList.Create; try FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0); DragQueryPoint(THandle(Msg.wParam), Point); for I := 0 to FilesCount - 1 do begin DragQueryFile(THandle(Msg.wParam), I, FileName, SizeOf(FileName)); FilesNames.Add(FileName); end; FOnDropFiles(Self, Point.X, Point.Y, FilesNames); finally FilesNames.Free; end; end; Msg.Result := 0; DragFinish(THandle(Msg.wParam));end;{ TDropFilesListBox }procedure TDropFilesListBox.SetCanDropFiles(const Value: Boolean);begin FCanDropFiles := Value; DragAcceptFiles(Handle, FCanDropFiles);end;procedure TDropFilesListBox.WMDropFiles(var Msg: TMessage);var I, FilesCount: Integer; FileName: array[0..MAX_PATH] of Char; Point: TPoint; FilesNames: TStringList;begin if Assigned(FOnDropFiles) then begin FilesNames := TStringList.Create; try FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0); DragQueryPoint(THandle(Msg.wParam), Point); for I := 0 to FilesCount - 1 do begin DragQueryFile(THandle(Msg.wParam), I, FileName, SizeOf(FileName)); FilesNames.Add(FileName); end; FOnDropFiles(Self, Point.X, Point.Y, FilesNames); finally FilesNames.Free; end; end; Msg.Result := 0; DragFinish(THandle(Msg.wParam));end;end.//demo pasunit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DropFiles;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FDropFilesListBox: TDropFilesListBox; procedure DropFilesListBoxDropFiles(Sender: TObject; X, Y: Integer; FileNames: TStrings); public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DropFilesListBoxDropFiles(Sender: TObject; X, Y: Integer; FileNames: TStrings);begin TListBox(Sender).Items.Assign(FileNames);end;procedure TForm1.FormCreate(Sender: TObject);begin FDropFilesListBox := TDropFilesListBox.Create(Self); FDropFilesListBox.Parent := Self; FDropFilesListBox.Width := 200; FDropFilesListBox.Height := 100; FDropFilesListBox.CanDropFiles := True; FDropFilesListBox.OnDropFiles := DropFilesListBoxDropFiles;end;procedure TForm1.FormDestroy(Sender: TObject);begin FDropFilesListBox.Free;end;end. unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) ListBox1: TListBox; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } procedure WMDropFiles(var Message: TMessage); message WM_DropFiles; end;var Form1: TForm1;implementation{$R *.dfm}uses ShellApi;procedure TForm1.WMDropFiles(var Message: TMessage);var sFileName: array [0..255] of char; iIndex, iCount: integer;begin iIndex := -1; iCount := DragQueryFile(Message.WParam, iIndex, sFileName, 255); for iIndex := 0 to iCount - 1 do begin DragQueryFile(Message.WParam, iIndex, sFileName, 255); ListBox1.Items.Add(sFileName); end; DragFinish(Message.WParam);end;procedure TForm1.FormCreate(Sender: TObject);begin DragAcceptFiles(Handle, true);end;end. cxgrid导出EXCEL文件后,打开导出文件有出错提示,不知为什么? 为什么我关不掉QQ? 请教一个关于使用Treeview的节点Data出错原因 毕设求助各位大侠 :) delphi 6中DBGrid数据导出到Excel中,老是把DBGrid中的第一行的值赋给了Excel的其他所有涉及到的单元格? 请教一个简单的问题 DBLookupCombobox问题 急聘一师傅 一个NMUDP的问题 能否在客户端控制服务器端的串口设备? 怎么样在程序中动态的产生SQL语句的参数?怎么样调用? 怎样设置installshield使安装后的程序出现在开始菜单?
//E-Mail: [email protected]
Messages, Windows, SysUtils, Controls, Forms, Classes, Menus, Graphics,
StdCtrls, ShellApi, ComCtrls;type
TDropFilesEvent = procedure(Sender: TObject; X, Y: Integer; FileNames: TStrings) of object;type
TDropFilesMemo = class(TCustomMemo)
private
FCanDropFiles: Boolean;
FOnDropFiles: TDropFilesEvent;
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure SetCanDropFiles(const Value: Boolean);
published
property Align;
property Alignment;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property Lines;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property WantReturns;
property WantTabs;
property WordWrap;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles;
property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles;
end; TDropFilesEdit = class(TCustomEdit)
private
FCanDropFiles: Boolean;
FOnDropFiles: TDropFilesEvent;
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure SetCanDropFiles(const Value: Boolean);
published
property Anchors;
property AutoSelect;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property CharCase;
property Color;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property ImeMode;
property ImeName;
property MaxLength;
property OEMConvert;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles;
property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles;
end; TDropFilesRichEdit = class(TCustomRichEdit)
private
FCanDropFiles: Boolean;
FOnDropFiles: TDropFilesEvent;
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure SetCanDropFiles(const Value: Boolean);
published
property Align;
property Alignment;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Color;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HideScrollBars;
property ImeMode;
property ImeName;
property Constraints;
property Lines;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PlainText;
property PopupMenu;
property ReadOnly;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop default True;
property Visible;
property WantTabs;
property WantReturns;
property WordWrap;
property OnChange;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnProtectChange;
property OnResizeRequest;
property OnSaveClipboard;
property OnSelectionChange;
property OnStartDock;
property OnStartDrag;
property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles;
property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles;
end; TDropFilesListBox = class(TCustomListBox)
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
procedure SetCanDropFiles(const Value: Boolean);
private
FCanDropFiles: Boolean;
FOnDropFiles: TDropFilesEvent;
published
property Style;
property AutoComplete;
property Align;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property BiDiMode;
property BorderStyle;
property Color;
property Columns;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property ExtendedSelect;
property Font;
property ImeMode;
property ImeName;
property IntegralHeight;
property ItemHeight;
property Items;
property MultiSelect;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ScrollWidth;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property TabWidth;
property Visible;
property OnClick;
property OnContextPopup;
property OnData;
property OnDataFind;
property OnDataObject;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property CanDropFiles: Boolean read FCanDropFiles write SetCanDropFiles;
property OnDropFiles: TDropFilesEvent read FOnDropFiles write FOnDropFiles;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Zsoft', [TDropFilesMemo, TDropFilesEdit, TDropFilesRichEdit]);
end;{ TDropFilesMemo }procedure TDropFilesMemo.SetCanDropFiles(const Value: Boolean);
begin
FCanDropFiles := Value;
DragAcceptFiles(Handle, FCanDropFiles);
end;procedure TDropFilesMemo.WMDropFiles(var Msg: TMessage);
var
I, FilesCount: Integer;
FileName: array[0..MAX_PATH] of Char;
Point: TPoint;
FilesNames: TStringList;
begin
if Assigned(FOnDropFiles) then begin
FilesNames := TStringList.Create;
try
FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0);
DragQueryPoint(THandle(Msg.wParam), Point);
for I := 0 to FilesCount - 1 do begin
DragQueryFile(THandle(Msg.wParam), I, FileName,
SizeOf(FileName));
FilesNames.Add(FileName);
end;
FOnDropFiles(Self, Point.X, Point.Y, FilesNames);
finally
FilesNames.Free;
end;
end;
Msg.Result := 0;
DragFinish(THandle(Msg.wParam));
end;{ TDropFilesEdit }procedure TDropFilesEdit.SetCanDropFiles(const Value: Boolean);
begin
FCanDropFiles := Value;
DragAcceptFiles(Handle, FCanDropFiles);
end;procedure TDropFilesEdit.WMDropFiles(var Msg: TMessage);
var
I, FilesCount: Integer;
FileName: array[0..MAX_PATH] of Char;
Point: TPoint;
FilesNames: TStringList;
begin
if Assigned(FOnDropFiles) then begin
FilesNames := TStringList.Create;
try
FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0);
DragQueryPoint(THandle(Msg.wParam), Point);
for I := 0 to FilesCount - 1 do begin
DragQueryFile(THandle(Msg.wParam), I, FileName,
SizeOf(FileName));
FilesNames.Add(FileName);
end;
FOnDropFiles(Self, Point.X, Point.Y, FilesNames);
finally
FilesNames.Free;
end;
end;
Msg.Result := 0;
DragFinish(THandle(Msg.wParam));
end;{ TDropFilesRichEdit }procedure TDropFilesRichEdit.SetCanDropFiles(const Value: Boolean);
begin
FCanDropFiles := Value;
DragAcceptFiles(Handle, FCanDropFiles);
end;procedure TDropFilesRichEdit.WMDropFiles(var Msg: TMessage);
var
I, FilesCount: Integer;
FileName: array[0..MAX_PATH] of Char;
Point: TPoint;
FilesNames: TStringList;
begin
if Assigned(FOnDropFiles) then begin
FilesNames := TStringList.Create;
try
FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0);
DragQueryPoint(THandle(Msg.wParam), Point);
for I := 0 to FilesCount - 1 do begin
DragQueryFile(THandle(Msg.wParam), I, FileName,
SizeOf(FileName));
FilesNames.Add(FileName);
end;
FOnDropFiles(Self, Point.X, Point.Y, FilesNames);
finally
FilesNames.Free;
end;
end;
Msg.Result := 0;
DragFinish(THandle(Msg.wParam));
end;{ TDropFilesListBox }procedure TDropFilesListBox.SetCanDropFiles(const Value: Boolean);
begin
FCanDropFiles := Value;
DragAcceptFiles(Handle, FCanDropFiles);
end;procedure TDropFilesListBox.WMDropFiles(var Msg: TMessage);
var
I, FilesCount: Integer;
FileName: array[0..MAX_PATH] of Char;
Point: TPoint;
FilesNames: TStringList;
begin
if Assigned(FOnDropFiles) then begin
FilesNames := TStringList.Create;
try
FilesCount := DragQueryFile(THandle(Msg.wParam), Cardinal(-1), nil, 0);
DragQueryPoint(THandle(Msg.wParam), Point);
for I := 0 to FilesCount - 1 do begin
DragQueryFile(THandle(Msg.wParam), I, FileName,
SizeOf(FileName));
FilesNames.Add(FileName);
end;
FOnDropFiles(Self, Point.X, Point.Y, FilesNames);
finally
FilesNames.Free;
end;
end;
Msg.Result := 0;
DragFinish(THandle(Msg.wParam));
end;end.
//demo pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DropFiles;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FDropFilesListBox: TDropFilesListBox;
procedure DropFilesListBoxDropFiles(Sender: TObject; X, Y: Integer; FileNames: TStrings);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DropFilesListBoxDropFiles(Sender: TObject; X, Y: Integer;
FileNames: TStrings);
begin
TListBox(Sender).Items.Assign(FileNames);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
FDropFilesListBox := TDropFilesListBox.Create(Self);
FDropFilesListBox.Parent := Self;
FDropFilesListBox.Width := 200;
FDropFilesListBox.Height := 100;
FDropFilesListBox.CanDropFiles := True;
FDropFilesListBox.OnDropFiles := DropFilesListBoxDropFiles;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FDropFilesListBox.Free;
end;end.
Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMDropFiles(var Message: TMessage); message WM_DropFiles;
end;var
Form1: TForm1;implementation{$R *.dfm}
uses ShellApi;procedure TForm1.WMDropFiles(var Message: TMessage);
var
sFileName: array [0..255] of char;
iIndex, iCount: integer;
begin
iIndex := -1;
iCount := DragQueryFile(Message.WParam, iIndex, sFileName, 255);
for iIndex := 0 to iCount - 1 do
begin
DragQueryFile(Message.WParam, iIndex, sFileName, 255);
ListBox1.Items.Add(sFileName);
end;
DragFinish(Message.WParam);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, true);
end;end.