I would like to create menu item in windows explorer content menu (for all file types) which after click will open my application and pass the selected file name to it. Is there any tutorial for this ? I know there is ShellPlus component available but it's a bit outdated.
Registry
This method is easy since it comes down to adding some registry keys. The downside is that you can't put any logic in it. You can read about it here and here a simple example in Delphi. You get a bit more control if you are using DDE to execute the menu items. See here for a Delphi example.
Shell Extension
This method is a bit more work, but you can completely control the context menu from code. You would have to write a DLL, implement IContextMenu (or others) and register the dll with Windows Explorer. You can read about it here. You already mentioned Shell+.
Delphi includes a demo project for shell extensions. Look in the Demos\ActiveX\ShellExt folder.
This is possible independendly from the programming language by setting up shortcut menu handlers for the desired filetype(s) in the registry. There you can call your application with the correct path, the correct options and the right file-placeholders.
See the MSDN article on Creating Shortcut Menu Handlers for more detailled information.
Related
how to add new items to certain file extension context menu (to .mp3 files for instance)
I've also noticed that there is common items in all context menus across the windows, does they all share/inherit one context menu ? where is it : which one is for text
what such keys are called and how to generate them (for instance {11dbb47c-a525-400b-9e80-a54615a090c0})
also is there a good brief reference for the registry that you would recommend ?
Type regedit in RUN dialog box or Start Menu searchbox and press Enter. It'll open Registry Editor, now go to following keys:
HKEY_CLASSES_ROOT* (for adding an option in All files context menu)
HKEY_CLASSES_ROOT\Directory (for adding an option in folders context menu only)
HKEY_CLASSES_ROOT\Drive (for adding an option in Drives context menu only)
HKEY_CLASSES_ROOT\Unknown (for adding an option in unknown files context menu)
Now under the above mentioned keys, you'll find "Shell" and "Shellex" keys. Both keys contain various entries, which are displayed when you right-click on a file, folder or drive. We'll use "Shell" key in this example:
Right-click on the "Shell" key and select "New -> Key".
Give it any name. Suppose we gave it name "Demo".
Now in right-side pane, double-click on "Default" String value and set its value to the Label which you want to display in context menu. Like if you want to add "Winamp" in context menu, then you can give it name "Open with Winamp" or similar.
Now create another key under this newly created key "Demo" with the name "command" and in right-side pane set value of "Default" to the path of application. For ex, for winamp you can set its value %programfiles%\Winamp\winamp.exe.
A full reference to this can be found here
how to add new items to certain file extension context menu
How you massage the registry to create context menu item entries is already covered by this MSDN article. It is extensive and well done, no need to repeat it here.
I've also noticed that there is common items in all context menus across the windows
The majority of them are baked-in items that Explorer itself understands. There is a backdoor to add an item yourself to any file, the HKCR\* registry key is used. Use this sparingly, it is pretty annoying to users.
for instance {11dbb47c-a525-400b-9e80-a54615a090c0}
That's an example of a custom shell extension handler, you found this one back in the HKCR\Folder registry key, the key that adds items to any directory. Think of it as a plug-in that adds capabilities to Explorer that it doesn't have itself. The {guid} selects the executable file that Explorer loads to implement the item. Navigate to HKCR\Classes\CLSID\{guid} to see that file, you'll see it is implemented by c:\windows\system32\explorerframe.dll
Writing your own shell extension handler is not that easy, it requires COM coding skills in C++. A coding technique that is getting obscure. Using something like C# is technically possible but strongly discouraged by Microsoft and they won't support it. You need to write an in-process COM server that implements the IContextMenu interface. Programming guide is here.
I want to create an application.
It is about dealing with files and folders.
I want to create a command which will appear after right-clicking any file on Windows.
Is there any way to accomplish this by C#?
Or do I need to use a lower-leveled language to access those things?
Yes, you can certainly write Windows "shell extensions" in C# or any other .NET language. It is quite involved (have to write a Component Object Model (COM) DLL). There is a tutorial on it using the .NET 4 Framework: http://blogs.msdn.com/b/codefx/archive/2010/09/14/writing-windows-shell-extension-with-net-framework-4-c-vb-net-part-1.aspx
You can probably do everything you are trying to do with simple registry changes. Do a Google search for "Explorer right click context menu."
If you need that for yourself I think that a quick way to obtain that is to put a link to your program into the SendTo folder.
Update: Otherwise, here is a c# code sample that shows how to add the registry key.
If you are doing the visual studio thing then I'm assuming you want to deploy your app and make the installer sort out the context menu stuff. read this http://msdn.microsoft.com/en-us/library/k3bb4tfd%28v=vs.80%29.aspx
I would like to write an application/extension that would replace the default explorer right-click context menu with something other than a menu, preferably a custom window. Is this possible, and if so, how?
I haven't tried it myself, but implementing a shell extension that subclasses the explorer window seems like the way to go. The following CodeProject article talks about a shell extension with a keyboard hook. It should be possible to adapt this to intercept the mouse and WM_CONTEXT messages:
Shell Extension with Keyboard Hook
I have a C/C++ algorithm that I want to create a GUI application for. I would prefer a .exe application that I can pass around to people. I would preferably want to create a dll of my c/c++ algorithm and then bundle it into the Windows GUI application which is basically just a wrapper around the main c/c++ application. How can I create this GUI in VC++ all with a couple of buttons, a text box and a file chooser/browser/opener?
Can someone throw some light on this problem?
Thanks,
Abhishek
There's a number of different options. First we have the microsoft-supported libraries:
MFC - The most heavy-weight library for the windows api.
ATL - A somewhat smaller, lightweight library.
Windows API - Use the Windows API directly.
Beyond that there's a number of third party GUI toolkits, notably:
GTK+
WxWidgets
If you want to make it as small as compact as possible and avoid external DLLs, you should use the Windows API directly or possibly ATL. This also gives you additional flexibility, but it's a bit more complicated. Take a look at for example theForger's tutorial. It's a bit old, but the api has remained more or less the same for the last ten years anyway.
Here's some additional pointers for using the API directly:
What is usually known as controls is called "windows" and are created using CreateWindowEx(). This function creates different things depending on the specified "window class", such as edit, button and static (described below). You create a regular window by registering a custom class.
You can use a function called GetOpenFileName() to invoke an open dialog.
The common text box is known as the edit control in the API.
Buttons are simply called button controls.
Labels are called static controls.
If it's enough for your purposes, you can also create a dialog window using CreateDialog(). This is possibly a bit easier, since dialogs can be designed using the resource editor, while you have to create all the controls in a regular window programmatically.
In Visual Studio:
File -> New Project
In the left panel choose "Visual C++" (or C# if you prefer) and in the right panel choose Windows Forms Application. Click Ok.
When your project is created, in the Toolbox panel you can find Button, Edit Box, OpenFileDialogs and SaveFileDialogs (which you need). If you can't find Toolbox panel, you can enable it in View->Toolbox menu.
Place the controls you need on the program window as you wish by simply dragging them over.
I want to add an item into the Desktop context menu (the menu you see when you right-click on an empty space on the Windows Desktop).
Something like Catalyst Control Center in this screenshot:
I know how to add items to files' and folders' context menus through registry, but the Desktop seems to work differently: I didn't even find the text in the registry.
So, how can I add a new item into the Desktop menu and how can I associate some code with it?
I think the solution is language independent, if it's not, I'd appreciate any code that helps.
Such a handler must be registered in HKCR\Directory\Background, instead of usual locations like HKCR\Directory, HKCR\Folder, etc.
Check out Creating Shell Extension Handlers in MSDN.
There's a series of articles on CodeProject that details writing Shell Extensions and is very good:
http://www.codeproject.com/KB/shell/shellextguide1.aspx