calband/calchart — pull request #80 by kmdurand (2014-07-02 00:35:19+00:00)
Title: Windows Fix - File Association

Previously, when you double clicked on .shw files on Windows, the CalChart program would open, but it wouldn't open the double-clicked file. That's fixed now, which is nice - just adds a little bit of convenience.

When I added this feature, I wanted to make sure that when you double clicked multiple files, they would open up under the same CalChartApp (normally Windows would open up a separate CalChartApp for each file). I did some research, and it seems like there's unfortunately no simple way to do this on windows... so here's what I had to do:

When a new CalChartApp starts, it checks if another application is already running:
If not:
The newly started app becomes the main app, or "server" app
The new app starts a server for inter process communication, and names that server according to the computer's current user and the filepath of calchart.exe (so that each user can have its own main app, and so that there can be one main app per calchart.exe, which means you can open multiple versions of calchart at once)
Because the server name can be calculated by any CalChartApp, each new starting app can detect whether or not a CalChartApp is already running by checking whether or not it can connect to a server with that name
If another application is already running:
The newly started app connects to the main app, and tells it to open the files that the new app intended to open

The process outlined above should NOT occur on a Mac, since Macs already have a really convenient way for doing this - all you need to do is override the MacOpenFile method of wxApp, which we've already done. I tried to make the preprocessor filter out this nonsense when building on a mac, but haven't been able to test it. It would be great if a mac user could try building these code changes and make sure that everything still works properly.