forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropListBox.pas
118 lines (103 loc) · 2.57 KB
/
DropListBox.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
unit DropListBox;
{
Inno Setup
Copyright (C) 1997-2019 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
This unit provides a listbox with drop files support.
}
interface
uses
StdCtrls,
Messages;
type
TDropListBox = class;
TDropFileEvent = procedure(Sender: TDropListBox; const FileName: String) of object;
TDropListBox = class(TCustomListBox)
private
FOnDropFile: TDropFileEvent;
protected
procedure CreateWnd; override;
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
published
property Align;
property Anchors;
property BorderStyle;
property Color;
property Columns;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property ExtendedSelect;
property Font;
property ImeMode;
property ImeName;
property IntegralHeight;
property ItemHeight;
property Items;
property MultiSelect;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property Style;
property TabOrder;
property TabStop;
property TabWidth;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropFile: TDropFileEvent read FOnDropFile write FOnDropFile;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
procedure Register;
implementation
uses
Classes,
Windows, ShellAPI;
procedure TDropListBox.CreateWnd;
begin
inherited;
if csDesigning in ComponentState then
Exit;
DragAcceptFiles(Handle, True);
end;
procedure TDropListBox.WMDropFiles(var Msg: TWMDropFiles);
var
FileName: array[0..MAX_PATH] of Char;
I, FileCount: Integer;
begin
try
if Assigned(FOnDropFile) then begin
FileCount := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);
for I := 0 to FileCount-1 do
if DragQueryFile(Msg.Drop, I, FileName, SizeOf(FileName)) > 0 then
FOnDropFile(Self, FileName);
end;
Msg.Result := 0;
finally
DragFinish(Msg.Drop);
end;
end;
procedure Register;
begin
RegisterComponents('JR', [TDropListBox]);
end;
end.