Results 1 to 16 of 16

Thread: Global Shell menu extension [resolved]

  1. #1

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Resolved Global Shell menu extension [resolved]

    Is it possible to create a shell menu extension (file or folder right-click menu) to allow opening it with my application?
    Last edited by baja_yu; Mar 12th, 2005 at 10:02 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Global Shell menu extension

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Last edited by manavo11; Feb 6th, 2005 at 04:19 PM.


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    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...

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Global Shell menu extension

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    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?

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Global Shell menu extension

    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.

    ...

  8. #8

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    Thanks. But what about files? I have added it to the "*" and it still only worked for exe file...

  9. #9

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    Anyone else have any ideas?

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Global Shell menu extension

    How about:
    HKEY_CLASSES_ROOT\*\OpenWithList\MyProg.exe

    ...

  11. #11

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    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.

  12. #12

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension

    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

  13. #13

    Thread Starter
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Global Shell menu extension (almost resolved)

    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:
    1. Private Sub IShellExtInit_Initialize(ByVal pidlFolder As Long, ByVal lpdobj As Long, ByVal hKeyProgID As Long)
    2.    
    3.        Dim strVal      As String
    4.        Dim pIDataObj   As IUnknown
    5.        Dim oIDataObj   As IDataObject
    6.        Dim FmtEtc      As FORMATETC
    7.        Dim pMedium     As STGMEDIUM
    8.        Dim szTemp      As String
    9.        Dim iFile       As Long
    10.        Dim rc          As Long
    11.    
    12.        CopyMemory pIDataObj, lpdobj, 4
    13.        Set oIDataObj = pIDataObj
    14.        ' oIDataObj now stores the object required
    15.        CopyMemory pIDataObj, 0&, 4
    16.        ' Set the format to get the data in...
    17.        With FmtEtc
    18.           .cfFormat = CF_HDROP
    19.           .ptd = 0
    20.           .dwAspect = DVASPECT_CONTENT
    21.           .lindex = -1
    22.           .tymed = TYMED_HGLOBAL
    23.           End With
    24.    
    25.        ' ... and store it in our medium
    26.        oIDataObj.GetData ByVal VarPtr(FmtEtc), ByVal VarPtr(pMedium)
    27.        rc = Err.LastDllError 'Check for errors
    28.        
    29.         Dim filename As String        'the dropped filename
    30.         Dim numOfDroppedFiles As Long 'the number of dropped files
    31.         Dim curFile As Long           'the current file number
    32.    
    33.         SelectedFile = ""
    34.  
    35.         'get the total number of files
    36.         numOfDroppedFiles = DragQueryFile(pMedium.hGlobal, True, filename, Len(filename))
    37.        
    38.         For curFile = 1 To numOfDroppedFiles
    39.             'get the file name
    40.             filename = String(260, 0)
    41.             rc = DragQueryFile(pMedium.hGlobal, curFile - 1, filename, Len(filename))
    42.             DoEvents
    43.             'at this pointer you can do what you want with the filename
    44.             'the filename will be a full qualified path
    45.             If curFile = 1 Then
    46.                 SelectedFile = Left$(filename, rc)
    47.             Else
    48.                 SelectedFile = SelectedFile & "|" & Left$(filename, rc)
    49.             End If
    50.             DoEvents
    51.         Next curFile
    52.         'we are now done with the structure, tell windows to discard it
    53.         DoEvents
    54.        
    55.         rc = ReleaseStgMedium(pMedium)
    56.         Set oIDataObj = Nothing
    57.         DoEvents
    58.     End Sub

    Thanks to everyone that helped.
    Last edited by baja_yu; Nov 24th, 2009 at 10:39 PM.

  14. #14
    New Member
    Join Date
    Jun 2005
    Posts
    1

    Re: Global Shell menu extension [resolved]

    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.
    Last edited by Clawsy; Jun 19th, 2005 at 06:33 PM.

  15. #15
    Frenzied Member
    Join Date
    Apr 2003
    Location
    The Future - Skynet
    Posts
    1,157

    Re: Global Shell menu extension (almost resolved)

    Quote Originally Posted by baja_yu
    Ok... I've got it... the solution to multiple selections that is:

    Use the code in the link I posted... then, replace the existing procedure with this one:

    VB Code:
    1. Private Sub IShellExtInit_Initialize(ByVal pidlFolder As Long, ByVal lpdobj As Long, ByVal hKeyProgID As Long)
    2.    
    3.        Dim strVal      As String
    4.        Dim pIDataObj   As IUnknown
    5.        Dim oIDataObj   As IDataObject
    6.        Dim FmtEtc      As FORMATETC
    7.        Dim pMedium     As STGMEDIUM
    8.        Dim szTemp      As String
    9.        Dim iFile       As Long
    10.        Dim rc          As Long
    11.    
    12.        CopyMemory pIDataObj, lpdobj, 4
    13.        Set oIDataObj = pIDataObj
    14.        ' oIDataObj now stores the object required
    15.        CopyMemory pIDataObj, 0&, 4
    16.        ' Set the format to get the data in...
    17.        With FmtEtc
    18.           .cfFormat = CF_HDROP
    19.           .ptd = 0
    20.           .dwAspect = DVASPECT_CONTENT
    21.           .lindex = -1
    22.           .tymed = TYMED_HGLOBAL
    23.           End With
    24.    
    25.        ' ... and store it in our medium
    26.        oIDataObj.GetData ByVal VarPtr(FmtEtc), ByVal VarPtr(pMedium)
    27.        rc = Err.LastDllError 'Check for errors
    28.        
    29.         Dim filename As String        'the dropped filename
    30.         Dim numOfDroppedFiles As Long 'the number of dropped files
    31.         Dim curFile As Long           'the current file number
    32.    
    33.         SelectedFile = ""
    34.  
    35.         'get the total number of files
    36.         numOfDroppedFiles = DragQueryFile(pMedium.hGlobal, True, filename, Len(filename))
    37.        
    38.         For curFile = 1 To numOfDroppedFiles
    39.             'get the file name
    40.             filename = String(260, 0)
    41.             rc = DragQueryFile(pMedium.hGlobal, curFile - 1, filename, Len(filename))
    42.             DoEvents
    43.             'at this pointer you can do what you want with the filename
    44.             'the filename will be a full qualified path
    45.             If curFile = 1 Then
    46.                 SelectedFile = Left$(filename, rc)
    47.             Else
    48.                 SelectedFile = SelectedFile & "|" & Left$(filename, rc)
    49.             End If
    50.             DoEvents
    51.         Next curFile
    52.         'we are now done with the structure, tell windows to discard it
    53.         DoEvents
    54.        
    55.         rc = ReleaseStgMedium(pMedium)
    56.         Set oIDataObj = Nothing
    57.         DoEvents
    58.     End Sub

    Thanks to everyone that helped.
    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.

    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.
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  16. #16
    New Member
    Join Date
    Jun 2009
    Posts
    1

    Thumbs up Re: Global Shell menu extension

    nice one to play with. Any way to add item to the Desktop context menu? Any one one have a .net port of these?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width