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

.NET Shell Extensions - Shell Preview Handlers

, 20 May 2014
Quickly create Shell Preview Handlers for Windows or Outlook 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
ILMerge.2.12.0803
ILMerge.2.12.0803.nupkg
ILMerge.doc
ILMerge.exe
NUnit.2.6.2
lib
nunit.framework.dll
NUnit.2.6.2.nupkg
NUnit.2.6.2.nuspec
Samples
ContextMenu
CountLinesExtension
CountLinesExtension.csproj.vspscc
Key.snk
Properties
Resources
CountLines.bmp
DllContextMenuExtension
DllContextMenuExtension.csproj.vspscc
Key.snk
Properties
DropHandler
XsdDropHandler
ExampleFiles
Key.snk
Properties
XsdDropHandler.csproj.vspscc
IconHandler
DllIconHandler
DllIconHandler.csproj.vspscc
Key.snk
Properties
Resources
ManagedDll.ico
NativeDll.ico
IconOverlayHandler
ReadOnlyFileIconOverlayHandler
Key.snk
Properties
ReadOnlyFileIconOverlayHandler.csproj.vspscc
Resources
ReadOnly.ico
InfoTipHandler
FolderInfoTipHandler
FolderInfoTipHandler.csproj.vspscc
Key.snk
Properties
PreviewHandler
IconPreviewHandler
Dependencies
IconLib.dll
IconLib.dll
IconPreviewHandler.csproj.user
IconPreviewHandler.csproj.vspscc
Key.snk
Properties
PropertySheet
DrivePropertySheet
DrivePropertySheet.csproj.vspscc
Key.snk
Properties
ResourcesPropertySheet
Key.snk
Properties
ResourcesPropertySheet.csproj.vspscc
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
SharpPreviewHandler
SharpPropertySheet
SharpShell.csproj.user
SharpShell.csproj.vspscc
SharpShellNativeBridge
SharpShellNativeBridge.aps
SharpShellNativeBridge.vcxproj.filters
SharpShellNativeBridge.vcxproj.user
SharpShellNativeBridge.vcxproj.vspscc
SharpShellNativeBridge1.aps
Tools
ExtensionManager
Properties
Settings.settings
Resources
xsd.ico
ServerInspector
Properties
Settings.settings
ServerInspector.csproj.vspscc
Servers
ServerManager
About
LogView
Properties
Settings.settings
Resources
ChangeYourView.png
ContextMenu.png
Icon.png
IconOverlayHandler.png
InfoTip.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.user
ServerManager.csproj.vspscc
SharpShell.ico
TestShell
ShellExtensionManager
Properties
Settings.settings
ShellExtensionManager.csproj.vspscc
SharpShell_Tools.zip
using System;
using SharpShell.Attributes;
using SharpShell.Interop;

namespace SharpShell.SharpInfoTipHandler
{
    /// <summary>
    /// The SharpIconHandler is the base class for SharpShell servers that provide
    /// custom Icon Handlers.
    /// </summary>
    [ServerType(ServerType.ShellInfoTipHandler)]
    public abstract class SharpInfoTipHandler : PersistFileServer, IQueryInfo
    {
        /// <summary>
        /// Gets the info tip text for an item.
        /// </summary>
        /// <param name="dwFlags">Flags that direct the handling of the item from which you're retrieving the info tip text. This value is commonly zero.</param>
        /// <param name="ppwszTip">The address of a Unicode string pointer that, when this method returns successfully, receives the tip string pointer. Applications that implement this method must allocate memory for ppwszTip by calling CoTaskMemAlloc.
        /// Calling applications must call CoTaskMemFree to free the memory when it is no longer needed.</param>
        /// <returns>
        /// Returns S_OK if the function succeeds. If no info tip text is available, ppwszTip is set to NULL. Otherwise, returns a COM-defined error value.
        /// </returns>
        int IQueryInfo.GetInfoTip(QITIPF dwFlags, out string ppwszTip)
        {
            //  Do we need to get the tip on a single line?
            var singleLine = dwFlags.HasFlag(QITIPF.QITIPF_SINGLELINE);

            //  Now work out what type of info to get.
            RequestedInfoType infoType;
            if(dwFlags.HasFlag(QITIPF.QITIPF_USENAME))
                infoType = RequestedInfoType.Name;
            else if(dwFlags.HasFlag(QITIPF.QITIPF_LINKUSETARGET))
                infoType = RequestedInfoType.InfoOfShortcutTarget;
            else if(dwFlags.HasFlag(QITIPF.QITIPF_LINKNOTARGET))
                infoType = RequestedInfoType.InfoOfShortcut;
            else
                infoType = RequestedInfoType.InfoTip;
            
            try
            {
                //  Get the requested info.
                var infoTip = GetInfo(infoType, singleLine);

                //  Set the tip. The runtime marshals out strings with CoTaskMemAlloc for us.
                ppwszTip = infoTip;
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured getting the info tip.", exception);

                //  If an exception is thrown, we cannot return any info.
                ppwszTip = string.Empty;
            }

            //  Return success.
            return WinError.S_OK;
        }

        /// <summary>
        /// Gets the information flags for an item. This method is not currently used.
        /// </summary>
        /// <param name="pdwFlags">A pointer to a value that receives the flags for the item. If no flags are to be returned, this value should be set to zero.</param>
        /// <returns>
        /// Returns S_OK if pdwFlags returns any flag values, or a COM-defined error value otherwise.
        /// </returns>
        int IQueryInfo.GetInfoFlags(out int pdwFlags)
        {
            //  Currently, GetInfoFlags shouldn't be called by the system. Return success if it is.
            pdwFlags = 0;
            return WinError.S_OK;
        }

        /// <summary>
        /// Gets info for the selected item (SelectedItemPath).
        /// </summary>
        /// <param name="infoType">Type of info to return.</param>
        /// <param name="singleLine">if set to <c>true</c>, put the info in a single line.</param>
        /// <returns>
        /// Specified info for the selected file.
        /// </returns>
        protected abstract string GetInfo(RequestedInfoType infoType, bool singleLine);
    }

    /// <summary>
    /// Specifies the type of information requested.
    /// </summary>
    public enum RequestedInfoType
    {
        /// <summary>
        /// The InfoTip - the text that will be shown in the tooltip for the item.
        /// </summary>
        InfoTip,

        /// <summary>
        /// Return the name of the item.
        /// </summary>
        Name,

        /// <summary>
        /// If the item is a shortcut file, get the info of the shortcut itself.
        /// </summary>
        InfoOfShortcut,

        /// <summary>
        /// If the item is a shortcut file, get the info of the target of the shortcut.
        /// </summary>
        InfoOfShortcutTarget
    }
}

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 MIT License

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
Web02 | 2.8.140827.1 | Last Updated 20 May 2014
Article Copyright 2013 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid