Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

.NET Shell Extensions - Shell Drop Handlers

, 19 Jan 2013
Rapidly create Shell Drop Handler Extensions using .NET
SharpShell_Core_Library.zip
SharpShell_Source_Code.zip
SharpShell Source Code
Dependencies
Apex
Apex.WinForms.dll
SharpShell
packages
Apex.1.5.0
Apex.1.5.0.nupkg
lib
net35
Apex.dll
net40
Apex.dll
sl30
Apex.Silverlight.dll
sl3-wp
Apex.WP7.dll
sl40
Apex.Silverlight4.dll
sl4-wp71
Apex.WP7.dll
sl50
Apex.Silverlight.dll
NUnit.2.6.2
lib
nunit.framework.dll
NUnit.2.6.2.nupkg
Samples
ContextMenu
CountLinesExtension
bin
CountLinesExtension.csproj.vspscc
Key.snk
Properties
Resources
CountLines.bmp
DropHandler
XsdDropHandler
bin
ExampleFiles
Key.snk
Properties
XsdDropHandler.csproj.vspscc
IconHandler
DllIconHandler
bin
DllIconHandler.csproj.vspscc
Key.snk
Properties
Resources
ManagedDll.ico
NativeDll.ico
IconOverlayHandler
ReadOnlyFileIconOverlayHandler
bin
Key.snk
Properties
ReadOnlyFileIconOverlayHandler.csproj.vspscc
Resources
ReadOnly.ico
InfoTipHandler
FolderInfoTipHandler
FolderInfoTipHandler.csproj.vspscc
Key.snk
Properties
PropertySheet
DrivePropertySheet
DrivePropertySheet.csproj.vspscc
Key.snk
Properties
TextFilePropertySheet
Key.snk
Properties
TextFilePropertySheet.csproj.vspscc
SharpShell
Attributes
Diagnostics
Extensions
Interop
Key.snk
NativeBridge
SharpShellNativeBridge32.dll
SharpShellNativeBridge64.dll
Properties
ServerRegistration
SharpContextMenu
SharpDropHandler
SharpIconHandler
SharpIconOverlayHandler
SharpInfoTipHandler
SharpPropertySheet
SharpShell.csproj.vspscc
SharpShellNativeBridge
SharpShellNativeBridge.vcxproj.filters
SharpShellNativeBridge.vcxproj.user
SharpShellNativeBridge.vcxproj.vspscc
Tools
ServerInspector
Properties
Settings.settings
ServerInspector.csproj.vspscc
Servers
ServerManager
About
LogView
Properties
Settings.settings
Resources
ChangeYourView.png
ContextMenu.png
Icon.png
openHS.png
PlayHS.png
PropertySheet.png
View_Details.png
View_LargeIcons.png
View_List.png
View_SmallIcons.png
View_Tiles.png
ServerDetails
ServerManager.csproj.vspscc
SharpShell.ico
TestShell
ShellExtensionManager
Properties
Settings.settings
ShellExtensionManager.csproj.vspscc
SharpShell_Tools.zip
SharpShell Tools
Apex.dll
Apex.WinForms.dll
ServerInspector.exe
ServerManager.exe
SharpShell.dll
System.Windows.Interactivity.dll
using System;
using System.Collections.Generic;
using System.Linq;
using SharpShell.Attributes;
using SharpShell.Diagnostics;
using SharpShell.Interop;

namespace SharpShell.SharpPropertySheet
{
    /// <summary>
    /// SharpPropertySheet is the base class for Shell Property Sheet Extensions supported
    /// by SharpShell.
    /// </summary>
    [ServerType(ServerType.ShellPropertySheet)]
    public abstract class SharpPropertySheet : ShellExtInitServer, IShellPropSheetExt
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SharpPropertySheet"/> class.
        /// </summary>
        protected SharpPropertySheet()
        {
            //  Log the event.
            Log("Constructing property sheet.");

            //  The lazy property sheet pages will be created by the abstract 
            //  create pages function.
            propertySheetPages = new Lazy<List<SharpPropertyPage>>( () => CreatePages().ToList());
        }

       #region Implementation of IShellPropSheetExt

        /// <summary>
        /// Adds the pages.
        /// </summary>
        /// <param name="pfnAddPage">The PFN add page.</param>
        /// <param name="lParam">The l param.</param>
        /// <returns></returns>
        int IShellPropSheetExt.AddPages(IntPtr pfnAddPage, IntPtr lParam)
        {
            //  Log the event.
            Log("Adding Pages...");

            //  Create the bridge.
            var bridge = new NativeBridge.NativeBridge();
            
            //  Initialise it.
            if(bridge.Initialise() == false)
            {
                Logging.Error("Failed to initialise the NativeBridge.", null);
                return 0;
            }

            //  Go through each page - that has a property page.
            foreach (var page in propertySheetPages.Value.Where(p => p.Handle != IntPtr.Zero))
            {
                //  Create a property page proxy for this page.
                var proxy = new PropertyPageProxy(this, page);

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

                //  Name the page, to aid with debugging.
                User32.SetWindowText(propertyPageHandle, "SharpShell Host for " + page.GetType().Name);
                
                //  Log the event.
                Log("Created Page Proxy, handle is " + propertyPageHandle.ToString("x8"));

                //  Now that we have the page handle, add the page via the callback.
                bridge.CallAddPropSheetPage(pfnAddPage, propertyPageHandle, lParam);
            }

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

            //  Log the event.
            Log("Adding Pages (Done)");

            //  We've succeeded.
            return WinError.S_OK;
        }

        /// <summary>
        /// Replaces the page.
        /// </summary>
        /// <param name="uPageID">The u page ID.</param>
        /// <param name="lpfnReplacePage">The LPFN replace page.</param>
        /// <param name="lParam">The l param.</param>
        /// <returns></returns>
        int IShellPropSheetExt.ReplacePage(uint uPageID, AddPropertySheetPageDelegate lpfnReplacePage, IntPtr lParam)
        {
            return 0;
        }

        #endregion

        /// <summary>
        /// Determines whether this instance can show a shell property sheet, given the specified selected file list.
        /// </summary>
        /// <returns>
        ///   <c>true</c> if this instance should show a shell property sheet for the specified file list; otherwise, <c>false</c>.
        /// </returns>
        protected abstract bool CanShowSheet();

        /// <summary>
        /// Creates the pages.
        /// </summary>
        /// <returns>The property sheet pages.</returns>
        protected abstract IEnumerable<SharpPropertyPage> CreatePages();

        /// <summary>
        /// The lazy property sheet pages, only created when we actually need them.
        /// </summary>
        private readonly Lazy<List<SharpPropertyPage>> propertySheetPages;
        
        /// <summary>
        /// Gets the pages.
        /// </summary>
        public IEnumerable<SharpPropertyPage> Pages
        {
            get { return propertySheetPages.Value; }
        }
    }
}

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)

Share

About the Author

Dave Kerr
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 19 Jan 2013
Article Copyright 2013 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid