CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2015
    Posts
    19

    Question Custom file association

    Hello

    I would like to provide my software with an automatic file association.
    my Project creates .ctx-Files. When I open this .ctx-File, my Software should start an make something with this file.

    So:
    - How can I create an Association that this file becomes an FileIcon an my Software opens as soon someone is opening this file?
    - How can I make, that the software unterstand that this file is opened and this will be proceeded?

    thank you

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Custom file association

    To have your program open files on start-up, let it examine the command line arguments that you can access by calling Environment::GetCommandLineArgs(). If you find a file name as the first argument, open the file.

    The command line also is the way that Windows (by default) uses to pass a file name to open. Your program gets started with the respective file name on the command line when you drop a file (of any extension) on (a link to) your .exe in Explorer or on the desktop - and when you double-click an associated file or use Open With.

    The quick and dirty way to create a file type association is to double-click any .ctx file (use right click and Open With... from the context menu if the extension .ctx already is associated with another program). Windows will then give you the choice which app to open the file with. Click your way (varies, depending on Windows version) through to the open file dialog to pick your .exe file to associate the file type with, and make sure you check the "Always use this program for .ctx files" (or so) option when you come by.

    The usual way to create a file type association is during installation of your program, and pretty much any installer package will give you the option to set this up. (Some installers seem to have problems with this under Windows Version 8.0 - at least - and up, though.) There also is a way to have your program set up its own file type assotiation programmatically, but I don't know it, because I always was fine with the quick and dirty method described above. This will probably require admin privileges.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    May 2015
    Posts
    19

    Re: Custom file association

    Hello

    Thank you for this input. My Software is an portable edition so an installation-packige is not possible.
    So my software shoult create some registry-entrys when I am correctly informed.

    Do you have a code example? The user should not do it manually it should works automaticly after the first time when my software runs.
    So every .ctx-File should get an Icon and by double-click, the software must be opened. Because the software-path can change, the software must actualize the registry every time with the new path.

    kind regards

    Roger

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Custom file association

    No I don't have such an example. As I wrote above, I never needed to do that. But someone else who is reading this may have.

    I took a quick look at one of my own file associations created using Open With... in the registry editor. The related information doesn't seem to be really complicated, but it's somewhat scattered across the registry. And I'm not certain which of the entries I would need to create myself and which are just mirrors of these (like HKCU vs. HKEY_USERS hives). I'm usually recluctant to doing direct registry manipulations without exactly knowing what I'm doing, as this, as you probably know, may cause severe system damage. But nothing keeps you from taking your own look at the generated registry entries, of course.

    After all, I think it's arguable whether a portable software should leave any registry footprint at all (or how portable it still is if it does). A remaining file association without the respective .exe file may perhaps, in some cases, pretty much cause some irritation.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured