Context menu handler for folders - c++

I am trying to wrap my head around Microsoft's shell extension context menu handler example.
Its implementation only shows a context menu on a .cpp file right-click. I want to try to extend it to allow it to show the context menu whenever a folder, drive, or empty space is right-clicked in Explorer as well.
So far I was only able to modify it to register right-clicks for all file types, not just .cpp files by specifying * when registering it:
hr = RegisterShellExtContextMenuHandler(L"*",
CLSID_FileContextMenuExt,
L"CppShellExtContextMenuHandler.FileContextMenuExt");
I must be missing something else because it won't pop up for folders. I have tried this suggestion but it did not work.
How can I extend this sample to also have it work for folders? Am I missing something from the registry?
Edit: Thanks to Igor's suggestion, I got it to work for folders and drives, but it does not show up when you right-click the desktop or when you right click blank space in a folder, and I did register for Directory\Background and DesktopBackground. Why is this?

Related

Modifying the Windows Explorer Toolbar with WinApi / c++

My task is to program change sorting parameter of files and folders in my operating system.
In the article on the MSDN:
under
Modifying the Windows Explorer Toolbar
indicated
In addition to modifying the Windows Explorer menu bar, you can also add buttons to the toolbar. And an example code.
But example of this modifying the Windows Explorer menu bar is not there, the only thing is there it's button adding example.
An alternative article has an example of opening it, so my question is: is it even possible, and if it is, how to do it?
The folder sort settings are saved to:
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\
HKCU\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU
The entries look like:
You would need to loop through all of these registry entries and change the 'Sort' key. This would only affect folders which have already been accessed.
If you want to see how these lists are parsed, run ShellBagsView while running ProcMon and log all the interactions with the registry.
To do it, not programatically you can follow these instructions:
https://superuser.com/a/1481763/1043059

How do I navigate from a dialog button to the code behind?

Cant believe I cant figure out how to do this.
If im looking at a created dialog in the dev studio and it has an ok button, how do I quickly get to the code for when the OK button is clicked?
At the moment I have to copy the resource ID for the dialog e.g. 'IDD_MYDIALOG'
search for that in the source files, open the source file, then start looking for an On_Ok() style function then do a search on that function then open it.
Thanks
ps Id also like to know how to do the same for menu selections.

How can I change the default .exe icon in Visual Studio 2012 (C++)

I was wondering if there was a way to change the default icon that VS2012 makes when I compile my app. Just for those wondering, I am trying to change the .exe program's icon, not the window icon at the top left of the window and on the start menu. I already know how to do that. I have been Google-ing this for ever and it always shows up how to change the window icon, not the actual file's icon. Thanks in advance!!!
EDIT: This is what I want to do...
I want to replace this...
with this...
]
Thanks, hope this clarifies.
Adding icon to executable
Tested for VS2012 Express
Create a icon.rc file next to your .vcxproj file and fill it with the following text:
// Icon Resource Definition
#define MAIN_ICON 102
MAIN_ICON ICON "your_icon.ico"
Then add the following to your .vcxproj file anywhere within the Project tag:
<ItemGroup>
<ResourceCompile Include="icon.rc">
</ResourceCompile>
</ItemGroup>
Additional options
If you want you may forward definitions to your icon.rc file like so:
<ItemGroup>
<ResourceCompile Include="icon.rc">
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/D_DEBUG %(AdditionalOptions)</AdditionalOptions>
</ResourceCompile>
</ItemGroup>
Notice the /D_DEBUG definition, which defines _DEBUG for your resource file. Then within your icon.rc file check for definitions normally:
#define MAIN_ICON 102
#if defined(_DEBUG)
MAIN_ICON ICON "debug_icon.ico"
#else
MAIN_ICON ICON "release_icon.ico"
#endif
Add an icon in the resource section of you C++ project. This icon will be shown as an Application icon for your executable. [Note: make sure you are in the Resource View window, not the Solution Explorer window. Then right-click on the rc folder to Add Resource...]
I have tried this with Win32 Console Application and it shows the icon in the Explorer as Application Icon. This should work with other types of applications also.
Also note that while adding the icon you need to add different size images for the Icon like 16*16, 32*32. These different icon images will be used by Windows Explorer to display Application Icon in different View Modes(Small Icons, Medium Icons, Larget Icons, Extra Large icons etc.)
This is not really how it works. The size of the icon of your program as displayed by Windows isn't determined by you, the user selects it. It is a user preference, very simple to change on later Windows versions by just rolling the mouse scroll button on the desktop. And an icon doesn't have just a single size, it is capable of storing multiple images. Windows picks the one that fits best. And the one you get when starting a new project is just a stock one that's stored in the project template. You can change it by tinkering with the project template .zip file but that's kinda pointless, you want to give your program a custom icon that personalizes it.
Best thing to do is to steal, beg or borrow one, making a good looking icon is an art. Lots of web sites where you can download free ones. If you want to take a shot at creating your own then that's supported as well. Simply double-click the project's .rc file to open the resource view, open the Icon node and double-click the default icon to open the icon editor. You add a new size with Image + New Image Type. Plenty of freeware icon editors available as well.
If its a Win32 application then you can add a resource to your project and then put the icon in there. Then you can assign the icon to your application by sending the WM_SETICON method. For MFC applications, resources are already present and there is a nominated icon resource that you can just change.
You can also load it directly from an external file as suggested here:
Setting program icon without resources using the WIN32 API
I would recommend the resource route though. Resources get embedded in your executable and it is the recommended way to do this sort of thing in Win32 and MFC.

How to restrict FileDialog to specific path

Is it possible to restrict a file dialog(open/save) to a specific folder is winapi?
OPENFILENAME fileDialogSettings;
...
fileDialogSettings.lpstrInitialDir = "Some path";
...
if(GetOpenFileName(&fileDialogSettings))
{
}
I want to have "Some path" as root path in the dialog and to restrict navigation to this folder and it's sub folders only. May I use lpfnHook for this?
If you're targeting Vista+ only, you can make use of the IFileDialogEvents::OnFolderChanging method to block the change altogether.
For older versions of Windows, the OpenFileDialog allows you to specify a hook procedure in which you can pick up on the CDN_FOLDERCHANGE notification.
While I can't see any message to disallow the change, you may be able to post a message to tell it to go "back", or just disable the "OK" button.
Another option is to handle CDN_FILEOK notification and refuse paths outside your required directory.
See this MSDN article for more details about the hook procedure.
This question also talks about changing the directory in an open dialog.
Look into OFN_NOCHANGEDIR flag, although the documentation says this:
Restores the current directory to its original value if the user
changed the directory while searching for files.
This flag is ineffective for GetOpenFileName.
Edit: Reading your question again, I guess you don't want the user to navigate up from that directory, not sure if this is possible with GetOpenFileName, you might have to create your own dialog with a directory list view and restrict them that way.

Adding an item to Internet Explorer's right-click context menu

I'm trying to add a new entry into Internet Explorer's right-click context menu. I understand that this can be achieved by creating an HTML file containing JavaScript, and then linking to this from a location in the registry. I have also read that you can also add the HTML to a resource file and compile it into a DLL (see the Microsoft KB: Adding Entries to the Standard Context Menu). This is where I have started to hit problems.
Here is a bit of background about what I have done so far.
I have the following JavaScript in the file C:\test.htm:
<script type="text/javascript">
alert('Hello, world!');
</script>
I have added a new REG_SZ value 'c:\test.htm' in the registry at the following location:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt
If I now restart IE, my new menu item appears in the context menu. If I select my new menu item, my message box alert appears as expected. So far so good. However, I can't seem to access the script if it's in a DLL. Here are the steps I have taken:
Created a new Visual C++ Class Library project in VS 2005 named 'IETest' in c:\IETest
Imported my C:\test.htm file into the default app.rc resource file. I have changed the ID to be TEST
Compiled the DLL in debug mode
Altered the registry entry to read
res://C:\IETest\debug\IETest.dll/TEST
If I now restart IE and try again, the message box does not appear when I right-click and select my new context menu entry. I have also tried a release build of the DLL without any luck, and also tried replacing the last forward slash with a comma and altering the path single-backslashes to double-slashes.
I can only presume that I've done something wrong when creating my DLL. Can anyone point me in the right direction? Is there any way I can examine the compiled DLL to examine the resources and associated IDs?
Thanks.
Have you tried having the ID be TEST.html? My guess is that IE doesn't know how to handle the file because it doesn't have an extension listed, but this is totally a guess based off the fact that's how certain MS .dlls identify them (i.e. res://c:\windows\system32\shdoclc.dll/navcancl.htm)
The only other thing I can think of is to make sure your resources are of type 23.
ResourceHacker can view the resource files like you want: http://angusj.com/resourcehacker/