Click here to Skip to main content
15,897,032 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Shell Property Sheets

Rate me:
Please Sign up or sign in to vote.
5.00/5 (18 votes)
7 Apr 2013CPOL7 min read 93.6K   3K   47  
Use .NET to rapidly build Shell Property Sheets
using System;
using System.Windows.Forms;
using SharpShell.Attributes;
using IDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;

namespace SharpShell.SharpDataHandler
{
    /// <summary>
    /// The SharpDataHandler is the base class for SharpShell servers that provide
    /// custom Icon Handlers.
    /// </summary>
    [ServerType(ServerType.ShellDataHandler)]
    public abstract class SharpDataHandler : PersistFileServer, IDataObject
    {
        #region Implementation of IDataObject

        int IDataObject.DAdvise(ref System.Runtime.InteropServices.ComTypes.FORMATETC pFormatetc, System.Runtime.InteropServices.ComTypes.ADVF advf, System.Runtime.InteropServices.ComTypes.IAdviseSink adviseSink, out int connection)
        {
            //  Log key events.
            Log("IDataObject.DAdvise called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        void IDataObject.DUnadvise(int connection)
        {
            //  Log key events.
            Log("IDataObject.DUnadvise called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        int IDataObject.EnumDAdvise(out System.Runtime.InteropServices.ComTypes.IEnumSTATDATA enumAdvise)
        {
            //  Log key events.
            Log("IDataObject.EnumDAdvise called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        System.Runtime.InteropServices.ComTypes.IEnumFORMATETC IDataObject.EnumFormatEtc(System.Runtime.InteropServices.ComTypes.DATADIR direction)
        {
            //  Log key events.
            Log("IDataObject.EnumFormatEtc called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        int IDataObject.GetCanonicalFormatEtc(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatIn, out System.Runtime.InteropServices.ComTypes.FORMATETC formatOut)
        {
            //  Log key events.
            Log("IDataObject.GetCanonicalFormatEtc called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        void IDataObject.GetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC format, out System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
        {
            //  Log key events.
            Log("IDataObject.GetData called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        void IDataObject.GetDataHere(ref System.Runtime.InteropServices.ComTypes.FORMATETC format, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
        {
            //  Log key events.
            Log("IDataObject.GetDataHere called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        int IDataObject.QueryGetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC format)
        {
            //  Log key events.
            Log("IDataObject.QueryGetData called.");

            //  Not needed for Shell Data Handlers.
            throw new NotImplementedException();
        }

        void IDataObject.SetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatIn, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium, bool release)
        {
            //  Log key events.
            Log("IDataObject.SetData called.");

            try
            {
                //  Let the derived class provide data.
                var itemData = GetData();

                //  Set the data.
                ((IDataObject)itemData).SetData(ref formatIn, ref medium, release);
            }
            catch (Exception exception)
            {
                LogError("An exception occured getting data for the item " + SelectedItemPath, exception);
            }
        }

        #endregion

        /// <summary>
        /// Gets the data for the selected item. The selected item's path is stored in the SelectedItemPath property.
        /// </summary>
        /// <returns>The data for the selected item, or null if there is none.</returns>
        protected abstract DataObject GetData();
    }
}

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