How to run a single instance of an application (part 1 of 4)
Contents
Abstract
This article discusses how to ensure that just a single instance of an application can be run. An application does this by checking if an instance is already running and terminating if so. We also look at how a duplicate instance can pass its command line parameters to the existing instance before terminating.
Overview
The method of preventing multiple application instances we demonstrate here is based on the detection of an application with a known main window class. Once such an application is detected we then pass any command line data via the WM_COPYDATA message.
Listing 1 outlines the methodology we will be using:
search for a top level window of the correct class if such a window exists activate the window pass any command line data to the window using WM_COPYDATA terminate this application instance else start this application as normal process the command line parameters end
We will discuss an initial approach to this problem in the next part.

