Custom file icon Windows/Inno

I recently realised my custom file types on Windows were showing with the App icon.
Even though I had file types and icons defined in my Xojo project.

There are many posts about ‘fixing’ same on MacOS, and Appwrapper handles it well anyway.

But on Windows, it was tricky.
I have a solution which Im sharing here.

In Inno setup you can associate files with apps, and assign an icon.
Most of the documentation assumes that the icon will be ‘in’ the app, and accessed as icon 1, 2, 3 etc
That didn’t work for me… I assume it is because the icons are no longer held as resources in the app like they used to be in older Win32 apps.

So, creating a standalone .ico file works nicely.

The relevant Inno script code then became this:

MyApp - replace with your app name throughout… it doesn’t appear to have to match your app name, but has to be consistent in these lines.
Custom.ico - drag into your project or pop it into resources with a build step
.MyExt - your file extension

You can add as many of these as you wish


[Registry]
Root: HKCR; Subkey: ".MyExt"; ValueType: string; ValueName: ""; ValueData: "MyApp Document"; Flags: uninsdeletevalue
Root: HKCR; Subkey: ".MyExt\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\MyApp.exe"" ""%1"""
Root: HKCR; Subkey: "MyApp Document"; ValueType: string; ValueName: ""; ValueData: "MyApp Document"; Flags: uninsdeletekey
Root: HKCR; Subkey: "MyApp Document\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\MyApp Resources\custom.ico,0"
Root: HKCR; Subkey: "MyApp Document\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\MyApp.EXE"" ""%1"""