Making an app single instance
-
Hello, I have an app which I need to make single instance. When the second instance is called it needs to bring the window of the first instance to the front, and pass it its command line params in some way. And I need the program to be single-instance on session only - i.e. only one instance is allowed per user, but many users logged on can each have their instance. There are a lot of articles on this in codeproject, but I'm not sure which of them is the best and covers all the requirements.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
-
Hello, I have an app which I need to make single instance. When the second instance is called it needs to bring the window of the first instance to the front, and pass it its command line params in some way. And I need the program to be single-instance on session only - i.e. only one instance is allowed per user, but many users logged on can each have their instance. There are a lot of articles on this in codeproject, but I'm not sure which of them is the best and covers all the requirements.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
Use the named mutex method. This is by default unique per session unless you prefix "Global\" to the mutex name.
«_Superman_»
I love work. It gives me something to do between weekends. -
Hello, I have an app which I need to make single instance. When the second instance is called it needs to bring the window of the first instance to the front, and pass it its command line params in some way. And I need the program to be single-instance on session only - i.e. only one instance is allowed per user, but many users logged on can each have their instance. There are a lot of articles on this in codeproject, but I'm not sure which of them is the best and covers all the requirements.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
I think you can make your class as singleton by making you contructors and destructor as private and publically expose a static method which will return the same instance once an instance is created. That shud take care of your problem.. Google for singleton class examples ..u will get loads of them .. -Kushagra
-
Hello, I have an app which I need to make single instance. When the second instance is called it needs to bring the window of the first instance to the front, and pass it its command line params in some way. And I need the program to be single-instance on session only - i.e. only one instance is allowed per user, but many users logged on can each have their instance. There are a lot of articles on this in codeproject, but I'm not sure which of them is the best and covers all the requirements.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
-
another way, if you are certain about the window caption, is to use FindWindow() API to search for already running application. To make it unique, you may use your own name for your window class, and use it in FindWindow().
I've used FindWindow before, but I remember it had a lot of issues, for example (I don't remember) but didn't it fail if the window was minimized?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
-
Hello, I have an app which I need to make single instance. When the second instance is called it needs to bring the window of the first instance to the front, and pass it its command line params in some way. And I need the program to be single-instance on session only - i.e. only one instance is allowed per user, but many users logged on can each have their instance. There are a lot of articles on this in codeproject, but I'm not sure which of them is the best and covers all the requirements.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
I think you can make your class as singleton by making you contructors and destructor as private and publically expose a static method which will return the same instance once an instance is created. That shud take care of your problem.. Google for singleton class examples ..u will get loads of them .. -Kushagra
The singleton pattern is not applicable in this case: its purpose is to have a unique instance of an object for each process. If you have two or more different instances of the same application, each of them runs on a different process with its own address space, then two applications cannot share the singleton object. Cheers, Sauro
-
I've used FindWindow before, but I remember it had a lot of issues, for example (I don't remember) but didn't it fail if the window was minimized?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal