Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Just single instance of my app.

Just single instance of my app.

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DerekSaw
    wrote on last edited by
    #1

    Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.

    A N N S 4 Replies Last reply
    0
    • D DerekSaw

      Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.

      A Offline
      A Offline
      Atlantys
      wrote on last edited by
      #2

      When the app starts up, do a check for a mutex. if it doesn't exist create one, and if not then find the existing app and restore it.. something like: CString strMutexName = _T("MyApp"); // can also use a GUID here if (!m_hMutex) { m_hMutex = CreateMutex(NULL, FALSE, strMutexName); } else { /* go through all the current windows and restore the existing version of your app. i can't remember how to do this now.. something to do with EnumWindow i'm sure, just don't use FindWindow (heard bad things about it :~ ). */ } hope this helps.:)

      1 Reply Last reply
      0
      • D DerekSaw

        Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        DerekSaw wrote: Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits. Avoiding Multiple Instances of an Application


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

        L 1 Reply Last reply
        0
        • D DerekSaw

          Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          Look at CSingleInstance in http://www.codeproject.com/library/pj.asp and the other related articles in the "Threads Processes & IPC" section. Neville Franks, Author of ED for Windows. www.getsoft.com

          1 Reply Last reply
          0
          • D DerekSaw

            Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.

            S Offline
            S Offline
            Scott H Settlemier
            wrote on last edited by
            #5

            sometimes its nice to pass off the command line from the second instance to the first. I usually do this with a control struct in shared memory. First instance creates the control struct and records its information there. Other instances, read the control struct and record their command line there, then activate the first instance, and notify it that their command line has been recorded before exiting. The first instance handles these as appropriate, perhaps opening another file, etc.

            1 Reply Last reply
            0
            • N Nish Nishant

              DerekSaw wrote: Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits. Avoiding Multiple Instances of an Application


              Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Using mutex is one way to do so, see MSKB: Q243953

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups