Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Add a context menu item in Windows Explorer (C/C++, no MFC)

Add a context menu item in Windows Explorer (C/C++, no MFC)

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestioncsharpcom
6 Posts 3 Posters 23 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Derell Licht
    wrote on last edited by
    #1

    This seems like a question that should be easy to find an answer to, but I'm not finding anything very convenient... What I will want to do with this, is to be able to right-click on a folder in Explorer, and have an item "run my program on this folder" available... I've found two example programs which do this, but each have drawbacks for my application; 1. one is a C# application (which I'm not familiar with, though it *is* pretty similar). Also, this CodeProject application is using registry modification to do the job; I would prefer to find a link somehow to the Explorer menu, then use InsertMenuItem() from WinAPI to add a link to my application... 2. that brings me to the second example that I found; it's in an older Platform SDK, in a utility called Shell\SampView... that application *does* do what I wish; however, that application is over 8500 lines long!! I am hoping to find a more concise solution to the problem... Can anyone provide any guidance or example code for this?? I use C++, and build with the MinGW (32-bit) toolchain... and yes, I realize that once I get *this* issue resolved, I'll still have a variety of other issues to resolve, such as finding the path to my application, and dealing with selection of wrong items (ideally, perhaps just grey out my menu item if the target is not a folder), and many other things, but for now, I just want to find a concise, clear solution to this one problem.

    V 1 Reply Last reply
    0
    • D Derell Licht

      This seems like a question that should be easy to find an answer to, but I'm not finding anything very convenient... What I will want to do with this, is to be able to right-click on a folder in Explorer, and have an item "run my program on this folder" available... I've found two example programs which do this, but each have drawbacks for my application; 1. one is a C# application (which I'm not familiar with, though it *is* pretty similar). Also, this CodeProject application is using registry modification to do the job; I would prefer to find a link somehow to the Explorer menu, then use InsertMenuItem() from WinAPI to add a link to my application... 2. that brings me to the second example that I found; it's in an older Platform SDK, in a utility called Shell\SampView... that application *does* do what I wish; however, that application is over 8500 lines long!! I am hoping to find a more concise solution to the problem... Can anyone provide any guidance or example code for this?? I use C++, and build with the MinGW (32-bit) toolchain... and yes, I realize that once I get *this* issue resolved, I'll still have a variety of other issues to resolve, such as finding the path to my application, and dealing with selection of wrong items (ideally, perhaps just grey out my menu item if the target is not a folder), and many other things, but for now, I just want to find a concise, clear solution to this one problem.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Read [ How add context menu item to Windows Explorer for folders or files -Advanced Installer](https://www.advancedinstaller.com/forums/viewtopic.php?t=49822). Then read the Microsoft documentation about using Registry API functions. Finally implement the described actions in your code.

      D 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Read [ How add context menu item to Windows Explorer for folders or files -Advanced Installer](https://www.advancedinstaller.com/forums/viewtopic.php?t=49822). Then read the Microsoft documentation about using Registry API functions. Finally implement the described actions in your code.

        D Offline
        D Offline
        Derell Licht
        wrote on last edited by
        #3

        Okay, I don't have any problem with the Registry API functions, I've used them before. I just expected that ShellAPI would be a more conventional way to do this; something similar to what is done with setting desktop icon colors, where we start with: HWND hwnd = FindWindow("Progman", "Program Manager"); hwnd = FindWindowEx(hwnd, NULL, "SHELLDLL_DefView", ""); hwnd = FindWindowEx(hwnd, NULL, "SysListView32", NULL); [ error handling omitted for clarity ] to gain access to elements under Program Manager... For one thing, the ShellAPI process would eliminate issues with permissions, which I might have with Registry access.. Anyway, I'll look into the links you've mentioned, and try those out.

        D 1 Reply Last reply
        0
        • D Derell Licht

          Okay, I don't have any problem with the Registry API functions, I've used them before. I just expected that ShellAPI would be a more conventional way to do this; something similar to what is done with setting desktop icon colors, where we start with: HWND hwnd = FindWindow("Progman", "Program Manager"); hwnd = FindWindowEx(hwnd, NULL, "SHELLDLL_DefView", ""); hwnd = FindWindowEx(hwnd, NULL, "SysListView32", NULL); [ error handling omitted for clarity ] to gain access to elements under Program Manager... For one thing, the ShellAPI process would eliminate issues with permissions, which I might have with Registry access.. Anyway, I'll look into the links you've mentioned, and try those out.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          If you depend on your application code making those changes, your app would have to run first before being able to use the Explorer context menu. Your code would also have to remember to remove those changes when it closes or upon uninstall. Doing it through registry pokes eliminates those problems and makes them permanent until uninstall, which can be handled entirely in the installer, not your code.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          D 1 Reply Last reply
          0
          • D Dave Kreskowiak

            If you depend on your application code making those changes, your app would have to run first before being able to use the Explorer context menu. Your code would also have to remember to remove those changes when it closes or upon uninstall. Doing it through registry pokes eliminates those problems and makes them permanent until uninstall, which can be handled entirely in the installer, not your code.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            D Offline
            D Offline
            Derell Licht
            wrote on last edited by
            #5

            That's a good point... for most situations that I'm thinking of using this tool, I wouldn't be removing the link once it was installed; it would be for situations such as "open this file in MyEditor", or "run MyUtility on this folder"... but yeah, initially creating the link has to be considered, in either case; My plan was to check for existence of my link when running the program, likely in WM_INITDIALOG.. if it's not there, create it. I mostly write small utilities, so don't always use a dedicated installer...

            D 1 Reply Last reply
            0
            • D Derell Licht

              That's a good point... for most situations that I'm thinking of using this tool, I wouldn't be removing the link once it was installed; it would be for situations such as "open this file in MyEditor", or "run MyUtility on this folder"... but yeah, initially creating the link has to be considered, in either case; My plan was to check for existence of my link when running the program, likely in WM_INITDIALOG.. if it's not there, create it. I mostly write small utilities, so don't always use a dedicated installer...

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              In that case, add command line switch support for installing your context menu items and removing them.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups