Get the name and extension of selected file in active window by delphi
<p>I want to get and show the name and extension of selected file in explorer by delphi7.</p>

<p>I use below code for show caption of active window but i need selected file name in active window.</p>

<pre><code>function ActiveCaption: string;

var
  Handle: THandle;
  Len: LongInt;
  Title: string;

begin
  Result := '';
  Handle := GetForegroundWindow;
  if Handle &lt;&gt; 0 then
  begin
    Len := GetWindowTextLength(Handle) + 1;
    SetLength(Title, Len);
    GetWindowText(Handle, PChar(Title), Len);
    ActiveCaption := TrimRight(Title);
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := ActiveCaption;
end;
</code></pre>