CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    How to open files always in the same instace?

    can you give some clues how can I open files always in the same instace of my app? I have my custom file extension and I'd like to be able to load a file into a running instance of my program when I double-click it
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to open files always in the same instace?

    There is really two parts to this problem:
    1) Detecting if your application is currently running.
    2) Passing the file to the currently executing application.

    For 1), you can add some code that checks for a previous instance of your application using a mutex. Just create a named mutex when you start the app and check if the mutex already exists. If it already exists, you will pass the file path to the original instance by calling IStartup.OpenFile(...) method (see 2) below) and then exit the app.

    For 2), you'll need to develop some interprocess communication method to pass the file path to the existing instance of the application. There are many ways to do this, but consider hosting a WCF service in the app. Since WCF can be hosted in IE, a Windows service or an application, it's pretty simple to set up a simple service that exposes an interface and a method (say IStartup w/method OpenFile).

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: How to open files always in the same instace?

    cool thx, that's exacly what I wanted to know, now I have something to go on
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

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