Is it possible to create a shell menu extension (file or folder right-click menu) to allow opening it with my application?
Printable View
Is it possible to create a shell menu extension (file or folder right-click menu) to allow opening it with my application?
Yes, it is. It take some registry hacks and adding some shell extensions. I just came accross it about two
weeks ago. Let me searh for the link. Be back.
I think this is what you want :)
http://www.vbforums.com/showpost.php...17&postcount=5
Or : http://www.vbforums.com/showthread.p...hreadid=183880
Thanks manavo for the example, but I couldnt get it to work. What values exactly would I need to add the the registry to make this happen? And more importantly in what format? I must be doing something wrong...
In the second link's thread there is a demo project attachment that you should
download. It has all you need and its very good.
Direct link to actual post with demo attachment
HTH
Thanks, I got it working partially like I wanted to. The only thing I couldnt do is make it work for any file/folder type.
I tried editing the .reg file so it registers the context menu in the "*" instead of "exefile" key but that didn't help, they still only worked for exe files.
Any ideas?
To add a context menu for any folder, Put the CLSID of your context menu handler in
HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\yourprogram (default) {YourCLSID}
You're also supposed to be able to add to the context menu for the Explorer Background in,
HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\yourprogram (default) {YourCLSID}
But I've never gotten this one to work.
...
Thanks. But what about files? I have added it to the "*" and it still only worked for exe file...
Anyone else have any ideas?
How about:
HKEY_CLASSES_ROOT\*\OpenWithList\MyProg.exe
...
Yes but that will subordinate it to the Open with item which does not always show. It only shows for unknown file types and for all when you hold Shift when opening the menu.
I got it to work for all file types and folders by adding references to these keys:
HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\AppName
HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\AppName
HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\AppName
HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\AppName
Now, I just have to find a way to make it detect when multiple (a group) files are selected and I'm set :)
Ok... I've got it... the solution to multiple selections that is:
Use the code in the link RobDog posted... then, replace the existing procedure with this one:
VB Code:
Private Sub IShellExtInit_Initialize(ByVal pidlFolder As Long, ByVal lpdobj As Long, ByVal hKeyProgID As Long) Dim strVal As String Dim pIDataObj As IUnknown Dim oIDataObj As IDataObject Dim FmtEtc As FORMATETC Dim pMedium As STGMEDIUM Dim szTemp As String Dim iFile As Long Dim rc As Long CopyMemory pIDataObj, lpdobj, 4 Set oIDataObj = pIDataObj ' oIDataObj now stores the object required CopyMemory pIDataObj, 0&, 4 ' Set the format to get the data in... With FmtEtc .cfFormat = CF_HDROP .ptd = 0 .dwAspect = DVASPECT_CONTENT .lindex = -1 .tymed = TYMED_HGLOBAL End With ' ... and store it in our medium oIDataObj.GetData ByVal VarPtr(FmtEtc), ByVal VarPtr(pMedium) rc = Err.LastDllError 'Check for errors Dim filename As String 'the dropped filename Dim numOfDroppedFiles As Long 'the number of dropped files Dim curFile As Long 'the current file number SelectedFile = "" 'get the total number of files numOfDroppedFiles = DragQueryFile(pMedium.hGlobal, True, filename, Len(filename)) For curFile = 1 To numOfDroppedFiles 'get the file name filename = String(260, 0) rc = DragQueryFile(pMedium.hGlobal, curFile - 1, filename, Len(filename)) DoEvents 'at this pointer you can do what you want with the filename 'the filename will be a full qualified path If curFile = 1 Then SelectedFile = Left$(filename, rc) Else SelectedFile = SelectedFile & "|" & Left$(filename, rc) End If DoEvents Next curFile 'we are now done with the structure, tell windows to discard it DoEvents rc = ReleaseStgMedium(pMedium) Set oIDataObj = Nothing DoEvents End Sub
Thanks to everyone that helped.
The demo example posted here is wonderful! Thank you so much for making & posting it! This is totally awesome, I am so happy to have found this sample, it rocks!!
It is very easy to use. I was a bit confused about how you get a DLLs GUID and how to make my own project...(I have never made a dll before), but figured that out pretty soon when i googled for dll progid and had a general read about them.
Thanks a bunch for this demo. :D
I am in need of similar to the same thing. I created an exe and am able to get it to work for context menu. Only problem is when it fires off, it fires off multiple instance of the same exe because multiple files are selected.Quote:
Originally Posted by baja_yu
I posted a similar thread earlier today:
http://www.vbforums.com/showthread.php?t=503943
baja_yu or anyone, can you show me where to plug this procedure in and what to feed into it? I noticed pidlFolder and hKeyProgID are not used in the procedure.
nice one to play with. Any way to add item to the Desktop context menu? Any one one have a .net port of these?