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

.NET Shell Extensions - Shell Icon Overlay Handlers

Rate me:
Please Sign up or sign in to vote.
5.00/5 (32 votes)
14 Sep 2013CPOL7 min read 185.1K   6.5K   83  
Create Shell Icon Overlay Handlers using .NET!
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Apex.MVVM;
using SharpShell.ServerRegistration;

namespace ShellExtensionManager.ShellExtensions
{
    [ViewModel]
    public class ShellExtensionsViewModel : ViewModel
    {
        public ShellExtensionsViewModel()
        {
            //  Create the RefreshExtensions Asynchronous Command.
            RefreshExtensionsCommand = new AsynchronousCommand(DoRefreshExtensionsCommand);

            RefreshExtensionsCommand.DoExecute();
        }

        /// <summary>
        /// Performs the  command.
        /// </summary>
        /// <param name="parameter">The RefreshExtensions command parameter.</param>
        private void DoRefreshExtensionsCommand(object parameter)
        {
            //  Get all servers.
            var servers = ServerRegistrationManager.EnumerateExtensions(RegistrationType.OS64Bit, ShellExtensionType.IconHandler);
            foreach (var server in servers)
            {
                var extensionViewModel = new ExtensionViewModel();
                extensionViewModel.DisplayName = server.DisplayName;
                extensionViewModel.ShellExtensionType = server.ShellExtensionType;
                foreach (var classReg in server.ClassRegistrations)
                    extensionViewModel.ClassRegistrations.Add(classReg);
                RefreshExtensionsCommand.ReportProgress(() => Extensions.Add(extensionViewModel));
            }
        }

        /// <summary>
        /// Gets the RefreshExtensions command.
        /// </summary>
        /// <value>The value of .</value>
        public AsynchronousCommand RefreshExtensionsCommand
        {
            get;
            private set;
        }

        
        /// <summary>
        /// The Extensions observable collection.
        /// </summary>
        private readonly ObservableCollection<ExtensionViewModel> ExtensionsProperty =
          new ObservableCollection<ExtensionViewModel>();

        /// <summary>
        /// Gets the Extensions observable collection.
        /// </summary>
        /// <value>The Extensions observable collection.</value>
        public ObservableCollection<ExtensionViewModel> Extensions
        {
            get { return ExtensionsProperty; }
        }

        
        /// <summary>
        /// The NotifyingProperty for the SelectedExtension property.
        /// </summary>
        private readonly NotifyingProperty SelectedExtensionProperty =
          new NotifyingProperty("SelectedExtension", typeof(ExtensionViewModel), default(ExtensionViewModel));

        /// <summary>
        /// Gets or sets SelectedExtension.
        /// </summary>
        /// <value>The value of SelectedExtension.</value>
        public ExtensionViewModel SelectedExtension
        {
            get { return (ExtensionViewModel)GetValue(SelectedExtensionProperty); }
            set { SetValue(SelectedExtensionProperty, 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)


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