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

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/

Related

VS2022 Community crashes when adding Class to MFC Dialog

I am facing a very consistent and persistent problem with Visual Studio 2022 Community Edition.
In an MFC project I open the Resource File and add a new Dialog. Then I place some standard controls and rename the dialog resource from its default name to a new ID.
Then I save and try to assign a Class to the dialog by right-clicking on the dialog and choosing 'Add Class'. Then the 'Add MFC Class' window appears, I enter the Class Name and click [OK].
It appears it creates the class on the File System and then VS2022 crashes completely!
I have disabled all addins in case an addin could be causing the problem but it happens every (almost) every time even without plugins. The only time I manage to get it to work is if I save, close all code editors, exit VS2022, restart it and immediately try to add the class. Another piece of information is that I have changed the MFC dialog template with a different one but it does not seem to bother it when I get it to work. Also intelliSense is completely disabled.
How can I debug this and identify the root cause of this crash?
There's a fair chance that you can't do anything in an effective fashion. VS2022 isn't an open source project, where you can easily pinpoint a crash to a specific line of code and fix it yourself.
But the good thing is that you don't need to. Just use the feedback channel VS2022 provides:
Usually a Microsoft employee will reply within a few days and maybe a fix will be included in the next preview version. Only now and then it can take some month to get a bug resolved.

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 to add an icon to a console application

This seems like a thing that should be quite simple to do, but for some reason I have problems even to google anything on the subject...
How do you add an icon to a console application in Visual Studio. Now, I know how this works with Win32 desktop applications - you have the resource file, and the icon with the lowest ID is simply used as the app's icon. But if I add a new resource file to a console application and even mess around with the icon editor - nothing happens. The target executable still has the same default icon. Is there some kind of difference between a console application and a desktop one regarding resources? Or do I need to also do set something else apart from just adding the resource file with an icon?
Thanks
It should work the same as with normal WinAPI application. In my case the problem was probably caused by windows icons caching. You can verify this is the case by moving the executable to another directory.

Context menu handler for folders

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?

GLUT_ICON not working on top left window

am trying to add an icon application that uses freeglut, according to the doc here it seems is enough to have an icon resource GLUT_ICON.
Although it worked, it only appears on the icon of the console window and the executable in windows explorer, but the main window remains with the default windows icon (as shown in the image). I tried building without the console window mode, but I get same behavior, is this the way it suppose to work or am getting a wrong behavior?
This might help clear things for others running into the same problem:
https://www.gamedev.net/forums/topic/151647-opengl-glut-icon/
Basically, in the "file.rc"resource-file (right click view code) that appears after adding an ico resouce, where you should have
MAINICON ICON "compiler_assets\\icon-name.ico" //set main icon to "file"
You should add another line
GLUT_ICON ICON DISCARDABLE "compiler_assets\\icon-name.ico"
Which is basically setting GLUT_ICON to a specific .ico file
Finally fixed this problem. Whether this issues come from the VStudio2012 environment or not is uncertain.
But generating the resource id like this; GLUT_ICON creates a non-defined behavior. The exe is unable to identify this tag as a valid one, therefore no icon can be indexed and found.
By just changing to lower case the string, all problems get fixed.
I did this process manually and the fix seems to be consistent between PC's.