Click here to Skip to main content
16,005,826 members
Home / Discussions / C#
   

C#

 
QuestionHow to create a "Double Click event" Pin
lee meng11-Jan-05 20:47
lee meng11-Jan-05 20:47 
AnswerRe: How to create a "Double Click event" Pin
Stefan Troschuetz11-Jan-05 21:20
Stefan Troschuetz11-Jan-05 21:20 
GeneralRe: How to create a "Double Click event" Pin
J4amieC11-Jan-05 22:30
J4amieC11-Jan-05 22:30 
GeneralRe: How to create a "Double Click event" Pin
Stefan Troschuetz11-Jan-05 22:43
Stefan Troschuetz11-Jan-05 22:43 
GeneralRe: How to create a "Double Click event" Pin
lee meng12-Jan-05 4:06
lee meng12-Jan-05 4:06 
GeneralRe: How to create a "Double Click event" Pin
Stefan Troschuetz12-Jan-05 4:15
Stefan Troschuetz12-Jan-05 4:15 
AnswerRe: Thank You Pin
lee meng12-Jan-05 5:46
lee meng12-Jan-05 5:46 
GeneralProblem with parameters (Registry) Pin
FireDK11-Jan-05 20:43
FireDK11-Jan-05 20:43 
Following is a sample of a C# class I created for one of my software projects.
I use it to register my application in the shortcut menu (right-click menu) of
all the files and folders of the HDD. I chose a simple registry approach to
this problem beacause I find it much easier than buiding and registering a COM
object (and I must say I'n not really into COM programming right now, so it
will be kinda hard for me to learn now, having to finish my project a.s.a.p.).

Basicly, the Associate function takes three parameters, the name of the
extension, the desired text to display and the path to the .exe file. (EG. If I
need to register DoIt that is located at C:\DoIt.exe and display the text DoIt
in the menu i use Associate("DoIt", "&DoIt", "C:\DoIt.exe") ). It works by
going to HKEY_CLASSES_ROOT in the registry and opening/creating the
AllFileSystemObjects subkey, whitch handles all the files and folders. It then
creates three new subkeys in this order shell \ extensionName \ command and
registers the .exe so that it is displayed in the right-click menu.

Everything works well, but I still have a problem. I need the path of the file
or folder on whitch I right-click to be sent as a parameter to my main
application (same as using command-line parameters) and I do this by adding %1
after my application's path in the registry (line 26 of the class). However,
this works only if I have a single file or folder selected and I was wondering
if it is possible to use this method to send multiple paths as parameters to my
application (by selecting multiple files or folders or both).

I would really appreciate your help beacause I'm... well, stuck. Smile | :) 10x a lot.

P.S. Please don't hate me for the long description or for the almost childish
manner that I used to express it, but I wanted my problem thoroughly
understood. No offence meant.



using System;
using Microsoft.Win32;

namespace ShellExtension
{
	public class ShellExtension
	{
		public ShellExtension() { }
		
		public void Associate(string extensionName, string extensionText, string filePath)
		{
			RegistryKey ClassesRoot = Registry.ClassesRoot;
			RegistryKey AllFileSystemObjects = ClassesRoot.OpenSubKey("AllFileSystemObjects", true);
			if (AllFileSystemObjects != null)
			{
				RegistryKey shell = AllFileSystemObjects.OpenSubKey("shell", true);
				if (shell != null)
				{
					shell.SetValue("", extensionName);
					shell.CreateSubKey(extensionName);
					
					RegistryKey shell_1 = shell.OpenSubKey(extensionName, true);
					shell_1.SetValue("", extensionText);
					shell_1.CreateSubKey("command");
					
					RegistryKey shell_2 = shell_1.OpenSubKey("command", true);
					shell_2.SetValue("", "\"" + filePath + "\" \"%1\"");
					
					return;
				}
				else
				{
					AllFileSystemObjects.CreateSubKey("shell");
					this.Associate(extensionName, extensionText, filePath);
					return;
				}
			}
			else
			{
				ClassesRoot.CreateSubKey("AllFileSystemObjects");
				this.Associate(extensionName, extensionText, filePath);
				return;
			}
		}
		
		public void unAssociate(string extensionName)
		{
			RegistryKey ClassesRoot = Registry.ClassesRoot;
			RegistryKey AllFileSystemObjects = ClassesRoot.OpenSubKey("AllFileSystemObjects", true);
			RegistryKey shell = AllFileSystemObjects.OpenSubKey("shell", true);
			
			if (shell.OpenSubKey(extensionName) != null)
			{
				shell.DeleteSubKeyTree(extensionName);
			}
			
			return;
		}
	}
}


Born from the dark, in the black cloak of night.
GeneralDatetime regional format Pin
sevan11-Jan-05 19:09
sevan11-Jan-05 19:09 
GeneralRe: Datetime regional format Pin
Stefan Troschuetz11-Jan-05 21:05
Stefan Troschuetz11-Jan-05 21:05 
GeneralTwo Assemblies in GAC Pin
IamADotNetGuy11-Jan-05 18:58
IamADotNetGuy11-Jan-05 18:58 
GeneralRe: Two Assemblies in GAC Pin
Jesse Squire12-Jan-05 7:01
Jesse Squire12-Jan-05 7:01 
GeneralRe: Two Assemblies in GAC Pin
IamADotNetGuy12-Jan-05 18:14
IamADotNetGuy12-Jan-05 18:14 
GeneralRe: Two Assemblies in GAC Pin
Jesse Squire13-Jan-05 2:26
Jesse Squire13-Jan-05 2:26 
GeneralRef Key word Pin
IamADotNetGuy11-Jan-05 18:55
IamADotNetGuy11-Jan-05 18:55 
GeneralRe: Ref Key word Pin
Corinna John11-Jan-05 21:02
Corinna John11-Jan-05 21:02 
GeneralRe: Ref Key word Pin
leppie12-Jan-05 6:22
leppie12-Jan-05 6:22 
GeneralRe: Ref Key word Pin
Corinna John12-Jan-05 7:19
Corinna John12-Jan-05 7:19 
GeneralHangs while opening word in C# Pin
itssuk11-Jan-05 18:37
itssuk11-Jan-05 18:37 
GeneralRe: Hangs while opening word in C# Pin
Dave Kreskowiak12-Jan-05 4:29
mveDave Kreskowiak12-Jan-05 4:29 
QuestionWhen will be the missing APIs be available with .NET FCL? Pin
Salil Khedkar11-Jan-05 18:25
Salil Khedkar11-Jan-05 18:25 
GeneralEBCDIC to ASCII Pin
Talktorajeev11-Jan-05 18:13
Talktorajeev11-Jan-05 18:13 
GeneralDisplaying an icon in a PictureBox control Pin
Member 131681311-Jan-05 17:53
Member 131681311-Jan-05 17:53 
GeneralInsert marks Pin
RockRock11-Jan-05 17:30
RockRock11-Jan-05 17:30 
QuestionCan someone suggest?... Pin
Synthia211-Jan-05 17:02
Synthia211-Jan-05 17:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.