在explorer进程下使用ShellExecuteEx打开文件属性表,而不是调用进程

问题描述 投票:0回答:1

我的问题是 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进程下打开吗?

c# windows-shell shellexecute
1个回答
0
投票

您的进程实际上应该一直保留到所有 shell 线程结束为止。

为此,您必须实现一个支持 IUnknown 的自由线程接口,并通过调用

SHSetInstanceExplorer
告知 Windows。

更多信息和 C++ 示例实现可以在 这篇博文中找到。

© www.soinside.com 2019 - 2024. All rights reserved.