Results 1 to 12 of 12

Thread: Add something to default Right Click Menu

  1. #1

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    365

    Add something to default Right Click Menu

    I have been wanting to know for a while how to do this, but I guess I dont exactly know what to look up to find it.

    How do you add a context menu/item to the default windows context menu for right clicking?

    Example: I right click on a picture, I want to add in "Open with ThisPictureViewer" as one of the top options.

    Any help or references that I can look into would be greatly appreciated!

    ~Frab
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    It's a registry setting. I created an Open with Paint contextmenuitem. What's the executable you want to open with?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\Open with Paint]

    [HKEY_CLASSES_ROOT\SystemFileAssociations\image\shell\Open with Paint\Command]
    @="Z:\\Documents\\Visual Studio 2008\\Projects\\runPaint\\runPaint\\bin\\Debug\\runPaint.exe %1"
    Change the highlighted text, then save as a .reg file. Doubleclick it to run and modify your registry...

    This is a windowless app i wrote (runPaint.exe). It handles the file paths sent from selecting Open with Paint in an image file contextmenu.
    Just change the highlighted app. path and compile it as an .exe


    Code:
    Module ModMain
        Public Sub main(ByVal args() As String)
            Dim path As String
    
            If Not args.First.StartsWith("::") Then
                path = IO.Path.GetFullPath(String.Join(" ", args))
            Else
                path = args.First
            End If
    
            Process.Start("C:\windows\system32\mspaint.exe", """" & path & """")
        End Sub
    End Module

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    If the image files were just an example, it'll need some adjusting, but it's a registry setting...

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    To add an option to open any file with notepad... (There's no problem with the fragmented file paths with this one)

    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with Notepad]

    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\Open with Notepad\Command]
    @="C:\\Windows\\notepad.exe %1"

  6. #6

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    365

    Re: Add something to default Right Click Menu

    Wow! Thank you Paul! Great help as always!

    Sorry I had to cut out for a bit. I will look over this information and get back with you if I have any issues or questions !

    Thanks!
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  7. #7

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    365

    Re: Add something to default Right Click Menu

    Quote Originally Posted by .paul. View Post
    To add an option to open any file with notepad... (There's no problem with the fragmented file paths with this one)

    Thank you! That worked out perfectly!

    I do have another question, how could I add an icon to this option?

    For anyone wandering, this is the completed code:

    Code:
                Dim RCK As String = "SystemFileAssociations\image\shell\Convert with " & ProgramName
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK)
                Dim exePath As String = Application.ExecutablePath()
                exePath.Replace("\", "\\")
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK & "\Command")
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK & "\DefaultIcon")
    
    
                Dim autoshell = My.Computer.Registry.ClassesRoot.OpenSubKey(RCK & "\Command", True)
                autoshell.SetValue("", """" & exePath & """ ""%1""")
    
                MsgBox("Successfully installed to Right Click Menu Options.")
    Last edited by Frabulator; Apr 26th, 2021 at 09:47 PM.
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    Quote Originally Posted by Frabulator View Post
    Thank you! That worked out perfectly!

    I do have another question, how could I add an icon to this option?

    For anyone wandering, this is the completed code:

    Code:
                Dim RCK As String = "SystemFileAssociations\image\shell\Convert with " & ProgramName
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK)
                Dim exePath As String = Application.ExecutablePath()
                exePath.Replace("\", "\\")
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK & "\Command")
                My.Computer.Registry.ClassesRoot.CreateSubKey(RCK & "\DefaultIcon")
    
    
                Dim autoshell = My.Computer.Registry.ClassesRoot.OpenSubKey(RCK & "\Command", True)
                autoshell.SetValue("", """" & exePath & """ ""%1""")
    
                MsgBox("Successfully installed to Right Click Menu Options.")
    Iím not sure how to add an icon. Have you tried your new contextmenuitem with a file in Program Files, or any folder with a space in the name? You might find it doesnít work. The file names become fragmented. You have to handle that...

  9. #9

    Thread Starter
    Hyperactive Member Frabulator's Avatar
    Join Date
    Jan 2015
    Posts
    365

    Re: Add something to default Right Click Menu

    Quote Originally Posted by .paul. View Post
    Iím not sure how to add an icon. Have you tried your new contextmenuitem with a file in Program Files, or any folder with a space in the name? You might find it doesnít work. The file names become fragmented. You have to handle that...
    Yes I have, and it seems to work fine.

    I found that there is a directory inside the image directory called 'DefaultIcon', which is then linked to a DLL and a line number. I would assume that I can modify this in some way to create an icon for the program.

    If I find more out I will get back with you

    Thanks for your help!
    Oops, There it goes. Yep... my brain stopped...
    _________________________________

    Useful Things:

    How to link your VB.Net application to Excel

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu


  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    Have a look at this page... I was able to add icons to two of my menuitems

    https://www.winhelponline.com/blog/a...enu-windows-7/

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,968

    Re: Add something to default Right Click Menu

    Iíve managed to assign default notepad and bitmap icons, and by changing the icon in one of my apps used in a right click menu, I could also set an icon for that. Itís not the DefaultIcon directory

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