Results 1 to 33 of 33

Thread: Adding options to context-menus

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Adding options to context-menus

    Does anybody know how to add options to the context menu of an specific EXE file?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    anyone?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    anyone?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    You might already know this, but it's easy to add options to the context menu for a given extension, or for all extensions, using the Registry

    But to add options for specific individual files? I don't know, I suspect not


    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  5. #5

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Yes... I knew that. I guess it cannot be done.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    I know now that it CAN be done - still interested?
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  7. #7

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Yes, please.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Hi McBrain!

    Just letting you know I'm still on the case - right now I'm in the middle of of a few other things - I'll have to put you on hold for maybe a couple of hours.

    Meanwhile, can you describe the context? What would you actually like to happen when the user right-clicks one of your designated files in the Explorer window?

    Cheers

    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  9. #9

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I want to have custom options for one EXE only... not for all EXEs, just for my app´s exefile.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    hey, buddy, your signature block tends to hide your messages!!!!

    Where were we, oh yes, I know we are just interested in a single exe, and you want to insert a number of options, either in the main body of the context menu, or perhaps a submenu would look cooler.....

    I'll just make a fresh coffee, and write up my solution description, should be about 30 mins .... sorry for the delay, but hey, Rome wasn't built in a day (nor was Uki!)


    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  11. #11
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Serves me right for complaining! Now I get dizzy looking at the revolving chook!!!!!

    OK, I've got a rather lengthy, but I hope, informative, analysis of the topic "Context Menus You Can Prepare At Home, in 67 easy steps!"

    I hope it's not to big to post - I like to be thorough!!!!!

    Here we go ......
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  12. #12
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    When you first posted the question, I was just starting to get interested in context menus. I wanted to be able to open files with my own "Toolbox" programs.

    So I learned about how I could get an option into the context menu which would run a program which would show a menu for the Toolbox.

    This primitive but effective first step simply added a shell/command entry into the "*" and "folder" registry entries.

    One of my tools was a directory searcher, and I wanted to be able to right-click on the files in its ListView window, and invoke the same context menu I would get if I was in Explorer.

    I kinda hoped there would be a magic API function called something like ShellInvokeContextMenu(filename$).

    Silly me! No such animal of course (although there's no reason why they couldn't give us one!)

    So I asked myself, how does something like WinZip not only get an entry in the menu, but have a popup submenu of its own?

    Looking in the registry, I see that WinZip's entry is not a shell/command but a shellex/ContextMenuHandlers and it's entry is a thing looking awfully like a Class GUID!

    This was a bit intimidating at first, but I pursued it, searching for a clue as to whether a VB program could be a ContextMenuHandler.

    OK, I'm coming to the point, trust me!!!!


    About ContextMenuHandlers

    What's a ContextMenuHandler, and how does it work? (Please excuse my clumsy descriptions and terms, I'm not a COM/OLE/TypeLib/Interface guru!)

    1 It's an ActiveX DLL, and exposes a class called cMenu

    2 The class Implements 2 interfaces, IContextMenu and IShellExtInit

    3 When Explorer is building the context menu and finds ContextMenuHandlers in the registry, it uses the GUID value to create a cMenu object which activates the DLL.

    4 It invokes the DLL's IContextMenu::QueryContextMenu method, which is basically asking our DLL, "Hey, do you want to insert some menu items?", and very kindly passes us the menu handle for the context menu it's building.

    Cool stuff, eh? But how do we attach commands to the menu options we insert?

    5 If the user selects one of our inserted options, Explorer invokes our IContextMenu::InvokeCommand method!

    If it's that simple (well, relatively speaking, anyway!) why isn't it more commonly used by VB programmers?

    One reason could be that the way OLE passes parameters and return values to/from OLE object methods is NOT the way VB normally does! For reasons to do with the Type Libraries, the interface methods in our DLL have to be declared as Sub's, but sometimes are also expected to return a result!

    In the cMenu class, the IContextMenu::QueryContextMenu method has to tell Explorer how many items it inserted into the menu. This presents the VB ContextMenuhandler a problem, and one which has no obvious solution, which might explain why the VB forums aren't cluttered with VB examples!

    Searching the Web, I found an article where some (cool) guy had been down this path, and he somehow learned that the main guy responsible for the design and development of OLE (chap named Curzon) let it be known that there WAS a way to get around this impasse.

    The method, in a nutshell, is that our DLL includes a Function version of QueryContextmenu, which is written to return the correct result.

    In the cMenu.Initialize procedure, the DLL goes to the object's VTable - this is a table of AddressOf(Interface Method)'s - and simply replaces the entry for the QueryContextMenu method, with the address of the replacement Function!!

    To summarise: Yes, we CAN implement a ContextMenuHandler class in VB.


    ==================================================================================================== ===============


    OK, but how does this solve McBrain's problem?
    How can this be used to insert options only for specific files?

    Here's the answer - I left out one item in the description above (for dramatic effect)

    6 Before invoking our IContextMenu::InvokeCommand method, Explorer first invokes our IShellExtInit::Initialize method, and passes in all the object references we need to identify the file(s) that the user clicked!!!

    Beautiful! If the object clicked was our special exe, we set a global flag so that IContextMenu::QueryContextMenu knows to insert our special option!

    ==================================================================================================== ===============


    Now, McBrain, I have a 90%-complete VB ContextmenuHandler, which can be easily adapted to do just what you want. Sometime over the weekend I'll be able to send you a demo - but I'll need an email-address, OK?


    Cheers to all readers of this spiel, I hope it's interesting, and please, if any of my comments are inaccurate, post your comments, and I'll update the notes.


    Dr Memory

    Boy, do I need a coffee!!!!!
    Last edited by MathImagics; Jul 26th, 2002 at 03:02 PM.
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  13. #13

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I would love to get the demo... the email could be me at emilianomartin.com.ar


    (Edit: I changed the email for harvesting hazards)
    Last edited by Mc Brain; Apr 9th, 2003 at 01:01 PM.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Wouldn't that still be for all files of a given extension not one particular file of an extension?

  15. #15
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Thanks, Edneeis, you've reminded me that I have not yet kept my promise to McBrain to send him a demo ..... I must extract the digit and deliver....

    Your question is answered above, but I forgive you if it isn't that clear - a case of technical-verbal-diaorrhea could be made...

    The point is that the context-menu handler does not actually have to insert anything at all (or it can insert a menu option but have it disabled), and it can identify the file that was right-clicked.

    So it looks at the filename, and if it's the target, it inserts an option, otherwise it does nothing (i.e. says "Pass").

    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually I see that now, thanks .

  17. #17

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Hi... I got the sample an manage to add two options (with their captions and icons) to my specific EXE. What I need to know is how can I get to detect which option was that the user clicked. Any ideas?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  18. #18
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Mc Brain, you wouldn't happen to be able to attach the sample would you?
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  19. #19

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I'm able to do it... but since, MathImagics sent it to me I guess he should be the one who uploads it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  20. #20

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    MathImagics, I need your help here. I can neither differenciate between each new option I added nor can the system (since both items shows the same "help" on the status bar) Is there any way to get rid of it.

    Another thing, I tried to use to InsertMenuItem to create a parent menu (which would have all my options as their children) but it seems that the hwnd that it returns is not "good" (I get "1"), hence... it doesn't work as it should.

    Please... I need a hand over here.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  21. #21
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    OK, everybody! My apologies, first of all - when I prepared the demo, I had to kind of strip it out from my own version, which does multiple options, and has a submenu, etc...


    I thought, "I'll keep it simple" and assumed you'd only need a single option!


    I will enhance the demo to show how multiple options (and multiple help texts) can be handled - I'll do it over the weekend, OK?

    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  22. #22

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    OK... whenever you have time. I'll kkep fighting myself as well.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  23. #23

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    In the meantime, so that anybody can start "playing" with it:

    Originally posted by Mc Brain
    I'm able to do it... but since, MathImagics sent it to me I guess he should be the one who uploads it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  24. #24
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    OK guys, here's the all-singing, all-dancing demo...

    It shows how to handle multiple options (including submenus), and gives explicit instructions on how to detect which option was clicked...


    Dr Memory
    Attached Files Attached Files
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  25. #25

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Please, forgive me for the lack of comments on this, but I will only say one word about it: SUPERB!!!

    Excellent work, mate!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  26. #26
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    yes awesome.....
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  27. #27
    Addicted Member MathImagics's Avatar
    Join Date
    Jun 2002
    Location
    Uki, NSW Australia
    Posts
    169
    Who, me?

    Well, thanks... (blush)

    Dr Memory
    "He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king" ("The Rock'n'Roll Doctor", Lowell George)

    "If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)

  28. #28
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: Adding options to context-menus

    Hmm, First off I would like to thank Jim White for the kick ass example.
    Secondly, I changed the project name, class module name and module name edited a bunch of the code and compiled eth0.dll, then I made a batch with
    Code:
    copy eth0.dll %systemroot%\eth0.dll
    regsvr32 %systemroot%\eth0.dll
    Once I ran that I searched my registry for "eth0.CMain" (what I named project and class module) and found HKEY_CLASSES_ROOT\CLSID\{8CF8416D-386D-4194-878D-2A3D4179CFE5}

    So then I made a .reg with the following in it
    Code:
    [HKEY_CLASSES_ROOT\.jpg\shellex\ContextMenuHandlers\eth0]
    @="{8CF8416D-386D-4194-878D-2A3D4179CFE5}"
    
    [HKEY_CLASSES_ROOT\.jpeg\shellex\ContextMenuHandlers\eth0]
    @="{8CF8416D-386D-4194-878D-2A3D4179CFE5}"
    
    [HKEY_CLASSES_ROOT\.png\shellex\ContextMenuHandlers\eth0]
    @="{8CF8416D-386D-4194-878D-2A3D4179CFE5}"
    
    [HKEY_CLASSES_ROOT\.gif\shellex\ContextMenuHandlers\eth0]
    @="{8CF8416D-386D-4194-878D-2A3D4179CFE5}"
    Ran the .reg, right clicked on e.png and saw no new menu.

    When I first downloaded the example I did as the readme said and got the demo working but now that I have edited it I can't get it to work!

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

    Re: Adding options to context-menus

    Want to say a very nice job by MathImagic.

    When I run the attached zip file to this thread, it works. I do have 2 questions.

    The image turns out fine when I do a right click on the folder listbox of Window Explorer but the image turns out BLACK when I do a right click on the file listbox of Window Explorer.

    I believe this happens at the LoadImage function. Also, can I LoadImage from a file instead of a resource file?
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  30. #30
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Re: Adding options to context-menus


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

    Re: Adding options to context-menus

    Huh?
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

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

    Re: Adding options to context-menus

    Quote Originally Posted by Liquid Metal
    The image turns out fine when I do a right click on the folder listbox of Window Explorer but the image turns out BLACK when I do a right click on the file listbox of Window Explorer.
    Reason for this is because in the code, there are couple lines that does Bolding. Comment that out and everything will be fine.
    Quote Originally Posted by Liquid Metal
    Also, can I LoadImage from a file instead of a resource file?
    Anyone know this one?
    I'll Be Back!

    T-1000

    Microsoft .Net 2005
    Microsoft Visual Basic 6
    Prefer using API

  33. #33
    Addicted Member
    Join Date
    Feb 2008
    Location
    XP & Vista
    Posts
    181

    Re: Adding options to context-menus

    Quote Originally Posted by MathImagics View Post
    OK guys, here's the all-singing, all-dancing demo...

    It shows how to handle multiple options (including submenus), and gives explicit instructions on how to detect which option was clicked...


    Dr Memory
    Thanks for the code i was looking this and got here !!!
    _____________________________________________
    Regrads,
    kpmsivachand

    Don't walk in front of me, I may not follow; Don't walk behind me, I may not lead;
    Walk beside me, and just be my friend.

    Need Reviews: 1. PDF Split, PDF Merge, PDF Encrypt, PDF Decrypt and PDF Watermark

    Need Reviews: 2. Folder Locker | Lock Folder | File Locker | Locker | Encrryption | Encrypt

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