Creating Info Tip Handlers with .NET

Posted on | 317 words | ~2 mins
COM SharpShell Shell C#

I have just added an article to the CodeProject that discusses how to create Info Tip shell extensions in .NET. These extensions are used by the shell to customise the tooltips shown over shell items.

ShellInfoTipHandler

The article shows how you can use SharpShell to very quickly create these extensions, you can find it at: http://www.codeproject.com/Articles/527058/NET-Shell-Extensions-Shell-Info-Tip-Handlers.

So just how easy does SharpShell make creating Shell Info Tip Handlers? The answer is pretty easy indeed. The code below shows the full implementation of a Shell Info Tip Handler that changes the tooltips for folders to show the name of the folder and the number of items it contains:

[csharp]/// <summary> /// The FolderInfoTip handler is an example SharpInfoTipHandler that provides an info tip /// for folders that shows the number of items in the folder. /// </summary> [ComVisible(true)] [COMServerAssociation(AssociationType.Directory)] public class FolderInfoTipHandler : SharpInfoTipHandler { /// <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 override string GetInfo(RequestedInfoType infoType, bool singleLine) { // Switch on the tip of info we need to provide. switch (infoType) { case RequestedInfoType.InfoTip:

            //  Format the formatted info tip.
            return string.Format(singleLine
                                   ? &quot;{0} - {1} Items&quot;
                                   : &quot;{0}&quot; + Environment.NewLine + &quot;Contains {1} Items&quot;,
                                   Path.GetFileName(SelectedItemPath), Directory.GetFiles(SelectedItemPath).Length);

        case RequestedInfoType.Name:
            
            //  Return the name of the folder.
            return string.Format(&quot;Folder '{0}'&quot;, Path.GetFileName(SelectedItemPath));
            
        default:

            //  We won't be asked for anything else, like shortcut paths, for folders, so we 
            //  can return an empty string in the default case.
            return string.Empty;
    }
}

} [/csharp]

As you can see, all of the COM interfaces are hidden away and handled for you, there is no ugly pinvoke code and no use of strange structures imported from Win32. SharpShell handles all of the plumbing for you.