Use SharpShell to quickly implement Windows Shell Extension

Source: Internet
Author: User

After the CLR in-process side-by-side feature is introduced in. NET 4, we can use C # To compile Windows Shell. We can find related examples In Microsoft's All-In-One Code Framework. There are also several articles about it In the yard:

  1. Windows Shell extension series Article 1-. NET 4 compiling Windows Shell context menu Extension
  2. Windows Shell extension Series 2-. NET 4 Add bitmap icons for extended Windows Shell context menu items

However, after studying these examples, we will find that although it is much easier to write Shell extensions in C # than to use C ++, it is still cumbersome and there are many things to be aware, an error occurs when you are not careful.

Today, we found a SharShell project on CodePlex, which allows you to quickly create Shell extensions, which is very convenient. For example, for a menu extension as follows:

You only need to use the following statements:

[ComVisible (true)]
[COMServerAssocation (AssociationType. ClassOfExtension, ". txt")]
Public
Class
CountLinesExtension: SharpContextMenu
{
Protected
Override
Bool CanShowMenu ()
{
Return
True;
}

Protected
Override ContextMenuStrip CreateMenu ()
{
Var menu = new ContextMenuStrip ();
Var itemCountLines = new ToolStripMenuItem
{
Text = "Count Lines ...",
Image = Properties. Resources. CountLines
};

ItemCountLines. Click + = (sender, args) => CountLines ();
Menu. Items. Add (itemCountLines );
Return menu;
}

Private
Void CountLines ()
{
Var builder = new
StringBuilder ();
Foreach (var filePath in SelectedFilePaths)
{
Builder. AppendLine (string. Format ("{0}-{1} Lines", Path. GetFileName (filePath), File. ReadAllLines (filePath). Length ));
}
MessageBox. Show (builder. ToString ());
}
}

For more information, see the Getting Started tutorial on CodeProject:. NET Shell Extensions-Shell Context Menus.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.