To show the properties page of a file and navigate

2019-07-13 11:20发布

In my software i need to show the property dialog of a file and navigate to a specific tab in that property dialog? please tell me how to acheive this using c#?

or Is it possible to replace the default property dialog with a custom one?

标签: c# pinvoke
2条回答
看我几分像从前
2楼-- · 2019-07-13 11:24

You must use P/Invoke to achieve this:

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);
}

don't know if it's even possible to select a specific tab (in a nice way)...

查看更多
小情绪 Triste *
3楼-- · 2019-07-13 11:44
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);
}

By setting info.lpParameters to name of the tab you want it gets opened with that tab selected. In my case "Details"...

Yes you need that declaration that codeteq wrote.

This is the declaration that I use:

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;

}

查看更多
登录 后发表回答