Solved

adding customapp to explorer rightclick

Posted on 2006-10-27
12
384 Views
Last Modified: 2008-01-09
friends,

when we do a right click on a file in 'windows explorer', we get options like 'notepad', 'winzip', 'edit with visual studio'.

1. now how can i add a customapplication to this list when i right click a file?

2. once this is click, what should i do in my customapplication to open this file? basically how do i get to know, which file needs to be opened.

i need vb6 code.
0
Comment
Question by:expertfan
  • 9
  • 2
12 Comments
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
Hi expertfan,

You're trying to do something like Winzip does, when you right click a file and you get the option "Extract To...", right?

I'v been trying to figure out how to do this for 6 months. So far, I have only gotten a little information.

1. The right click is a CLSID.
2. It refers / calls / executes (pick your terminology) a DLL.

How to write the DLL and register it so that it will show up in the context menu, I have no idea. So, I'll be watching this thread. Good luck.

Cheers!
0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
expertfan,

BTW... if you want to do it with a file folder on the folder list tree, you would need to do this:

1. HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell
2. Create a key under shell, and name it what you want it to appear in the right click context menu.
3. Create another key under that called "command" (no quotes).
4. Put in the full path to the executable, followed by %1 %2 %3, etc... as needed to pass vars to the file (ex: c:\windows\system32\cmd.exe %1 will open a command prompt in that folder).

Cheers!
-Doc.
0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
expertfan,

Some more information:

Winrar is the example I use. You right click a rar file, you get the context menu commands like we're looking for.

Under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WinRAR\shellex we have:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WinRAR\shellex\ContextMenuHandlers
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WinRAR\shellex\ContextMenuHandlers\{B41DB860-8EE4-11D2-9906-E49FADC173CA}.

If you look up {B41DB860-8EE4-11D2-9906-E49FADC173CA}, you find this:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{B41DB860-8EE4-11D2-9906-E49FADC173CA}
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{B41DB860-8EE4-11D2-9906-E49FADC173CA}\InProcServer32

It is this final value that has the following values:
(Default)                             REG_SZ                               C:\Program Files\WinRAR\rarext.dll
Threading Model                  REG_SZ                               Apartment

It is this dll that will process the file you right click on.

This is everything I know. Hope it can lead you or some other experts to the right place!

0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
expertfan,

I just found this too:
http://www.oreilly.com/catalog/vbshell/chapter/ch04.html

It may hold some clues for us.

Cheers!
-Doc
0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
expertfan,

THis is how it is done in Delphi, which may also help: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=536&lngWId=7
0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
expertfan,

The last post has an attachement that is a VB6 project. It should be the answer we are looking for. Here are the remarks from the project:

   ' =======================
   ' VB Context Menu Handler
   ' =======================
   '
   '    by Jim White, MathImagical Systems, NSW Australia
   '
   '    email: mathimagics@yahoo.co.uk
   '
   ' cMenu class - when this DLL is registered, AND there is a reference
   '               to our ClassId in the "ContextMenuHandlers" key for some
   '               file association(s) in the registry, then Explorer will
   '               create an instance of this class when the user right-clicks a
   '               file of that type.
   '
   '               At some stage in the life cycle of the cMenu object,
   '               Explorer will invoke the IContextMenu::QueryContextMenu
   '               method, which gives us the opportunity to insert
   '               a menu option of our own (if we choose to do so).
   '
   '               If the user then clicks on the option we insert,
   '               Explorer will invoke the IContextMenu::InvokeCommand
   '               method - this is the equivalent of the "Click" event
   '               procedure for a normal VB menu.
   '
   ' There are two interfaces that must be implemented for Explorer to be
   ' able to transfer data to and from this dll. They are declared in the
   ' accompanying type libraries (.tlb files) - don't modify or lose them!
0
 

Author Comment

by:expertfan
Comment Utility
DrDamnit,

this is cool, onclicking the context-menu, this code is showing a 'message box', but how do i invoke (or launch) an EXE?
'---------------------


Private Sub IContextMenu_InvokeCommand(ByVal lpcmi As Long)
   Dim CMI         As CMINVOKECOMMANDINFO
   CopyMemory CMI, ByVal lpcmi, Len(CMI)

   '=======================================================
   '  The user has clicked one of our context menu options!
   '=======================================================
   
   Dim Display As String
   Display = "File clicked was: " & SelectedFile & vbLf & vbLf
   If CMI.lpVerb < 3 Then
      Display = Display & "ContextMenu item ID = " & CMI.lpVerb
   Else
      Display = Display & "SubMenu item ID = " & CMI.lpVerb
    End If
   
   MessageBox 0&, Display, "MathImagics", vbInformation
End Sub
0
 
LVL 32

Accepted Solution

by:
DrDamnit earned 500 total points
Comment Utility
In a module, declare shellexecute:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

the use the following command to execute the exe:

lRet = ShellExecute(Me.hwnd, "open", [PATH TO EXE], [EXE PARAMETERS], [APPLICATION DIRECTORY], SW_SHOWNORMAL)
0
 

Author Comment

by:expertfan
Comment Utility
DrDamnit, thanks !! this works great.
0
 
LVL 32

Expert Comment

by:DrDamnit
Comment Utility
I can't wait to try it out. I have been trying to do that forever!

...wouldn't you know, it takes serving others before you can find a means to your own end..... :-)

Glad to help.
0
 

Expert Comment

by:Muncky
Comment Utility
Hello,
I appreciate this is an old post, But the Link that DrDamnit put up from Jim White is awesome, but i cannot build the DLL due to not having VB6, do you know if it is possible to make it happen in visual studio 2010?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now