browse by category or date

I was looking for a way to add my program into Windows Explorer right-click context. So I googled it, and I think I found what I was looking for.

As usual, StackOverflow delivers the best clue. I found this discussion that gave me the starting point.

So the idea here is to use Windows’ registry. Apparently there’s a location where we can register/unregister the context menu.

Thanks polyglot & StackOverflow!

These are the required assemblies to interop with Windows.

using System;
using Microsoft.Win32;

The functions to register/unregister the context menu :

string contextName = "contextTest";
public bool Register()
{
	//Open HKEY_CLASSES_ROOT, Key *, last param is to make it writable
	RegistryKey reg = Registry.ClassesRoot.OpenSubKey("*", true);
	if (reg != null)
	{
		RegistryKey shell = reg.OpenSubKey("shell", true);
		if (shell != null)
		{
			//Get Current Assembly fullname
			string appLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
			
			RegistryKey ctx = shell.OpenSubKey(contextName);
			if (ctx != null)
				return true;
			else
				ctx = shell.CreateSubKey(contextName);
			ctx.SetValue("","Context It");
			RegistryKey cmd = ctx.CreateSubKey("command");
			cmd.SetValue("", """ + appLocation +"" "%L"");
			return true;
		}
	}
	return false;
}
public bool Unregister()
{
	RegistryKey reg = Registry.ClassesRoot.OpenSubKey("*", true);
	if (reg != null)
	{
		RegistryKey shell = reg.OpenSubKey("shell", true);
		if (shell != null)
		{
			shell.DeleteSubKeyTree(contextName);					
			return true;
		}
	}
	return false;
}

The result:
right.contex

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

Yesterday, a colleague requested my assistance to modify an Excel chart. She has the following chart:
chart.profit
The data: (not the real data, of course :D)

JanFebMarchAprMay
Cost1500035000450008500060000
Sales1700045000500009000070000
Profit2000100005000500010000
Profit%12%22%10%6%14%

She wanted to add another series of data for next year profit target:

JanFebMarchAprMay
Cost1500035000450008500060000
Sales1700045000500009000070000
Profit2000100005000500010000
Profit%12%22%10%6%14%
Target Next Yr.%12%16%20%24%30%

So how do we incorporate the new row?

  1. Add the new series.
    Right click on the chart, click ‘Source Data’ chart.profit.2
    Click Add button, and fill up the fields as indicatedchart.profit.3
  2. Modify the series
    If you don’t have Chart toolbar as shown below, click View – Toolbars – Chart. If you already have it, select the newly created series. chart.profit.4
    Change the chart type. chart.profit.5Change the chart properties.chart.profit.6

Final result:
chart.profit.7

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

These are free ebooks that hopefully will help all of us to be a better programmer/architects. Thanks Anoop!!

  1. Foundations Of Programming
  2. Microsoft Application Architecture Guide, 2nd Edition
  3. Rob Miles C# Yellow Book 2010
  4. Threading in C#
  5. Improving .NET Application Performance and Scalability
  6. Applying Design Patterns

Happy reading!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: