Witam
Chiałem napisac sobei program, który odczyta z upuszczonego pliku metadą DragAndDrop jego nazwę. No i wyszło mi, ale działa to tylko wtedy jeśli program jest uruchomiony, a plik którego nazwę chce odczytać upuszcze na okienko programu. Teraz chciałbym by można było odczytać nazwę pliku rzeciągając go na ikone programu, który nie jest uruchomiony i nigdzie nie mogę znaleŹć jak to zrobić.
Kod źródłowy:
unit index;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI;
type
TForm1 = class(TForm)
E: TEdit;
CB: TComboBox;
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
var
hDrop: THandle;
FileCount: Integer;
FileNameLength: Integer;
FileName: String;
P : Byte;
begin
hDrop:= Msg.Drop;
try
FileCount:= DragQueryFile(hDrop, $FFFFFFFF, nil, 0);
if FileCount > 1 then
else
begin
FileNameLength:= DragQueryFile(hDrop, 0, nil, 0);
SetLength(FileName, FileNameLength);
DragQueryFile(hDrop, 0, PChar(FileName), FileNameLength + 1);
P:=Pos('\',FileName);
while P>0 do
begin
P:=Pos('\',FileName);
Delete(FileName,1,P);
end;
E.Text := FileName;
end;
finally
DragFinish(hDrop);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var P : TSHFileOpStruct;
begin
DragAcceptFiles(Self.Handle, True);
end;
end.
Proszę o pomoc.
Pozdrawiam