Click here to Skip to main content
14,635,075 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi! I am creating an Explorer kind of app, and it's been going well - Until I realized I had to add a Properties menu..

So, I used this code:

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


Now, it works to display the files properties, but it allows the user to resume focus with the original form.

How can I give the Properties menu that is opened by the code provided the same behavior as ShowDialog()?

Summary of my question:

How do I make the parent form paused until the Properties form, which is opened using the code above, like it would if I opened a generic form using ShowDialog()?

Thanks :)

What I have tried:

I provided the code above - I don't really know what to change to add the desired behavior.
Posted
Updated 28-Apr-20 23:25pm
Comments
Richard Deeming 29-Apr-20 10:54am
   
NB: The properties window isn't modal in Windows Explorer. If you're trying to mimic the Explorer behaviour, you shouldn't make the properties window modal. :)

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Why are you using ShellExecute instead of Process? The Process class has a WaitForExit method and doesn't require faffing with Shell32.dll at all ...
   
Comments
The Magical Magikarp 29-Apr-20 16:14pm
   
How would I use Process to open the Properties Dialog? Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100