Windows 7 Calculator has added this nice little unit converters and templates, but I thought it would be cool to be able to customize your own ones.
Please note: this is a hack, not a proper solution. This is purely for educational purposes, modifying Windows binaries is typically a violation of the license agreement…and updates could potentially break this solution as well.
To start I backed up calc and related MUI files into a separate folder for working on. In this case I just used command xcopy C:\windows\system32\calc.* /s
As English is the only user interface language installed on this machine I only got the en-US MUI file. The MUI is basically a Windows Resource DLL that will contain language specific strings, images, dialog boxes, menus etc of an application.
We need something to edit the resources in the MUI file. For this I used the old class tool Resource Hacker http://www.angusj.com/resourcehacker/ To edit 64-bit resource files ensure you download the 64-bit version.
Please note this tool is no longer maintained, but it was the only freely available tool I tried that could let me correctly extract the XML resource and re-import it. If you know of others that work let me know.
With calc.exe.mui opened in Resource Hacker under the “23” (HTML) tree in Resource Hacker I saved the two resources IDS_TEMPLATE_XML and IDS_TEMPLATE_SCHEMA as “binary” files with an XML extension:
This gave me two XML files to edit
The IDS_TEMPLATE_XML resource contains the rules for the various templates
So let’s start with basics…I want to add a new Length conversion…While there are a lot of choices already
…I had read about Noah’s Ark and it was measured in Cubits and I wanted to convert it to metres. Now the size of a cubit is debated but the world almanac defines it as 17.5 inches.
First I needed to add the word “Cubits” to the String Table in Resource Hacker. I had to use a Resource ID number that was not already being used. After adding I hit “Compile Script”
I then added the display code into the XML. Again I had to ensure “cu” was not used anywhere else.
(Note: TEMPALTE is misspelt on purpose, this is because it is misspelt in Windows resource file)
Unfortunately now calc.exe doesn’t launch…launching via WinDbg we see the failure is at
Now why is this? Examining our XML file we find the reason
-> Although the XML file specifies UTF-8 encoding, within the MUI file it is actually encoded in UNICODE (UTF-16) we can see this from the header of the file:
However when Visual Studio had saved the file…
So I opened the file in Notepad and saved in Unicode format. (Yes Visual Studio can save in Unicode format, but it will switch the utf-8 in XML header to utf-16 and we don’t want that)
This is because we haven’t added our “To” formulas yet. So back to the XML…
Looking through the various “Length” formulas I found that Centimetres seemed to be the gold standard:
So I need a conversion of my inches to cm
Ok so I needed to multiply by 43.815…
So I added the formulas within the <unitFormulas hintBaseUnit=”cm”> section of the XML file. We simply add a “to” and “from” conversion ration. The “to” will be * whatever the value of our unit is in cm. The “from” will be / by whatever our unit is in cm.
<formula name=“cuTocm“ toUnit=“cm“ fromUnit=“cu“>
<constantString formulaConst=“* 43.815“/>
<formula name=“cmTocu“ toUnit=“cu“ fromUnit=“cm“>
<constantString formulaConst=“/ 43.815“/>
(Note: Now that I originally saved the file as unicode, Visual Studio will save it in unicode format without switching the utf-8 to utf-16)
OK and so now my conversion is working…
So with Noah’s ark recorded as 300 cubits long…so I now have it in metres
OK that was pretty simple. But what about customized Worksheets like the mortgage calculator? Creating custom worksheets to follow in next blog post. Any special requests?