要显示一个文件的属性页面,浏览到一个标签(To show the properties page o

2019-09-22 00:55发布

在我的软件,我需要显示一个文件的属性对话框,然后导航到该属性对话框中的特定标签? 请告诉我如何达致这使用C#?

或者是否有可能更换一个自定义的默认属性对话框?

Answer 1:

private bool properties(string Filename) 
{
    SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
    info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
    info.lpVerb = "properties";
    info.lpParameters = "Details";
    info.lpFile = Filename;
    info.nShow = SW_SHOW;
    info.fMask = SEE_MASK_INVOKEIDLIST;
    return ShellExecuteEx(ref info);
}

通过info.lpParameters设置选项卡的名称,你想它被打开与选择的选项卡。 在我的情况“详细信息” ...

是的,你需要一个声明,表明codeteq写道。

这是我使用的声明:

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;

[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHELLEXECUTEINFO
{
     public int cbSize;
     public uint fMask;
     public IntPtr hwnd;
     [MarshalAs(UnmanagedType.LPTStr)]
     public string lpVerb;
     [MarshalAs(UnmanagedType.LPTStr)]
     public string lpFile;
     [MarshalAs(UnmanagedType.LPTStr)]
     public string lpParameters;
     [MarshalAs(UnmanagedType.LPTStr)]
     public string lpDirectory;
     public int nShow;
     public IntPtr hInstApp;
     public IntPtr lpIDList;
     [MarshalAs(UnmanagedType.LPTStr)]
     public string lpClass;
     public IntPtr hkeyClass;
     public uint dwHotKey;
     public IntPtr hIcon;
     public IntPtr hProcess;

}



Answer 2:

您必须使用P / Invoke来实现这一目标:

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;

[DllImport("shell32.dll")]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

public static void ShowFileProperties(string filename) 
{
    SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
    info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
    info.lpVerb = "properties";
    info.lpFile = filename;
    info.nShow = SW_SHOW;
    info.fMask = SEE_MASK_INVOKEIDLIST;
    ShellExecuteEx(ref info);
}

不知道,如果它甚至有可能选择一个特定的标签(在一个不错的方式)...



文章来源: To show the properties page of a file and navigate to a tab
标签: c# pinvoke