Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I am a begginer regarding to Windows right-click context menus.However i added a submenu with two options, which appears whenever you select images. Both options call the same application but for different features. how can I know which option was selected from my submenu? It is possible?

please forgive me for my terrible english..
Posted
Comments
Dean Oliver 12-Mar-12 10:11am    
wpf or winforms? please supply code as well.
MarleneLV 12-Mar-12 10:48am    
thank you for your answer, i'll try to explain my problem a bit more detailed.

From the beginning:

I added a submenu on windows explorer context menu when images are selected, this way:

[HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\Test]
"MUIVerb"="test"
"SubCommands"="option1;option2"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\option1]
@="option1"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\option1\command]
@="\"ApplicationTeste.exe\" \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\option2]
@="option2"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\option2\command]
@="\"ApplicationTeste.exe\" \"%1\""

I saved the above lines in a registry file and i merge it, to add the submenu. That way i get a submenu like this:

MySubmenu -> option1
-> option2

After that my problem was to get all the selected images, but as far as i search, using the "%1" i only get one argument by instance. (if i select more than one image and select my submenu option it will open 'n' instances).
To prevent that my application open an instance for each image i put the following code on my program class:

namespace WindowsFormsApplicationTeste
{
static class Program
{
///
/// The main entry point for the application.
///

static Mutex mutex = new Mutex(true, "{8F6F0AC4-B9A1-45fd-A8CF-72F04E6BDE8F}");
[STAThread]

static void Main()
{
if (mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
mutex.ReleaseMutex();
}
else
{
Thread.Sleep(3000);
MessageBox.Show("I'm sleeping");
Process.GetCurrentProcess().Kill(); // or Application.Exit(); or anything else
}
}
}
}

And after that i'm checking if my application is already running if it is i just put the tread sleeping to get the others instances arguments like this:

string processName = "myApplication.exe";

string wmiQuery = string.Format("select CommandLine from Win32_Process where Name='{0}'", processName);

ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();

foreach (ManagementObject retObject in retObjectCollection)
{
string text = "";
text = retObject["CommandLine"].ToString();
}

At the moment my problem is that i need to know which was the selected submenu option because both of them are pointing to the same application.exe. The aim is to send the images to different features,for example, like this:

if option1 was selected
send to myApplication the code 1 and the images selected

if option2 was selected
send to myApplication the code 2 and the images selected


I hope someone can help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900