I have a small Windows application which is allowed to run only once. The single instance check is done using a Windows mutex (CreateMutex).
The application should bring the already running application to the front and show an info message to the user.
The info message is created using the MessageBox function from Windows. However, each time I try to start a new instance of my application, a new messagebox is created (allowing me to open hundreds of messageboxes).
Is there a way to limit the number of message boxes to one (besides locking another mutex for the message box)?
There are three states of your program:
It seems reasanoble for the program in third state to quit silently. There are many ways to do it. And since you are already using mutex for detection of second state, is will be reasanoble to use the same logic for detection of third state too.
But you can do it another way:
From my point of view, first approach is better (ie to show message box by second/third/... instance of the program, and only after it to bring main instance to the front).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.