unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm6 =
class(TForm)
Edit1: TEdit;
Edit2: TEdit;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
procedure AppMessage(
var Msg: Tmsg;
var Handled: Boolean);
function IsDropPointInside(
const aDropPoint: TPoint;
const aControl: TControl): Boolean;
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
uses
ShellAPI;
procedure TForm6.AppMessage(
var Msg: Tmsg;
var Handled: Boolean);
const
BufferLength: word = 255;
var
DroppedFilename:
string;
FileIndex: Word;
QtyDroppedFiles: Word;
pDroppedFilename:
array[0..255]
of Char;
DropPoint: TPoint;
begin
if Msg.
Message = WM_DROPFILES
then
begin
FileIndex := $FFFF;
QtyDroppedFiles := DragQueryFile(Msg.WParam, FileIndex, pDroppedFilename, BufferLength);
for FileIndex := 0
to (QtyDroppedFiles - 1)
do
begin
DragQueryFile(Msg.WParam, FileIndex, pDroppedFilename, BufferLength);
DroppedFilename := StrPas(pDroppedFilename);
DropPoint := Msg.pt;
if IsDropPointInside(DropPoint, Edit1)
then
Edit1.Text := DroppedFilename
else if IsDropPointInside(DropPoint, Edit2)
then
Edit2.Text := DroppedFilename;
end;
DragFinish(Msg.WParam);
Handled := true;
end;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Edit1.Handle, true);
DragAcceptFiles(Edit2.Handle, true);
Application.OnMessage := AppMessage;
end;
function TForm6.IsDropPointInside(
const aDropPoint: TPoint;
const aControl: TControl): Boolean;
begin
Result := PtInRect(aControl.ClientRect, aControl.ScreenToClient(aDropPoint));
end;
end.