File handling by extension (Windows Explorer/Mac Finder)


Hi Folks,

I have a problem I’ve been meaning to resolve for a long time, and can’t put it off any longer. :slight_smile:

The problem is this: I want my Juce app to register support for files of one or more extension (e.g. “.wibble”, “.wobble” etc.).

So that if in Windows Explorer or Finder, the user double-clicks on such a file, my app will launch automatically (if not already running) and open the file immediately.

And files of that extension to display my application icon automatically in Windows Explorer or Finder.

I can’t find how to do this in the docs/forum, so please excuse if I’ve missed it!



I had this bit of code knocking around that might be useful:

[code]static void createFileAssociation (const String& suffix,
const String& shortDesc,
const String& fullDesc,
const String& exe,
int resourceNum)
String key (T(“HKEY_CLASSES_ROOT\”));
key << suffix << T("\");

    PlatformUtilities::setRegistryValue (key, shortDesc);

    String shortDescKey (T("HKEY_CLASSES_ROOT\\"));
    shortDescKey << shortDesc;

    key = shortDescKey + T("\\DefaultIcon\\");
    PlatformUtilities::setRegistryValue (key, exe + T(",") + String (-resourceNum));

    key = shortDescKey + T("\\");
    PlatformUtilities::setRegistryValue (key, fullDesc);

    key = shortDescKey + T("\\shell\\open\\command\\");
    PlatformUtilities::setRegistryValue (key, exe + T(" %1"));



Hi Jules,

Aha - very interesting - top man!

I’ve figured out these questions for myself:

  • what value should I use for resourceNum?
    I just use zero, and that forces Windows to use the default icon; no problem there!
  • how does the JuceApplication get notified about file open events from Windows Explorer that will be generated as a result of that code?
    I see that moreThanOneInstanceAllowed() and anotherInstanceStarted() and initialise() are all involved - no problem there!

Can you answer these for me?

  • what is the Mac equivalent I should use? :slight_smile:
  • are you going to put a handy call to do just this in the framework (as any app which wants to store/restore data to/from a given file type will want this!!)

All the best!



I think resourceNum is the index of the icon in your executable to use as the icon for the file.

The filenames of the files opened get passed as parameters on the comandline, I think you’ve got it figured out with anotherInstanceStarted() etc.

For the mac, the info needs to go into the .plist file.

I think if you getinfo for the executable there is a dialog you fill out with the appropriate info and it edits your plist for you.



This link seems pretty definitive: