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

A tool to order the window buttons in your taskbar

, 9 Aug 2005
Move your window buttons into your preferred order. WinXP or later only.
taskbarsorter_app_1.zip
taskbarsorter_app_2.zip
taskbarsorter_src_1.zip
TaskbarSorter.1
System.Runtime.InteropServices.APIs.dll
System.Windows.Forms.TreeListView.dll
TaskbarSorter
Common
Icons
MoveDown.ico
MoveFirst.ico
MoveLast.ico
MoveUp.ico
Refresh.ico
WindowsExplorer.ico
Work.ico
TaskbarSorter.snk
TaskbarSorter.debug.FxCop
taskbarsorter_src_2.zip
TaskbarSorter.2
System.Runtime.InteropServices.APIs.dll
System.Windows.Forms.TreeListView.dll
TaskbarSorter
bin
Release
Common
Icons
App.ico
MoveDown.ico
MoveFirst.ico
MoveLast.ico
MoveUp.ico
WindowsExplorer.ico
Work.ico
TaskbarSorter.csproj.user
TaskbarSorter.snk
TaskbarSorter.debug.FxCop
using System;
using System.Windows.Forms;
using System.Globalization;
using System.Diagnostics;

using Microsoft.Win32;

namespace Common
{
	
//-----------------------------------------------------------------------------

	internal class Settings
	{

//-----------------------------------------------------------------------------

		public static string DefaultRegistrySettingsPath = "Software\\" + Application.CompanyName + "\\" + Application.ProductName + "\\Settings";

//-----------------------------------------------------------------------------
// Get

		// bool
		public static bool Get( string sValueName, bool bDefault )
		{
			return Get( null, sValueName, bDefault );
		}

		public static bool Get( string sPath, string sValueName, bool bDefault )
		{
			return Get( null, sPath, sValueName, bDefault );
		}

		public static bool Get( string sRoot, string sPath, string sValueName, bool bDefault )
		{
			object o = GetObject( sRoot, sPath, sValueName );
			if ( o == null ) return bDefault;

			if ( ! ( o is string ) ) return bDefault;

			return ( string.Compare( (string) o, "False", true, CultureInfo.InvariantCulture ) != 0 );
		}

		// int
		public static int Get( string sValueName, int iDefault )
		{
			return Get( null, sValueName, iDefault );
		}

		public static int Get( string sPath, string sValueName, int iDefault )
		{
			return Get( null, sPath, sValueName, iDefault );
		}

		public static int Get( string sRoot, string sPath, string sValueName, int iDefault )
		{
			object o = GetObject( sRoot, sPath, sValueName );
			if ( o == null ) return iDefault;

			if ( ! ( o is int ) ) return iDefault;

			return (int) o;
		}

		// string
		public static string Get( string sValueName, string sDefault )
		{
			return Get( null, sValueName, sDefault );
		}

		public static string Get( string sPath, string sValueName, string sDefault )
		{
			return Get( null, sPath, sValueName, sDefault );
		}

		public static string Get( string sRoot, string sPath, string sValueName, string sDefault )
		{
			object o = GetObject( sRoot, sPath, sValueName );
			if ( o == null ) return sDefault;

			if ( ! ( o is string ) ) return sDefault;

			return (string) o;
		}

		// object
		public static object GetObject( string sValueName )
		{
			return GetObject( null, sValueName );
		}

		public static object GetObject( string sPath, string sValueName )
		{
			return GetObject( null, sPath, sValueName );
		}

		public static object GetObject( string sRoot, string sPath, string sValueName )
		{
			string s = DefaultRegistrySettingsPath;
			if ( sRoot != null && sRoot.Length > 0 ) s = sRoot;
			if ( sPath != null && sPath.Length > 0 ) s += "\\" + sPath;

			RegistryKey key = Registry.CurrentUser.OpenSubKey( s );
			if ( key == null ) return null;
			
			object o = key.GetValue( sValueName );

			key.Close();

			return o;
		}

//-----------------------------------------------------------------------------
// Set

		// bool
		public static void Set( string sValueName, bool value )
		{
			Set( null, sValueName, value );
		}

		public static void Set( string sPath, string sValueName, bool value )
		{
			Set( null, sPath, sValueName, value );
		}

		public static void Set( string sRoot, string sPath, string sValueName, bool value )
		{
			Set( sRoot, sPath, sValueName, (object) ( value ? "True" : "False" ) );
		}

		// object
		public static void Set( string sValueName, object value )
		{
			Set( null, sValueName, value );
		}

		public static void Set( string sPath, string sValueName, object value )
		{
			Set( null, sPath, sValueName, value );
		}

		public static void Set( string sRoot, string sPath, string sValueName, object value )
		{
			string s = DefaultRegistrySettingsPath;
			if ( sRoot != null && sRoot.Length > 0 ) s = sRoot;
			if ( sPath != null && sPath.Length > 0 ) s += "\\" + sPath;

			RegistryKey key = Registry.CurrentUser.CreateSubKey( s );
			key.Close();

			key = Registry.CurrentUser.OpenSubKey( s, true );

			key.SetValue( sValueName, value );

			key.Close();
		}

//-----------------------------------------------------------------------------

	} // Settings

//-----------------------------------------------------------------------------

	internal class Setting
	{
		private string _Root = String.Empty;
		private string _Path = String.Empty;
		private string _Name = String.Empty;
		private object _Default = null;

		public Setting( string name, object defaultValue )
		{
			_Name = name;
			_Default = defaultValue;
		}

		public Setting( string path, string name, object defaultValue )
		{
			_Path = path;
			_Name = name;
			_Default = defaultValue;
		}

		public Setting( string root, string path, string name, object defaultValue )
		{
			_Root = root;
			_Path = path;
			_Name = name;
			_Default = defaultValue;
		}

		public bool Bool { get { return GetBool(); } }
		public int Int { get { return GetInt(); } }
		public string String { get { return GetString(); } }

		public bool GetBool()
		{
			Debug.Assert( _Default is bool );
			return Settings.Get( _Root, _Path, _Name, ( bool ) _Default );
		}

		public int GetInt()
		{
			Debug.Assert( _Default is int );
			return Settings.Get( _Root, _Path, _Name, ( int ) _Default );
		}

		public string GetString()
		{
			Debug.Assert( _Default is string );
			return Settings.Get( _Root, _Path, _Name, ( string ) _Default );
		}

		public void Set( bool value )
		{
			Debug.Assert( _Default is bool );
			Settings.Set( _Root, _Path, _Name, value );
		}

		public void Set( int value )
		{
			Debug.Assert( _Default is int );
			Settings.Set( _Root, _Path, _Name, value );
		}

		public void Set( string value )
		{
			Debug.Assert( _Default is string );
			Settings.Set( _Root, _Path, _Name, 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)

About the Author

Nicholas Butler

United Kingdom United Kingdom

I built my first computer, a Sinclair ZX80, on my 11th birthday in 1980.
In 1992, I completed my Computer Science degree and built my first PC.
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing concurrent software professionally, using multi-processor machines, since 1995.
 
In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.
 
I now live near idyllic Bournemouth in England.
 
If you would like help with multithreading, please contact me via my website:
 
 
I can work 'virtually' anywhere!

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 10 Aug 2005
Article Copyright 2005 by Nicholas Butler
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid