October 29, 2025, 06:54:37 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Context menu

Started by king2k, September 02, 2008, 05:39:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

king2k

Hey,

I want to make a program detect when an item is clicked from the context menu in windows.
Ex. If i right-click on a folder from explorer, I want to have a custom item 'add to myApp', that when clicked sends the path to that folder into my program. The program should allready be running.

Any suggestions?
Please advise.

Regards
Kim

Allan

Hi Kim

I think that would need to be handled with Registry entries.

The following text may give you an answer towards what you want. It explains about removing Right-Click from FOLDERS and from FILES as well as ADDING to same:

QuoteHow To Remove and Add Right-Click Menu Items from Files and Folders
Removing Items
A lot of programs you install will add themselves to the right-click menu of your files and/or folders. And most times, you have no choice in the matter and, as a result, your right-click menu can get very long with added items you don't even use. The last person I was helping with this had a right context menu so long that the Rename option was no longer visible!
Fortunately, you can easily remove those unwanted menu items, if you know the registry values to edit. And it's not at all difficult once you know the keys responsible for the additions.

For Files, the secret lies in the "context menu handlers" under the shellex subkey for "All Files" which, in the registry, is nothing but an asterisk - like a dos wildcard, which means the values entered apply to all files. It is at the very top of the Root key, right here:

HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers

Click the the + sign next to the ContextMenuHandlers key, to expand it.
Now you will see some of the programs that have added items to your right-click menu. Simply delete the program keys you don't want.
Yup! It's that simple. If deleting makes you uneasy, just export the key before deleting it. Or, instead of deleting the values, disable them. Simply double click the default value for the program on the right hand pane and rename the clsid value by placing a period or dash in front of it.
ie; - {b5eedee0-c06e-11cf-8c56-444553540000}
Then exit the registry, refresh, and right click a file to see if the item was removed from the menu.
Some programs - like WinZip or WinRar - will add several items to your right click menu but all of them will be removed by deleting or disabling their one context menu handler.

Note that the above key only applies to the right click menu of files.
To remove entries from the right click context menu of folders, you need to navigate to the Folder and Drive keys:

HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers
HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers

All you have to do is follow the same procedure as for Files - either disable or delete items you wish to remove.
Adding Items
Adding Items to the right click menu of Files and Folders is also fairly simple using the Registry. It just involves the creation of a few new keys for each item you wish to add. You edit the same keys used for removing items. Let's use Notepad as an example of an item you'd like to add to the right click menu of all your files or folders.

For folders, go to this key:
HKEY_CLASSES_ROOT\Folder
Click the + sign next to Folder and expand it so that the Shell key is visible. Right click the Shell key and choose New>Key and name the key Notepad or whatever else you'd prefer (whatever the key is named is what will appear in the right-click menu). Now right click the new key you made and create another key named Command. Then, in the right hand pane, double click "Default" and enter Notepad.exe as the value.
Exit the registry, refresh, and right click any folder. Notepad should now be on the context menu.


For files, go here again:

HKEY_CLASSES_ROOT\*
Expand the * key and see if a Shell key exists. If it does exist, follow the same procedure as for folders. If it does not exist, you'll have to create a new Shell first. Just right click the * key and choose New>Key and name it Shell. Then right click the Shell key and continue on the same way you did for adding items to the right click menu of folders.
Once done, Notepad should appear as an option in the right click menu of all your files.

Allan


LarryMc

Thanks Allan,
I find that very useful indeed.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

king2k, start with:
HKEY_CLASSES_ROOT\*\shell\add to myApp\command
@ = cmd /k echo "%1"


Note: you must manually create the "add to myApp" subkey.
Now go to your desktop, right click on a item (or more) and then click 'add to myApp'. The command prompt will open, showing path to selected file (if not a shortcut).

Now to make it usable in your program: Write a program called for example cmdline.exe, and replace cmd /k in the registry to full path of your program. If the path contain spaces, quote the path:
@ = c:\users\king2k\ebasic\cmdline.exe "%1"
or
@ = "c:\users\king2k\ebasic programms\cmdline.exe" "%1"   <-- space in path!


Use one of command line functions to extract parameters passed to your program, like GetCommandLine, getmainargs:
MessageBox 0, GetCommandLineA(), ""
And finally write some code to ensure that all parameters are passed to the first instance of your program, because the shell always launches new program instance for every selected icon.


Your session timed out while posting. Please try to re-submit your message :)

king2k

Thanks for great response. I will definitely try your solution sapero;D
Allan: Good info about context menu. I find shell extentions not that easy to handle.

Kim

Allan

September 04, 2008, 06:43:03 PM #5 Last Edit: September 04, 2008, 06:53:35 PM by Allan
Thanks for the source sapero.

Allan

Allan

If you did not wish to work with Registry then there is a possible alternative which is Drag and Drop.

Put say a ListBox on the main Window. Set it to Accept Files in the EX_STYLE

Put in the relative QueryDrop Files  procedures etc.

Easier to show than explain so see attached example code.

Allan