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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating Single instance Application

Creating Single instance Application

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi, My application while starting is placed in the systray as a icon. When i double click the icon, i get a Dialog. If i execute my application again, i get one more icon in the systray and similarly if i double click the icon twice two dialogs appear on the screen. I want to have only one icon on the systray and even if i click the icon again ( ie double click ) it should show only the previous dialog and not the new one. ie I want to have only one instance of my application at any time. Can anybody help me in doing this. Thanks in advance VMJ

    K 1 Reply Last reply
    0
    • L Lost User

      Hi, My application while starting is placed in the systray as a icon. When i double click the icon, i get a Dialog. If i execute my application again, i get one more icon in the systray and similarly if i double click the icon twice two dialogs appear on the screen. I want to have only one icon on the systray and even if i click the icon again ( ie double click ) it should show only the previous dialog and not the new one. ie I want to have only one instance of my application at any time. Can anybody help me in doing this. Thanks in advance VMJ

      K Offline
      K Offline
      Kannan
      wrote on last edited by
      #2

      Hello, In first line of InitInstance method of the Your application class, put the following code, APP_NAME -- is the DialogWindow Title. if(AfxGetMainWnd( )->FindWindow(NULL, APP_NAME)) { AfxMessageBox("Application Already running"); exit(0); } If any suggesstions let me know. Thanks , - Kannan.A.;)

      B 1 Reply Last reply
      0
      • K Kannan

        Hello, In first line of InitInstance method of the Your application class, put the following code, APP_NAME -- is the DialogWindow Title. if(AfxGetMainWnd( )->FindWindow(NULL, APP_NAME)) { AfxMessageBox("Application Already running"); exit(0); } If any suggesstions let me know. Thanks , - Kannan.A.;)

        B Offline
        B Offline
        Bartosz Lizak
        wrote on last edited by
        #3

        Hello, ;-p it works fine, but if you have open another window with the same name (e.g. explorer window or application with the same name) your application won't start. Better way is to create some kernel object (MS suggest mutex) when your application starts and destroy at ending. Before creating you simply try to open such object and if succeded it means that your application is already running. Regards Bartek

        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