4 Replies - 2291 Views - Last Post: 27 February 2012 - 09:32 PM Rate Topic: -----

#1 manhthaodn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-February 12

Adding icon program to context menu and processing!

Posted 24 February 2012 - 06:58 PM

I have made program for the purpose of processing data obtained from excel file.

When package to install my program (use visual studio setup project). I am having a problem as follows:

1. How do you install the program, the program's icon is added to context menu (Eg: when I right click on excel file (.xls) will see the icon of the program (my program'name). This work similar to when right click on the file extension .rar will see winrar program. I want to know whether visual studio setup project can not support this?

2. And how to transmit parameters into my program. My goal when I right-click the excel file and select icon my program from context menu, program will be activated, then my program will read data from that excel file.

I know this is a common task of a software program. But I'm really confused with it. I really want to understand how this should?

Thanks!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Adding icon program to context menu and processing!

#2 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Adding icon program to context menu and processing!

Posted 24 February 2012 - 10:30 PM

Well, the simplest way is through a registry entry. Here's the basic theory:

http://www.codeproje...indows-Explorer

That'll show you how to add any particular entry through code. The first part is the name, the second, the command.

Of course, you want parameters, so you'll need to change it up a bit. This is a good example of that:

http://www.howtogeek...-for-all-files/

It shows how to add a command "Open with Notepad", which includes a parameter. Basically, it'll be the full path to your app, followed by %1 (which represents the first parameter, the file name).

Now, you can do this with the installer project. There's a way to add registry keys. I've never actually done it, but you should be able to do it with the Add interface.

Next, you'll need to know how to get the command line parameters. Well, if you've ever wondered what the string[] args parameter in the main method is for, that's it. It contains the command line parameters used to launch your program. Also, they should be accessible through the Environment static class. Here's an example of how to do that: http://msdn.microsof...ndlineargs.aspx
Was This Post Helpful? 0
  • +
  • -

#3 manhthaodn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-February 12

Re: Adding icon program to context menu and processing!

Posted 26 February 2012 - 07:59 PM

Dear Curtis Rutland,

I tried the way you instruct. As a result I have registered the program's icon in context menu (right click excel file to see my program 'icon). However, when I select my program an error message appears: "This file does not have a program associated with it for performing this action"

I understand that I have not been transfer parameter of excel file in my program. Although, if I turn on the program and select path to excel file from my program, the program is still read data from excel file (ie open excel file from the program without opening the excel file right click on excel file).

So my program is missing something to be able to load the contents of the excel file. Although still able to load the contents of excel file if select the path to excel file from the program.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Adding icon program to context menu and processing!

Posted 27 February 2012 - 06:06 AM

That probably means that you didn't put the path to your program in correctly. It's not a problem with the parameter, you have to use the full path to your executable in the registry key.

Also, when you do that, you'll have to change your program too. You'll have to change the program to use the args or [/il]Environment.GetCommandLineArgs[/il] parameter/property.
Was This Post Helpful? 0
  • +
  • -

#5 manhthaodn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-February 12

Re: Adding icon program to context menu and processing!

Posted 27 February 2012 - 09:32 PM

Dear Curtis Rutland,

I tried the following code:

public bool AddContextMenuItem(string Extension, string MenuName, string MenuDescription, string MenuCommand)
        {
            bool ret = false;
            RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(Extension);

            if (rkey != null)
            {
                string extstring = rkey.GetValue("").ToString();

                rkey.Close();

                if (extstring != null)
                {
                    if (extstring.Length > 0)
                    {
                        rkey = Registry.ClassesRoot.OpenSubKey(extstring, true);

                        if (rkey != null)
                        {
                            string strkey = "shell\\" + MenuName + "\\command";

                            RegistryKey subky = rkey.CreateSubKey(strkey);

                            if (subky != null)
                            {
                                subky.SetValue("", MenuCommand);
                                subky.Close();
                                subky = rkey.OpenSubKey("shell\\" + MenuName, true);
                                if (subky != null)
                                {
                                    subky.SetValue("", MenuDescription);
                                    subky.Close();
                                }
                                ret = true;
                            }
                            rkey.Close();
                        }
                    }
                }
            }

            return ret;
        }      


And call it:
AddContextMenuItem(".xls", "EasyForm", "Open with &EasyForm", menuCommand);


However, I still can not load content from the excel file.

However, I still can not download content from the excel file. The picture below is my program to load excel file if only the direct path from the program

Posted Image

And the program still does not load the contents of the excel file when selecting the program from the context menu (choose program in context menu when right click on excel file). The picture below:

Posted Image

I can not understand why?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1