我的问题是 PropertySheetExtension,但默认文件属性表似乎存在相同的行为。以下代码的问题:
// Snippet from http://stackoverflow.com/a/1936957/124721
using System.Runtime.InteropServices;
[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;
}
private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
public static bool 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;
return ShellExecuteEx(ref info);
}
是它在调用应用程序进程下打开文件属性表,而不是 explorer.exe。因此,当应用程序关闭时,属性表会关闭,这不是我需要的行为。当应用程序退出时,我需要工作表保持打开状态。另一个问题是,如果应用程序打开属性表,然后通过资源管理器右键单击文件并单击属性,它将打开第二个重复表。
我尝试使用 ShellExecuteEx 并使用资源管理器的主窗口或 GetShellWindow 设置父窗口句柄,但这没有帮助。
有没有另一种方法可以让这个属性表在 explorer.exe 进程下打开?