Solved

Limiting an application to only one instance

Posted on 1998-12-14
6
153 Views
Last Modified: 2013-11-20
I need to know how to prevent more than one instance of my application from being loaded at the same time. If a user attempts to load the application while an instance is already running, the currently running instance should be brought up instead. Can anyone tell me how to do this?
0
Comment
Question by:jhanson040697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:kanni
ID: 1326188
Hi

You can find solutions with sample code in the codeguru.com site.
0
 

Accepted Solution

by:
kanni earned 100 total points
ID: 1326189
Hi

Get all the active application window handles,
Compare the Window names with your app name,
If any of the Window name is same as your app names then bring the window to top.
0
 
LVL 1

Expert Comment

by:fkurucz
ID: 1326190
there is a more simple solution using a named mutex (see CMutex or as kanni said an example at codeguru.com)

bye
  feri
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:fkurucz
ID: 1326191
Ok, ok,
its not that complicated:

in your initialization module insert the following code:

// Check for existence of second Instance, and keep Mutex open
HANDLE hRunOnceMutex;
hRunOnceMutex = CreateMutex(NULL, FALSE, "EsKannNurEinenGeben");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
    // some code to exit your program
}

you need not to call "CloseHandle(hRunOnceMutex)", because the mutex is freed automatically if your program exits.

bye,
  feri

0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1326192
fkurucz 's solution is common way in win32.
0
 

Author Comment

by:jhanson040697
ID: 1326193
The example on codeguru.com worked very well for me.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question