Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Drop Handlers

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
19 Jan 2013CPOL7 min read 53.8K   2.1K   35  
Rapidly create Shell Drop Handler Extensions using .NET
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using SharpShell.Interop;
using SharpShell.SharpPropertySheet;

namespace SharpShell.Diagnostics
{
    public static class SharpPropertyPageTester
    {
        public static void Test(SharpPropertySheet.SharpPropertySheet sheet)
        {

            //  Create the bridge.
            var bridge = new NativeBridge.NativeBridge();
            bridge.Initialise();

            //  Create a property page proxy for this page.
            var proxy = new PropertyPageProxy(sheet, sheet.Pages.First());

            //  Using the proxy, create the property page handle.
            proxy.CreatePropertyPageHandle(bridge);
            var propertyPageHandle = proxy.HostWindowHandle;

            var psh = new PROPSHEETHEADER();
            psh.dwSize = Marshal.SizeOf(psh);
            psh.dwSize = 96;// (uint)Marshal.SizeOf(psh);
            //psh.dwFlags
            psh.hwndParent = IntPtr.Zero;
            psh.hInstance = bridge.GetInstanceHandle();
            psh.hIcon = IntPtr.Zero;
            psh.pszCaption = "Property Sheet";
            psh.nPages = 1;

            var pages = new []{ propertyPageHandle};
int nParts = pages.Length;
IntPtr pointer = Marshal.AllocHGlobal(nParts * Marshal.SizeOf(typeof(IntPtr)));
for (int i = 0; i < nParts; i++) {
    Marshal.WriteIntPtr(pointer, i * Marshal.SizeOf(typeof(IntPtr)), pages[i]);
}
            psh.phpage = pointer;
            psh.nStartPage = (IntPtr)0;
            try
            {
                var result = Comctl32.PropertySheet(ref psh);
            }
            catch (Exception)
            {
                var excep = new Win32Exception(Marshal.GetLastWin32Error());
                
                throw;
            }


            //  Release the bridge.
            bridge.Deinitialise();

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions