单击按钮时如何打开Windows资源管理器?

Tob*_*nir 7 windows delphi explorer

我在Delphi项目中有一个表单.表格上有一个按钮.当用户单击该按钮时,我希望它打开Windows资源管理器.

我需要用什么代码来实现这个目标?

zz1*_*433 26

如果你需要在资源管理器中选择一些特定的文件,我有以下功能,我使用

procedure SelectFileInExplorer(const Fn: string);
begin
  ShellExecute(Application.Handle, 'open', 'explorer.exe',
    PChar('/select,"' + Fn+'"'), nil, SW_NORMAL);
end;
Run Code Online (Sandbox Code Playgroud)

你可以称之为:

SelectFileInExplorer('C:\Windows\notepad.exe');
Run Code Online (Sandbox Code Playgroud)

编辑:如上所述,必须将ShellAPI添加到您的使用列表中


Jos*_*ons 11

以Mason Wheeler所说的为基础:您还可以将目录作为参数传递,以使窗口打开到非默认位置:

uses
  ShellAPI;

...

  ShellExecute(Application.Handle,
    nil,
    'explorer.exe',
    PChar('c:\'), //wherever you want the window to open to
    nil,
    SW_NORMAL     //see other possibilities by ctrl+clicking on SW_NORMAL
    );
Run Code Online (Sandbox Code Playgroud)


Mas*_*ler 8

试试这个:

ShellExecute(Application.Handle, nil, 'explorer.exe', nil, nil, SW_NORMAL);
Run Code Online (Sandbox Code Playgroud)

您需要添加ShellAPI到您的uses子句.