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 pleaseRate 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.
If a post has helped you then pleaseRate 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.
If a post has helped you then pleaseRate 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.
If a post has helped you then pleaseRate 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.
If a post has helped you then pleaseRate 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.
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)
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 pleaseRate 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.
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)
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)
6Before 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)
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 pleaseRate 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.
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)
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 pleaseRate 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.
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 pleaseRate 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.
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 pleaseRate 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.
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)
OK... whenever you have time. I'll kkep fighting myself as well.
Emiliano F. Martín
If a post has helped you then pleaseRate 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.
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 pleaseRate 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.
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 pleaseRate 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.
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
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}
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?
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.
Originally Posted by Liquid Metal
Also, can I LoadImage from a file instead of a resource file?