使用RunFileDlg:
[DllImport("shell32.dll", EntryPoint = "#61", CharSet = CharSet.Unicode)]
public static extern int RunFileDlg(
[In] IntPtr hWnd,
[In] IntPtr icon,
[In] string path,
[In] string title,
[In] string prompt,
[In] uint flags);
private static void Main(string[] args)
{
// You might also want to add title, window handle...etc.
RunFileDlg(IntPtr.Zero, IntPtr.Zero, null, null, null, 0);
}
Run Code Online (Sandbox Code Playgroud)
可能的值flags
:
RFF_NOBROWSE = 1; //Removes the browse button.
RFF_NODEFAULT = 2; // No default item selected.
RFF_CALCDIRECTORY = 4; // Calculates the working directory from the file name.
RFF_NOLABEL = 8; // Removes the edit box label.
RFF_NOSEPARATEMEM = 14; // Removes the Separate Memory Space check box (Windows NT only).
Run Code Online (Sandbox Code Playgroud)
该RunFileDlg
API是不支持的,并且可以通过微软从(我将授予该MS的向后兼容性而事实上,这个API,虽然无证,似乎相当广为人知的承诺,使这不可能的,但它仍然是一个未来的Windows版本中删除可能性).
启动运行对话框的支持方式是使用该IShellDispatch::FileRun
方法.
在C#中,您可以通过转到"添加引用",选择"COM"选项卡,然后选择"Microsoft Shell控件和自动化"来访问此方法.执行此操作后,您可以按如下方式启动对话框:
Shell32.Shell shell = new Shell32.Shell();
shell.FileRun();
Run Code Online (Sandbox Code Playgroud)
是的,RunFileDlg
API提供了更多的可定制性,但这具有记录,支持的优势,因此将来不太可能破坏.