• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Right click on file or folder to launch app

Hi there,

I need to register all files and folders in Windows for a click on the right mouse button to open a context menu.

The program referred to in the context menu (the one I'm going to write) must get all selected files and folders as a parameter list when the user clicks the context menu entry. What can I do to achieve that? As I interprete from WinRAR's registry entries (I used that as my reference to find out a way to do it), i guess I need to write a COM+ object.

It's definately not enough for me to use HKEY_CLASSES_ROOT\*\shell\... for that because then my test program pops up once for each selected file. For folders, the registry entry does not work either. If you have a solution that way, you're welcome anyway.

So, if needed, where can I find REALLY good COM+ beginner's references and some easy-to-understand exampled? What's the best way to start with COM+?

Using C++ is not an option because my time is very, very limited and I'm really no C++ pro.
1 Solution
zzconsumer, you can do it using the *\shell method in fact, what you have to do is to create a text box in your application that uses DDE. Set the form as a DDE source and then use App.PrevInstance to detect whether this is the first or a subsequent instance of the application, if it is the first then store the passed command line parameter, if a subsequent one then you use a DDE Poke to the original application to send the filename passed in as the command line parameter to the textbox. Then on the change event of this textbox add it to your list and terminate the subsequent instance, this way you end up with one instance that has a complete list of your selected files. I have a code sample somewhere that uses this method. I will dig it out and post it for you.
Here it is in its simple form, just change TDDE to the name of your executable, add two textboxes and set the form to be a DDE source.

Private Sub Form_Load()
  If App.PrevInstance Then
      Text2.LinkTopic = "TDDE|Form1"
      Text2.LinkItem = "Text1"
      Text2.LinkMode = vbLinkAutomatic
      Text2.Text = Command()
  End If
End Sub

Private Sub Text1_Change()
  MsgBox Text1.Text
' Here you would add the new item to a list and / or process this filename.
End Sub
zzconsumerAuthor Commented:
Thanks! There are still some things I'm wondering about:

Still belonging to the question:
Can I register folders the same or a similar way?

And just for interest:
Do I really need to use a Textbox?
Can you give a short explanation why I need two textboxes?
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

As for folders, I don't actually know but will look into it. Yes you do need to use a textbox, well two in fact because these are controls that support DDE functionality, one to send and one to receive the data. There may be other controls that support this as well but they don't necessarily have the required _Change event to handle new data - the label control is an example of this. I use two textboxes really to avoid confusion, I suppose that you could use just one and treat it as a sender in one instance and a receiver in the other.
zzconsumerAuthor Commented:
That's it! Thanks a lot!
i did something similar, but in a different way,
i added a shortcut to the SENDTO folder, when the userclicks that shortcut, everything that were selected
passes as a parameter to the application referenced in the shortcut.

example:    test.bat shortcut is created in the sendto folder

test.exe contains:

Option Explicit
Sub Main()
MsgBox Command$
End Sub

when you select c:\command.com and right click and sendto test.bat

the msgbox is created with:

if you select 2 folders and 1 file, the following is created

"C:\Documents and settings" C:\command.com C:\windows

quotes surround names with spaces on them.

you can then parse the command$ as you need it
this is an easy way to do what you want, but i dont know if it works this way when not called from the sendto.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now