Ich weiß nicht genau was dein Ziel ist. Aber das sieht doch mehr als kompliziert aus.
Versuchs mal hiermit:
Delphi-Quellcode:
// FormCreate
DragAcceptFiles(ListBox1.Handle, Accept);
function IsDirectory(const aFileName: string): Boolean;
var
R: DWORD;
begin
R := GetFileAttributes(PChar(aFileName));
Result := (R <> DWORD(-1)) and ((R and FILE_ATTRIBUTE_DIRECTORY) <> 0);
end;
procedure DragDropHandleProcess(Wnd: HWND; aPath: string);
var
bIsPath: Boolean;
begin
bIsPath := IsDirectory(aPath);
if bIsPath and (Wnd = ListBox1.Handle) then
FListBox1.Items.Add(aPath);
end;
// ApplicationEvents aufs Form packen und OnMessage nutzen
const
BufferLength = 255;
var
QtyDroppedFiles, FileIndex: Integer;
pDroppedFilename: array [0 .. BufferLength] of Char;
begin
WM_DROPFILES:
begin
QtyDroppedFiles := DragQueryFile(Msg.WParam, Cardinal(-1), nil, 0);
try
for FileIndex := 0 to QtyDroppedFiles - 1 do
begin
DragQueryFile(Msg.WParam, FileIndex, @pDroppedFilename, BufferLength);
DragDropHandleProcess(Msg.HWND, PChar(@pDroppedFilename));
Break;
end;
finally
DragFinish(Msg.WParam);
Handled := True;
end;
end;
end;