-
Notifications
You must be signed in to change notification settings - Fork 20
/
UFileDropper.pas
79 lines (65 loc) · 1.61 KB
/
UFileDropper.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
Unit UFileDropper;
Interface
Uses Classes,Windows,ShellAPI;
// simple class that allow/disallow drag-drop support for window
Type
TDragDropHelper=class
private
wndHandle:HWND;
public
constructor Create(const wnd:HWND);
destructor Destroy; Override;
end;
// simple class that accepts dropped files and stores names + droppoint
TFileDropper=class
private
DropHandle:HDrop;
function GetFile(Index:Integer):AnsiString;
function GetFileCount:Integer;
function GetPoint:TPoint;
public
constructor Create(Handle:HDrop);
destructor Destroy; override;
public
property FileCount:Integer read GetFileCount;
property Files[Index:Integer]:AnsiString read GetFile;
property DropPoint:TPoint read GetPoint;
end;
Implementation
Constructor TDragDropHelper.Create (Const wnd:HWND);
Begin
wndHandle:=wnd;
DragAcceptFiles(wndHandle,True);
end;
Destructor TDragDropHelper.Destroy;
Begin
DragAcceptFiles(wndHandle,False);
Inherited;
end;
Constructor TFileDropper.Create (Handle:HDrop);
Begin
DropHandle:=Handle;
end;
Destructor TFileDropper.Destroy;
Begin
DragFinish(DropHandle);
Inherited;
end;
Function TFileDropper.GetFile (Index:Integer):AnsiString;
Var
FileNameLength:Integer;
Begin
FileNameLength:=DragQueryFile(DropHandle,Index,Nil,0);
SetLength(Result,FileNameLength);
DragQueryFile(DropHandle,Index,PAnsiChar(Result),FileNameLength);
end;
Function TFileDropper.GetFileCount:Integer;
Begin
Result:=DragQueryFile(DropHandle,$FFFFFFFF,Nil,0);
end;
Function TFileDropper.GetPoint:TPoint;
Begin
Result:=Point(0,0);
DragQueryPoint(DropHandle,Result);
end;
End.