Drag’n’drop files from Windows Explorer


TYPE
TForm1 = CLASS(TForm)
PROCEDURE FormCreate(Sender: TObject);
PRIVATE
PROCEDURE WMDropFiles(VAR Msg: TWMDROPFILES); MESSAGE WM_DROPFILES;
END;
...




PROCEDURE TForm1.FormCreate(Sender: TObject);
BEGIN
DragAcceptFiles(Handle, true);
END;

PROCEDURE TForm1.WMDropFiles(VAR Msg: TWMDROPFILES);
VAR
buf: ARRAY[0..MAX_PATH] OF char;
filename: STRING;
BEGIN
DragQueryFile(Msg.Drop, 0, @buf, sizeof(buf));
DragFinish(Msg.Drop);
filename := STRING(buf);
...
END;